Преглед изворни кода

1.修改Android Apex Mobile Detail文档下载指示器以及保持Web内容不变。

Pen Li пре 8 година
родитељ
комит
5cc1de3a59
1 измењених фајлова са 54 додато и 8 уклоњено
  1. 54 8
      Apex Mobile/app/src/main/java/com/usai/apex/DetailFragment.java

+ 54 - 8
Apex Mobile/app/src/main/java/com/usai/apex/DetailFragment.java

@@ -18,6 +18,7 @@ import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Build;
 import android.os.Bundle;
+import android.support.annotation.Nullable;
 import android.support.constraint.ConstraintLayout;
 import android.support.v4.app.Fragment;
 import android.text.Html;
@@ -48,6 +49,7 @@ import com.usai.util.commonUtil;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 
 public class DetailFragment extends Fragment implements OnClickListener /*
@@ -62,10 +64,21 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 
 	Context mContext;
 	ProgressDialog progressDialog;
-	protected void showProgressDialog(String title, String msg) {
-		progressDialog.setTitle(title);
-		progressDialog.setMessage(msg);
-		progressDialog.show();
+	protected void showProgressDialog(final String title, final String msg) {
+
+		getActivity().runOnUiThread(new Runnable() {
+			@Override
+			public void run() {
+				try {
+					progressDialog.setTitle(title);
+					progressDialog.setMessage(msg);
+					progressDialog.show();
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+		});
+
 	}
 
 	/* private GestureDetector mGestureDetector; */
@@ -75,7 +88,16 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		// TODO Auto-generated method stub
 		super.onCreate(savedInstanceState);
 
-		progressDialog = new ProgressDialog(getActivity());
+//		progressDialog = new ProgressDialog(mContext);
+//		progressDialog.setCancelable(false);
+
+	}
+
+	@Override
+	public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+		super.onActivityCreated(savedInstanceState);
+
+		progressDialog = new ProgressDialog(mContext);
 		progressDialog.setCancelable(false);
 	}
 
@@ -262,6 +284,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		return view;
 	}
 
+	private JSONObject mContent;
 	void init(String jstr, LayoutInflater inflater)
 	{
 		String TAG = "init@DetailFragment";
@@ -269,6 +292,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		try
 		{
 			JSONObject jsonObj = new JSONObject(jstr);
+			mContent = jsonObj;
 			int group_count = jsonObj.getInt("count");
 			if (group_count == 0)
 			{
@@ -448,6 +472,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 //						}
 //
 //					});
+					wv.setTag(i);
 					control.put(v.getId(), wv.getId());
 					wv.loadData(content, mimeType, null);
 
@@ -754,7 +779,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 	public void download(String url) {
 
 		final String download_url = url;
-//		showProgressDialog("Please wait","Downloading...");
+		showProgressDialog("Please wait","Downloading...");
 		new Thread(new Runnable() {
 			@Override
 			public void run() {
@@ -766,7 +791,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 				getActivity().runOnUiThread(new Runnable() {
 					@Override
 					public void run() {
-//						progressDialog.dismiss();
+						progressDialog.dismiss();
 						RAUtil.openFile(getActivity(),downloadFile);
 					}
 				});
@@ -821,12 +846,33 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 			Log.d("Web Client", "shouldInterceptRequest: " + url);
 			if (url.startsWith("http") && url.contains("action_type=download_doc")) {
 				download(url);
-				return null;
+
+				String content = contentOfWebView(view);
+				WebResourceResponse response = new WebResourceResponse("text/html",
+						"utf-8",
+						new ByteArrayInputStream(content.getBytes()));
+				return response;
+
 			} else {
 				return super.shouldInterceptRequest(view,url);
 			}
 		}
 
+		String contentOfWebView(WebView webView) {
+
+			int i = (int)webView.getTag();
+			try {
+
+				JSONObject groupobj = mContent.getJSONObject("group" + i);
+				String content = groupobj.getString("content");
+				return content;
+			} catch (JSONException e) {
+				e.printStackTrace();
+			}
+
+			return null;
+		}
+
 //		@Override
 //		public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
 //			Log.d("Web Client", "shouldInterceptRequest: " + request);