|
@@ -0,0 +1,503 @@
|
|
|
+package com.hongyegroup.cpt_main.ui;
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+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.widget.FrameLayout;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.guadou.cs_cptservices.YYConstants;
|
|
|
+import com.guadou.cs_cptservices.widget.PickPhotoDialog;
|
|
|
+import com.guadou.lib_baselib.base.activity.BaseVMActivity;
|
|
|
+import com.guadou.lib_baselib.base.vm.BaseViewModel;
|
|
|
+import com.guadou.lib_baselib.engine.PermissionExtKt;
|
|
|
+import com.guadou.lib_baselib.engine.image_select.ImageSelectExtKt;
|
|
|
+import com.guadou.lib_baselib.provider.PermissionFileProvider;
|
|
|
+import com.guadou.lib_baselib.utils.CheckUtil;
|
|
|
+import com.guadou.lib_baselib.utils.CommUtils;
|
|
|
+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.WebViewProgressBar;
|
|
|
+import com.hongyegroup.cpt_main.R;
|
|
|
+import com.luck.picture.lib.entity.LocalMedia;
|
|
|
+import com.luck.picture.lib.listener.OnResultCallbackListener;
|
|
|
+import com.luck.picture.lib.tools.ToastUtils;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.annotation.RequiresApi;
|
|
|
+import kotlin.Unit;
|
|
|
+import kotlin.jvm.functions.Function0;
|
|
|
+
|
|
|
+
|
|
|
+ * V11 Me页面的帮助中心
|
|
|
+ * 内部处理
|
|
|
+ */
|
|
|
+public class HelpCenterProfileH5Activity extends BaseVMActivity<BaseViewModel> {
|
|
|
+
|
|
|
+ private String mWebtitle;
|
|
|
+ private String mWeburl;
|
|
|
+ private WebViewProgressBar mPbWebView;
|
|
|
+ private FrameLayout mFlContent;
|
|
|
+ private MyWebView mWebView;
|
|
|
+ private TextView mTvTitle;
|
|
|
+ private ImageView mIvBack;
|
|
|
+ private ImageView mIvFinish;
|
|
|
+ private ImageView mIvSearch;
|
|
|
+
|
|
|
+ private String mHelpCenterUrl = "";
|
|
|
+
|
|
|
+ public static void startInstance(String helpCenterUrl) {
|
|
|
+ Context context = CommUtils.getContext();
|
|
|
+ Intent intent = new Intent(context, HelpCenterProfileH5Activity.class);
|
|
|
+ intent.putExtra("helpCenterUrl", helpCenterUrl);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ context.startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void getDataFromIntent(Intent intent) {
|
|
|
+ super.getDataFromIntent(intent);
|
|
|
+ mHelpCenterUrl = intent.getStringExtra("helpCenterUrl");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void init(@Nullable Bundle savedInstanceState) {
|
|
|
+
|
|
|
+ mWebtitle = "Help Center";
|
|
|
+
|
|
|
+ mWeburl = mHelpCenterUrl + "?token=" + SPUtils.getInstance(CommUtils.getContext()).getString(YYConstants.USER_TOKEN, "");
|
|
|
+
|
|
|
+ initView();
|
|
|
+ initTitles();
|
|
|
+ initWeb();
|
|
|
+ initListener();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getLayoutIdRes() {
|
|
|
+
|
|
|
+ return R.layout.activity_help_center;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void startObserve() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ mIvBack.setOnClickListener(v -> {
|
|
|
+
|
|
|
+ webgoBack();
|
|
|
+ });
|
|
|
+
|
|
|
+ mIvFinish.setOnClickListener(v -> {
|
|
|
+ finish();
|
|
|
+ });
|
|
|
+
|
|
|
+ mIvSearch.setOnClickListener(v -> {
|
|
|
+ if (mWebView != null) {
|
|
|
+ mWebView.loadUrl(mHelpCenterUrl + "/search");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void webgoBack() {
|
|
|
+ if (ThreadPoolUtils.getCachedThreadPool() != null) {
|
|
|
+ ThreadPoolUtils.getCachedThreadPool().execute(() -> {
|
|
|
+ try {
|
|
|
+ Instrumentation inst = new Instrumentation();
|
|
|
+ inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initTitles() {
|
|
|
+ if (!CheckUtil.isEmpty(mWebtitle) && mTvTitle != null) {
|
|
|
+ mTvTitle.setText(mWebtitle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @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.addJavascriptInterface(new H5CallBackAndroid(), "webkit");
|
|
|
+
|
|
|
+ mWebView.setWebChromeClient(new WebChromeClient() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReceivedTitle(WebView view, String title) {
|
|
|
+ YYLogUtils.e("title" + 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) {
|
|
|
+
|
|
|
+ if (newProgress == 100) {
|
|
|
+ mPbWebView.setProgress(100);
|
|
|
+ CommUtils.getHandler().postDelayed(() -> mPbWebView.setVisibility(View.GONE), 200);
|
|
|
+ } else if (mPbWebView.getVisibility() == View.GONE) {
|
|
|
+ mPbWebView.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (newProgress < 10) {
|
|
|
+ newProgress = 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ mPbWebView.setProgress(newProgress);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
|
|
+ boolean allow = true;
|
|
|
+ boolean retain = false;
|
|
|
+ callback.invoke(origin, true, false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGeolocationPermissionsHidePrompt() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
|
+ @Override
|
|
|
+ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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
|
|
|
+ public void onInnerLinkChecked() {
|
|
|
+ mIvFinish.setVisibility(View.VISIBLE);
|
|
|
+ YYLogUtils.e("onInnerLinkChecked" + mWebView.canGoBack());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onWebLoadError() {
|
|
|
+ ToastUtils.s(mActivity, "Load Error!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ YYLogUtils.e("mWeburl:" + mWeburl);
|
|
|
+ if (!TextUtils.isEmpty(mWeburl))
|
|
|
+ mWebView.loadUrl(mWeburl);
|
|
|
+
|
|
|
+ mFlContent.addView(mWebView);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isCancel = true;
|
|
|
+
|
|
|
+
|
|
|
+ * 相机相册的选择
|
|
|
+ */
|
|
|
+ private void showPickDialog() {
|
|
|
+
|
|
|
+ PickPhotoDialog photoDialog = new PickPhotoDialog(mActivity);
|
|
|
+ photoDialog.SetOnChooseClickListener(new PickPhotoDialog.OnChooseClickListener() {
|
|
|
+ @Override
|
|
|
+ public void chooseCamera() {
|
|
|
+ isCancel = false;
|
|
|
+ startCamera();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void chooseAlbum() {
|
|
|
+ isCancel = false;
|
|
|
+ startAlbum();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ photoDialog.setCancelable(false);
|
|
|
+ photoDialog.show();
|
|
|
+ photoDialog.setOnDismissListener(dialog -> {
|
|
|
+ cancelFilePick();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void startAlbum() {
|
|
|
+
|
|
|
+ ImageSelectExtKt.extOpenImageSelect(mActivity, new ArrayList<LocalMedia>(), new OnResultCallbackListener<LocalMedia>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResult(List<LocalMedia> result) {
|
|
|
+
|
|
|
+ handlePath(result);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCancel() {
|
|
|
+
|
|
|
+ cancelFilePick();
|
|
|
+
|
|
|
+ }
|
|
|
+ }, 1, false, false, true, 1, 1, false);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void startCamera() {
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 处理图片-转换图片-返回给Web
|
|
|
+ */
|
|
|
+ private void handlePath(List<LocalMedia> result) {
|
|
|
+ YYLogUtils.w("处理图片-转换图片-返回给Web");
|
|
|
+
|
|
|
+ if (!CheckUtil.isEmpty(result)) {
|
|
|
+
|
|
|
+ String path = result.get(0).getCompressPath();
|
|
|
+
|
|
|
+
|
|
|
+ Uri fileUri = Uri.fromFile(new File(path));
|
|
|
+
|
|
|
+
|
|
|
+ if (filePathCallback1 != null) {
|
|
|
+ filePathCallback1.onReceiveValue(new Uri[]{fileUri});
|
|
|
+ filePathCallback1 = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ isCancel = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void cancelFilePick() {
|
|
|
+ if (isCancel && filePathCallback1 != null) {
|
|
|
+ YYLogUtils.w("取消图片的选择");
|
|
|
+ filePathCallback1.onReceiveValue(null);
|
|
|
+ filePathCallback1 = null;
|
|
|
+ }
|
|
|
+ isCancel = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private class H5CallBackAndroid {
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void callPhone(String phoneNum) {
|
|
|
+
|
|
|
+
|
|
|
+ PermissionExtKt.extRequestPermission(mActivity, new String[]{Manifest.permission.CALL_PHONE}, new Function0<Unit>() {
|
|
|
+ @Override
|
|
|
+ public Unit invoke() {
|
|
|
+
|
|
|
+ call();
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void call(){
|
|
|
+
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setAction(Intent.ACTION_CALL);
|
|
|
+ Uri uri = Uri.parse("tel:" + "+65 66046919");
|
|
|
+ intent.setData(uri);
|
|
|
+ startActivity(intent);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void EmailUsSuccess(Object obj) {
|
|
|
+ YYLogUtils.e("回调EmailUsSuccess");
|
|
|
+ webgoBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
+ mPbWebView = findViewById(R.id.pb_web_view);
|
|
|
+ mFlContent = findViewById(R.id.fl_content);
|
|
|
+ mTvTitle = findViewById(R.id.tv_title);
|
|
|
+ mIvBack = findViewById(R.id.iv_back);
|
|
|
+ mIvFinish = findViewById(R.id.iv_finish);
|
|
|
+ mIvSearch = findViewById(R.id.iv_search);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 回调的图片选择
|
|
|
+ */
|
|
|
+ private ValueCallback<Uri[]> filePathCallback1;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+
|
|
|
+ if (requestCode == 99) {
|
|
|
+ if (resultCode == RESULT_OK && null != data) {
|
|
|
+ Uri selectedImage = data.getData();
|
|
|
+ filePathCallback1.onReceiveValue(new Uri[]{selectedImage});
|
|
|
+ } else {
|
|
|
+
|
|
|
+ filePathCallback1.onReceiveValue(new Uri[]{});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 集成了系统的回退和网页的回退
|
|
|
+ */
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+ if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
|
|
|
+ mWebView.goBack();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return super.onKeyDown(keyCode, event);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ if (mWebView != null) {
|
|
|
+ mWebView.onPause();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ if (mWebView != null) {
|
|
|
+ mWebView.onResume();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|