|
|
@@ -2,11 +2,13 @@ package com.usai.apex;
|
|
|
|
|
|
import android.animation.Animator;
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
+import android.app.Activity;
|
|
|
import android.app.AlertDialog;
|
|
|
import android.app.AlertDialog.Builder;
|
|
|
import android.app.Dialog;
|
|
|
import android.app.DownloadManager;
|
|
|
import android.app.DownloadManager.Request;
|
|
|
+import android.app.ProgressDialog;
|
|
|
import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
@@ -27,6 +29,8 @@ import android.view.View;
|
|
|
import android.view.View.OnClickListener;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.webkit.DownloadListener;
|
|
|
+import android.webkit.WebResourceRequest;
|
|
|
+import android.webkit.WebResourceResponse;
|
|
|
import android.webkit.WebView;
|
|
|
import android.webkit.WebViewClient;
|
|
|
import android.widget.Button;
|
|
|
@@ -38,11 +42,14 @@ import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.usai.util.Network;
|
|
|
+import com.usai.util.RAUtil;
|
|
|
import com.usai.util.commonUtil;
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
public class DetailFragment extends Fragment implements OnClickListener /*
|
|
|
* ,
|
|
|
* OnGestureListener
|
|
|
@@ -53,6 +60,14 @@ public class DetailFragment extends Fragment implements OnClickListener /*
|
|
|
|
|
|
// DataFragment mdataFragment;
|
|
|
|
|
|
+ Context mContext;
|
|
|
+ ProgressDialog progressDialog;
|
|
|
+ protected void showProgressDialog(String title, String msg) {
|
|
|
+ progressDialog.setTitle(title);
|
|
|
+ progressDialog.setMessage(msg);
|
|
|
+ progressDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
/* private GestureDetector mGestureDetector; */
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
@@ -60,6 +75,14 @@ public class DetailFragment extends Fragment implements OnClickListener /*
|
|
|
// TODO Auto-generated method stub
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
+ progressDialog = new ProgressDialog(getActivity());
|
|
|
+ progressDialog.setCancelable(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAttach(Context context) {
|
|
|
+ super.onAttach(context);
|
|
|
+ mContext = context;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -314,116 +337,117 @@ public class DetailFragment extends Fragment implements OnClickListener /*
|
|
|
wv.getSettings().setDefaultTextEncodingName("UTF-8");
|
|
|
wv.setId(commonUtil.generateViewId());
|
|
|
wv.setWebViewClient(new MyWebViewClient());
|
|
|
- wv.setDownloadListener(new DownloadListener()
|
|
|
- {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onDownloadStart(String url,
|
|
|
- String userAgent, String contentDisposition,
|
|
|
- String mimetype, long contentLength)
|
|
|
- {
|
|
|
- if(!commonUtil.localdirExist())
|
|
|
- {
|
|
|
-
|
|
|
- new AlertDialog.Builder(getActivity())
|
|
|
- .setIconAttribute(android.R.attr.alertDialogIcon)
|
|
|
- .setTitle(R.string.str_localdir_error)
|
|
|
- .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
- public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
-
|
|
|
- /* User clicked OK so do some stuff */
|
|
|
- }
|
|
|
- })
|
|
|
- .create().show();
|
|
|
- return;
|
|
|
- }
|
|
|
- String filename = contentDisposition.replace("attachment;filename=\"", "");
|
|
|
- filename = filename.replace("\"", "");
|
|
|
-
|
|
|
- Log.d("WebView", "Download Action");
|
|
|
- Log.d("tag", "url=" + url);
|
|
|
- // Log.i("tag", "userAgent="+userAgent);
|
|
|
- // Log.i("tag",
|
|
|
- // "contentDisposition="+contentDisposition);
|
|
|
- // Log.i("tag", "mimetype="+mimetype);
|
|
|
- // Log.i("tag", "contentLength="+contentLength);
|
|
|
- // Uri uri = Uri.parse(url);
|
|
|
- // Intent intent = new Intent(Intent.ACTION_VIEW,
|
|
|
- // uri);
|
|
|
- // startActivity(intent);
|
|
|
-
|
|
|
- final DownloadManager downloadManager = (DownloadManager) ApexTrackingApplication
|
|
|
- .get_instance().getSystemService(
|
|
|
- Context.DOWNLOAD_SERVICE);
|
|
|
-
|
|
|
- Uri uri = Uri.parse(url);
|
|
|
- final Request request = new Request(uri);
|
|
|
-
|
|
|
- // 设置允许使用的网络类型,这里是移动网络和wifi都可以
|
|
|
- request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE
|
|
|
- | DownloadManager.Request.NETWORK_WIFI);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- request.setDestinationInExternalPublicDir("Apex Mobile",filename);
|
|
|
-
|
|
|
- // 禁止发出通知,既后台下载,如果要使用这一句必须声明一个权限:android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
|
|
|
- // request.setShowRunningNotification(false);
|
|
|
-
|
|
|
- // 不显示下载界面
|
|
|
- request.setVisibleInDownloadsUi(false);
|
|
|
- request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
|
|
-
|
|
|
- /*
|
|
|
- * 设置下载后文件存放的位置,如果sdcard不可用,那么设置这个将报错,
|
|
|
- * 因此最好不设置如果sdcard可用,下载后的文件 在/mnt/sdcard/Android/
|
|
|
- * data/packageName/files目录下面
|
|
|
- * ,如果sdcard不可用,设置了下面这个将报错,不设置,下载后的文件在/cache这个 目录下面
|
|
|
- */
|
|
|
- // request.setDestinationInExternalFilesDir(this,
|
|
|
- // null, "tar.apk");
|
|
|
-
|
|
|
-// getActivity();
|
|
|
- AlertDialog.Builder builder = new Builder(
|
|
|
- getActivity());
|
|
|
- builder.setMessage(getString(R.string.str_downloadmessage));
|
|
|
-
|
|
|
- builder.setTitle(getString(R.string.str_confirmdownload));
|
|
|
-
|
|
|
- builder.setPositiveButton(
|
|
|
- getString(R.string.str_download),
|
|
|
- new Dialog.OnClickListener()
|
|
|
- {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(
|
|
|
- DialogInterface dialog,
|
|
|
- int which)
|
|
|
- {
|
|
|
- downloadManager.enqueue(request);
|
|
|
- dialog.dismiss();
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- builder.setNegativeButton(
|
|
|
- getString(R.string.str_cancel),
|
|
|
- new Dialog.OnClickListener()
|
|
|
- {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(
|
|
|
- DialogInterface dialog,
|
|
|
- int which)
|
|
|
- {
|
|
|
- dialog.dismiss();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- builder.create().show();
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
+// wv.setDownloadListener(new DownloadListener()
|
|
|
+// {
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void onDownloadStart(String url,
|
|
|
+// String userAgent, String contentDisposition,
|
|
|
+// String mimetype, long contentLength)
|
|
|
+// {
|
|
|
+// if(!commonUtil.localdirExist())
|
|
|
+// {
|
|
|
+//
|
|
|
+// new AlertDialog.Builder(getActivity())
|
|
|
+// .setIconAttribute(android.R.attr.alertDialogIcon)
|
|
|
+// .setTitle(R.string.str_localdir_error)
|
|
|
+// .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
+// public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
+//
|
|
|
+// /* User clicked OK so do some stuff */
|
|
|
+// }
|
|
|
+// })
|
|
|
+// .create().show();
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//// String filename = contentDisposition.replace("attachment;filename=\"", "");
|
|
|
+//// filename = filename.replace("\"", "");
|
|
|
+////
|
|
|
+//// Log.d("WebView", "Download Action");
|
|
|
+//// Log.d("tag", "url=" + url);
|
|
|
+//// // Log.i("tag", "userAgent="+userAgent);
|
|
|
+//// // Log.i("tag",
|
|
|
+//// // "contentDisposition="+contentDisposition);
|
|
|
+//// // Log.i("tag", "mimetype="+mimetype);
|
|
|
+//// // Log.i("tag", "contentLength="+contentLength);
|
|
|
+//// // Uri uri = Uri.parse(url);
|
|
|
+//// // Intent intent = new Intent(Intent.ACTION_VIEW,
|
|
|
+//// // uri);
|
|
|
+//// // startActivity(intent);
|
|
|
+////
|
|
|
+//// final DownloadManager downloadManager = (DownloadManager) ApexTrackingApplication
|
|
|
+//// .get_instance().getSystemService(
|
|
|
+//// Context.DOWNLOAD_SERVICE);
|
|
|
+////
|
|
|
+//// Uri uri = Uri.parse(url);
|
|
|
+//// final Request request = new Request(uri);
|
|
|
+////
|
|
|
+//// // 设置允许使用的网络类型,这里是移动网络和wifi都可以
|
|
|
+//// request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE
|
|
|
+//// | DownloadManager.Request.NETWORK_WIFI);
|
|
|
+////
|
|
|
+////
|
|
|
+////
|
|
|
+//// request.setDestinationInExternalPublicDir("Apex Mobile",filename);
|
|
|
+////
|
|
|
+//// // 禁止发出通知,既后台下载,如果要使用这一句必须声明一个权限:android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
|
|
|
+//// // request.setShowRunningNotification(false);
|
|
|
+////
|
|
|
+//// // 不显示下载界面
|
|
|
+//// request.setVisibleInDownloadsUi(false);
|
|
|
+//// request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
|
|
+////
|
|
|
+//// /*
|
|
|
+//// * 设置下载后文件存放的位置,如果sdcard不可用,那么设置这个将报错,
|
|
|
+//// * 因此最好不设置如果sdcard可用,下载后的文件 在/mnt/sdcard/Android/
|
|
|
+//// * data/packageName/files目录下面
|
|
|
+//// * ,如果sdcard不可用,设置了下面这个将报错,不设置,下载后的文件在/cache这个 目录下面
|
|
|
+//// */
|
|
|
+//// // request.setDestinationInExternalFilesDir(this,
|
|
|
+//// // null, "tar.apk");
|
|
|
+////
|
|
|
+////// getActivity();
|
|
|
+//// AlertDialog.Builder builder = new Builder(
|
|
|
+//// getActivity());
|
|
|
+//// builder.setMessage(getString(R.string.str_downloadmessage));
|
|
|
+////
|
|
|
+//// builder.setTitle(getString(R.string.str_confirmdownload));
|
|
|
+////
|
|
|
+//// builder.setPositiveButton(
|
|
|
+//// getString(R.string.str_download),
|
|
|
+//// new Dialog.OnClickListener()
|
|
|
+//// {
|
|
|
+////
|
|
|
+//// @Override
|
|
|
+//// public void onClick(
|
|
|
+//// DialogInterface dialog,
|
|
|
+//// int which)
|
|
|
+//// {
|
|
|
+//// downloadManager.enqueue(request);
|
|
|
+//// dialog.dismiss();
|
|
|
+////
|
|
|
+//// }
|
|
|
+//// });
|
|
|
+////
|
|
|
+//// builder.setNegativeButton(
|
|
|
+//// getString(R.string.str_cancel),
|
|
|
+//// new Dialog.OnClickListener()
|
|
|
+//// {
|
|
|
+////
|
|
|
+//// @Override
|
|
|
+//// public void onClick(
|
|
|
+//// DialogInterface dialog,
|
|
|
+//// int which)
|
|
|
+//// {
|
|
|
+//// dialog.dismiss();
|
|
|
+//// }
|
|
|
+//// });
|
|
|
+////
|
|
|
+//// builder.create().show();
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// });
|
|
|
control.put(v.getId(), wv.getId());
|
|
|
wv.loadData(content, mimeType, null);
|
|
|
|
|
|
@@ -727,27 +751,60 @@ public class DetailFragment extends Fragment implements OnClickListener /*
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
+ public void download(String url) {
|
|
|
+
|
|
|
+ final String download_url = url;
|
|
|
+// showProgressDialog("Please wait","Downloading...");
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+
|
|
|
+// String cacheDir = ApexTrackingApplication.getInstance().getDocumentDir();
|
|
|
+ // 下载文件
|
|
|
+ final File downloadFile = Network.downloadFile(null,download_url,null);
|
|
|
+
|
|
|
+ getActivity().runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+// progressDialog.dismiss();
|
|
|
+ RAUtil.openFile(getActivity(),downloadFile);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+
|
|
|
public class MyWebViewClient extends WebViewClient
|
|
|
{
|
|
|
// 如果页面中链接,如果希望点击链接继续在当前browser中响应,
|
|
|
// 而不是新开Android的系统browser中响应该链接,必须覆盖 webview的WebViewClient对象。
|
|
|
public boolean shouldOverviewUrlLoading(WebView view, String url)
|
|
|
{
|
|
|
+ Log.d("Web Client", "shouldOverviewUrlLoading: " + url);
|
|
|
// L.i("shouldOverviewUrlLoading");
|
|
|
view.loadUrl(url);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
|
|
+ Log.d("Web Client", "shouldOverrideUrlLoading: " + request);
|
|
|
+ return super.shouldOverrideUrlLoading(view, request);
|
|
|
+ }
|
|
|
+
|
|
|
public void onPageStarted(WebView view, String url, Bitmap favicon)
|
|
|
{
|
|
|
// L.i("onPageStarted");
|
|
|
// showProgress();
|
|
|
+ Log.d("Web Client", "onPageStarted: ");
|
|
|
}
|
|
|
|
|
|
public void onPageFinished(WebView view, String url)
|
|
|
{
|
|
|
// L.i("onPageFinished");
|
|
|
// closeProgress();
|
|
|
+ Log.d("Web Client", "onPageFinished: ");
|
|
|
}
|
|
|
|
|
|
public void onReceivedError(WebView view, int errorCode,
|
|
|
@@ -755,7 +812,33 @@ public class DetailFragment extends Fragment implements OnClickListener /*
|
|
|
{
|
|
|
// L.i("onReceivedError");
|
|
|
// closeProgress();
|
|
|
+ Log.d("Web Client", "onReceivedError: ");
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
|
|
+
|
|
|
+ Log.d("Web Client", "shouldInterceptRequest: " + url);
|
|
|
+ if (url.startsWith("http") && url.contains("action_type=download_doc")) {
|
|
|
+ download(url);
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return super.shouldInterceptRequest(view,url);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
|
|
+// Log.d("Web Client", "shouldInterceptRequest: " + request);
|
|
|
+//
|
|
|
+// if (request.getUrl().toString().contains("action_type=download_doc")) {
|
|
|
+// return null;
|
|
|
+// } else {
|
|
|
+// return super.shouldInterceptRequest(view,request);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
}
|