瀏覽代碼

1.修改Android RedAnt Mobile Result获取失败。

Pen Li 8 年之前
父節點
當前提交
02f666e701

+ 17 - 8
RedAnt Mobile/app/src/main/java/com/usai/redant/Result/SearchResultActivity.java

@@ -11,6 +11,7 @@ import android.net.Uri;
 import android.os.Bundle;
 import android.support.v7.app.AlertDialog;
 import android.support.v7.app.AppCompatActivity;
+import android.text.Html;
 import android.text.Layout;
 import android.text.TextUtils;
 import android.util.Log;
@@ -263,6 +264,8 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
 
                 try {
 
+                    mParams.putInt("offset",adapter.getCount());
+                    mParams.putInt("limit",25);
                     resultData = Network.query(mParams);
                     if (resultData == null) {
                         resultData = new JSONObject();
@@ -327,6 +330,7 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
 //                    JSONObject newJson = new JSONObject(res);
 
                     mParams.putInt("offset",adapter.getCount());
+                    mParams.putInt("limit",25);
                     JSONObject newJson = Network.query(mParams);
 
                     if (newJson != null) {
@@ -409,7 +413,7 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
 
                 try {
 
-                    JSONArray row_action = resultData.getJSONArray("row_action");
+                    JSONArray row_action = resultData.optJSONArray("row_action");
                     if (row_action != null) {
 
                         if (row_action.length() == 1) {
@@ -731,7 +735,11 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
                        }
 
 
-                       tv.setText(name);
+                       if (name.contains("</")) {
+                           tv.setText(Html.fromHtml(name));
+                       } else {
+                           tv.setText(name);
+                       }
 
                    }
                    holder.row.setBackgroundColor(Color.parseColor(bg_color));
@@ -801,7 +809,12 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
                            tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.result_black_border));
                        }
 
-                       tv.setText(value);
+
+                       if (value.contains("</")) {
+                           tv.setText(Html.fromHtml(value));
+                       } else {
+                           tv.setText(value);
+                       }
 
 
                    }
@@ -919,12 +932,8 @@ public class SearchResultActivity extends AppCompatActivity implements AbsListVi
             public void run() {
 
                 // download & get path
-                String path = null;
+                String path = Network.download_query(mParams);
 
-                if(BuildConfig.DEBUG && true){
-                    //do something for assert aim
-                    Log.e("Result", "onClick: not implement");
-                }
 
                 documentPath = path;
                 download_query = path;

+ 47 - 1
RedAnt Mobile/app/src/main/java/com/usai/redant/util/Network.java

@@ -1,5 +1,6 @@
 package com.usai.redant.util;
 
+import android.app.DownloadManager;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
@@ -10,6 +11,7 @@ import android.os.Bundle;
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.usai.redant.redantmobile.BuildConfig;
 import com.usai.redant.redantmobile.RedAntApplication;
 
 import org.apache.http.HttpEntity;
@@ -78,7 +80,7 @@ public class Network
 																						// out
 																						// 20
 																						// secs
-	private static final int	SO_TIMEOUT						= 15 * 1000;			// so
+	private static final int	SO_TIMEOUT						= 60 * 1000;			// so
 																						// time
 																						// out
 																						// 20
@@ -1820,6 +1822,50 @@ public class Network
 		}
 	}
 
+	public static String download_query(Bundle params) {
+
+		if(BuildConfig.DEBUG && true){
+			//do something for assert aim
+			Log.e("Result", "onClick: not implement");
+		}
+
+//		HttpURLConnection connection = null;
+//		try {
+//
+//			URL url = new URL("https://www.baidu.com/");
+//			connection = (HttpURLConnection)url.openConnection();
+//			connection.setRequestMethod("GET");
+//			connection.setUseCaches(false);
+//			connection.setConnectTimeout(1500);
+//			connection.setReadTimeout(1500);
+//
+//			BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+//			StringBuilder response = new StringBuilder();
+//			String line;
+//			while ((line = reader.readLine()) != null) {
+//				response.append(line);
+//			}
+//
+//		} catch (IOException e) {
+//			e.printStackTrace();
+//		} finally {
+//			if (connection != null) {
+//				connection.disconnect();
+//			}
+//		}
+
+
+//		//创建下载任务,downloadUrl就是下载链接
+//		DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadUrl));
+//		//指定下载路径和下载文件名
+//		request.setDestinationInExternalPublicDir("/download/", fileName);
+//		//获取下载管理器
+//		DownloadManager downloadManager= (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
+//		//将下载任务加入下载队列,否则不会进行下载
+//		downloadManager.enqueue(request);
+
+		return null;
+	}
 
 
 }