|
@@ -6,23 +6,19 @@ import android.app.Instrumentation;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
-import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
-import android.webkit.GeolocationPermissions;
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
import android.webkit.ValueCallback;
|
|
|
-import android.webkit.WebChromeClient;
|
|
|
-import android.webkit.WebView;
|
|
|
+import android.webkit.WebBackForwardList;
|
|
|
import android.widget.FrameLayout;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
-import androidx.annotation.RequiresApi;
|
|
|
|
|
|
import com.guadou.cs_cptservices.YYConstants;
|
|
|
import com.guadou.cs_cptservices.widget.PickPhotoDialog;
|
|
@@ -37,6 +33,7 @@ import com.guadou.lib_baselib.utils.SPUtils;
|
|
|
import com.guadou.lib_baselib.utils.ThreadPoolUtils;
|
|
|
import com.guadou.lib_baselib.utils.log.YYLogUtils;
|
|
|
import com.guadou.lib_baselib.view.MyWebView;
|
|
|
+import com.guadou.lib_baselib.view.WebViewManager;
|
|
|
import com.guadou.lib_baselib.view.WebViewProgressBar;
|
|
|
import com.hongyegroup.cpt_main.R;
|
|
|
import com.luck.picture.lib.entity.LocalMedia;
|
|
@@ -147,41 +144,38 @@ public class HelpCenterProfileH5Activity extends BaseVMActivity<BaseViewModel> {
|
|
|
@SuppressLint("AddJavascriptInterface")
|
|
|
private void initWeb() {
|
|
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
- mWebView = new MyWebView(getApplicationContext());
|
|
|
- mWebView.setLayoutParams(params);
|
|
|
|
|
|
- //允许访问多媒体
|
|
|
- mWebView.getSettings().setAllowFileAccess(true);
|
|
|
- mWebView.getSettings().setAllowFileAccessFromFileURLs(true);
|
|
|
- mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
|
|
|
+ mWebView = WebViewManager.obtain(CommUtils.getContext());
|
|
|
+ mWebView.setLayoutParams(params);
|
|
|
|
|
|
mWebView.addJavascriptInterface(new H5CallBackAndroid(), "webkit");
|
|
|
|
|
|
- mWebView.setWebChromeClient(new WebChromeClient() {
|
|
|
- //获取html的title标签
|
|
|
+ //文件与图片的选择回调
|
|
|
+ mWebView.setOnWebChooseFileListener(new MyWebView.OnWebChooseFileListener() {
|
|
|
+ @Override
|
|
|
+ public void onWebFileSelect(ValueCallback<Uri[]> callback) {
|
|
|
+ filePathCallback1 = callback;
|
|
|
+ showPickDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //网络状态回调
|
|
|
+ mWebView.setOnWebChangeListener(new MyWebView.OnWebChangeListener() {
|
|
|
@Override
|
|
|
- public void onReceivedTitle(WebView view, String title) {
|
|
|
- YYLogUtils.e("title" + title);
|
|
|
+ public void titleChange(String title) {
|
|
|
|
|
|
if (!CheckUtil.isEmpty(title) && mTvTitle != null && !title.equals("common_html")) {
|
|
|
mTvTitle.setText(title);
|
|
|
-
|
|
|
if (title.equals("Help Center")) {
|
|
|
-
|
|
|
mIvSearch.setVisibility(View.VISIBLE);
|
|
|
-
|
|
|
} else {
|
|
|
-
|
|
|
mIvSearch.setVisibility(View.GONE);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
- super.onReceivedTitle(view, title);
|
|
|
}
|
|
|
|
|
|
- //获取页面加载的进度
|
|
|
@Override
|
|
|
- public void onProgressChanged(WebView view, int newProgress) {
|
|
|
+ public void progressChange(int newProgress) {
|
|
|
|
|
|
if (newProgress == 100) {
|
|
|
mPbWebView.setProgress(100);
|
|
@@ -195,48 +189,6 @@ public class HelpCenterProfileH5Activity extends BaseVMActivity<BaseViewModel> {
|
|
|
}
|
|
|
//不断更新进度
|
|
|
mPbWebView.setProgress(newProgress);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 指定源的网页内容在没有设置权限状态下尝试使用地理位置API。
|
|
|
- @Override
|
|
|
- public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
|
|
- boolean allow = true; // 是否允许origin使用定位API
|
|
|
- boolean retain = false; // 内核是否记住这次制授权
|
|
|
- callback.invoke(origin, true, false);
|
|
|
- }
|
|
|
-
|
|
|
- // 之前调用 onGeolocationPermissionsShowPrompt() 申请的授权被取消时,隐藏相关的UI。
|
|
|
- @Override
|
|
|
- public void onGeolocationPermissionsHidePrompt() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
|
- @Override
|
|
|
- public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
|
|
|
- //启动系统相册
|
|
|
-// Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
|
|
-// startActivityForResult(intent, 99);
|
|
|
- YYLogUtils.w("网页尝试调取Android相机相册");
|
|
|
- filePathCallback1 = filePathCallback;
|
|
|
- CommUtils.getHandler().post(() -> {
|
|
|
- showPickDialog();
|
|
|
- });
|
|
|
-
|
|
|
- return true;
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- mWebView.setOnWebChangeListener(new MyWebView.OnWebChangeListener() {
|
|
|
- @Override
|
|
|
- public void titleChange(String title) {
|
|
|
- YYLogUtils.e("titleChange-" + title);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void progressChange(int newProgress) {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -298,16 +250,12 @@ public class HelpCenterProfileH5Activity extends BaseVMActivity<BaseViewModel> {
|
|
|
|
|
|
@Override
|
|
|
public void onResult(List<LocalMedia> result) {
|
|
|
-
|
|
|
handlePath(result);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onCancel() {
|
|
|
-
|
|
|
cancelFilePick();
|
|
|
-
|
|
|
}
|
|
|
}, 1, false, false, true, 1, 1, false);
|
|
|
|
|
@@ -326,16 +274,12 @@ public class HelpCenterProfileH5Activity extends BaseVMActivity<BaseViewModel> {
|
|
|
ImageSelectExtKt.extOpenCamera(mActivity, new ArrayList<LocalMedia>(), new OnResultCallbackListener<LocalMedia>() {
|
|
|
@Override
|
|
|
public void onResult(List<LocalMedia> result) {
|
|
|
-
|
|
|
handlePath(result);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onCancel() {
|
|
|
-
|
|
|
cancelFilePick();
|
|
|
-
|
|
|
}
|
|
|
}, false, true, 1, 1);
|
|
|
|
|
@@ -448,9 +392,31 @@ public class HelpCenterProfileH5Activity extends BaseVMActivity<BaseViewModel> {
|
|
|
* 集成了系统的回退和网页的回退
|
|
|
*/
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+
|
|
|
+ WebBackForwardList webBackForwardList = mWebView.copyBackForwardList();
|
|
|
+ String historyOneOriginalUrl = webBackForwardList.getItemAtIndex(0).getOriginalUrl();
|
|
|
+ int curIndex = webBackForwardList.getCurrentIndex();
|
|
|
+
|
|
|
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
|
|
|
- mWebView.goBack();
|
|
|
- return true;
|
|
|
+
|
|
|
+ //判断是否是缓存的WebView
|
|
|
+ if (historyOneOriginalUrl.contains("data:text/html;charset=utf-8")) {
|
|
|
+ //说明是缓存复用的的WebView
|
|
|
+ if (curIndex > 1) {
|
|
|
+ //内部跳转到另外的页面了,可以返回的
|
|
|
+ mWebView.goBack();
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ //等于1的时候就要Finish页面了
|
|
|
+ return super.onKeyDown(keyCode, event);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //如果不是缓存复用的WebView,可以直接返回
|
|
|
+ mWebView.goBack();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
}
|
|
@@ -474,25 +440,7 @@ public class HelpCenterProfileH5Activity extends BaseVMActivity<BaseViewModel> {
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
- if (mWebView != null) {
|
|
|
- mWebView.clearCache(true); //清空缓存
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- if (mFlContent != null) {
|
|
|
- mFlContent.removeView(mWebView);
|
|
|
- }
|
|
|
- mWebView.removeAllViews();
|
|
|
- mWebView.destroy();
|
|
|
- } else {
|
|
|
- mWebView.removeAllViews();
|
|
|
- mWebView.destroy();
|
|
|
- if (mFlContent != null) {
|
|
|
- mFlContent.removeView(mWebView);
|
|
|
- }
|
|
|
- }
|
|
|
- mWebView = null;
|
|
|
- }
|
|
|
+ WebViewManager.recycle(mWebView);
|
|
|
|
|
|
- //退出当前web进程
|
|
|
-// System.exit(0);
|
|
|
}
|
|
|
}
|