导航菜单

页面标题

页面副标题

AdaModal v1.4.0 - BridgeWebActivity.java 源代码

正在查看: AdaModal v1.4.0 应用的 BridgeWebActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.common.fine.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.hardware.SensorManager;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Bundle;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.PermissionRequest;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.net.MailTo;
import androidx.core.view.OnApplyWindowInsetsListener;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.databinding.DataBindingUtil;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.StringUtils;
import com.common.fine.R;
import com.common.fine.constant.SPConstant;
import com.common.fine.databinding.ActivityBridgeWebBinding;
import com.common.fine.event.LoginChangeEvent;
import com.common.fine.utils.ChannelUtils;
import com.common.fine.utils.ExpUtils;
import com.common.fine.utils.PermissionUtils;
import com.common.fine.utils.jsbridge.BridgeWebViewClient;
import com.common.fine.utils.jsbridge.CallbackBridgeRegister;
import com.common.fine.utils.jsbridge.FileChooserAdapter;
import com.common.fine.utils.preference.ESPUtils;
import com.common.fine.utils.twebview.OneWayFuncRegister;
import com.common.fine.widget.dialog.StopDialog;
import com.squareup.seismic.ShakeDetector;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class BridgeWebActivity extends AppCompatActivity {
    private ActivityBridgeWebBinding binding;
    private Activity mActivity;
    private CallbackBridgeRegister mCallbackBridgeRegister;
    private boolean mDebugDialogShow = false;
    private FileChooserAdapter mFileChooserAdapter;
    private String mHomeUrl;
    private SensorManager mSensorManager;
    private ShakeDetector mShakeDetector;
    StopDialog stopDialog;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onLoginStateChange(LoginChangeEvent loginChangeEvent) {
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        EdgeToEdge.enable(this);
        this.mActivity = this;
        this.binding = (ActivityBridgeWebBinding) DataBindingUtil.setContentView(this, R.layout.activity_bridge_web);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.web_main), new OnApplyWindowInsetsListener() {
            @Override
            public final WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsetsCompat) {
                return BridgeWebActivity.lambda$onCreate$0(view, windowInsetsCompat);
            }
        });
        this.binding.statusLayout.setRetryListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                BridgeWebActivity.this.lambda$onCreate$1(view);
            }
        });
        String stringExtra = getIntent().getStringExtra("url");
        this.mHomeUrl = stringExtra;
        if (!StringUtils.isTrimEmpty(stringExtra)) {
            initWebView(this.mHomeUrl);
        }
        EventBus.getDefault().register(this);
    }

    static WindowInsetsCompat lambda$onCreate$0(View view, WindowInsetsCompat windowInsetsCompat) {
        boolean isVisible = windowInsetsCompat.isVisible(WindowInsetsCompat.Type.ime());
        int i = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.ime()).bottom;
        Insets insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.systemBars());
        int i2 = insets.left;
        int i3 = insets.top;
        int i4 = insets.right;
        if (!isVisible) {
            i = insets.bottom;
        }
        view.setPadding(i2, i3, i4, i);
        return windowInsetsCompat;
    }

    public void lambda$onCreate$1(View view) {
        reloadWebView();
    }

    private void initWebView(String str) {
        getWindow().addFlags(16777216);
        this.mFileChooserAdapter = new FileChooserAdapter(this);
        this.mCallbackBridgeRegister = new CallbackBridgeRegister(this, this.binding.webViewWeb);
        this.binding.webViewWeb.setDownloadListener(getDownloadListener());
        this.binding.webViewWeb.setWebChromeClient(getChromeClient());
        this.binding.webViewWeb.setWebViewClient(getWebViewClient());
        registerJavaHandlers();
        if (!StringUtils.isTrimEmpty(str)) {
            if (NetworkUtils.isConnected()) {
                this.binding.statusLayout.showContent();
            } else {
                this.binding.statusLayout.showNoNetwork();
            }
            this.binding.webViewWeb.loadUrl(str);
        } else {
            this.binding.statusLayout.showError();
        }
        initShakeDetector();
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (this.mSensorManager == null) {
            this.mSensorManager = (SensorManager) getSystemService("sensor");
        }
        if (this.mShakeDetector == null) {
            this.mShakeDetector = new ShakeDetector(new BridgeWebActivity$$ExternalSyntheticLambda2(this));
        }
        this.mShakeDetector.start(this.mSensorManager);
    }

    @Override
    protected void onStop() {
        super.onStop();
        this.mShakeDetector.stop();
    }

    private void initShakeDetector() {
        this.mSensorManager = (SensorManager) getSystemService("sensor");
        this.mShakeDetector = new ShakeDetector(new BridgeWebActivity$$ExternalSyntheticLambda2(this));
    }

    public void onDeviceShake() {
        if (!ChannelUtils.isTestEnv() || this.mDebugDialogShow) {
            return;
        }
        final EditText editText = new EditText(this);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public final void onCancel(DialogInterface dialogInterface) {
                BridgeWebActivity.this.lambda$onDeviceShake$2(dialogInterface);
            }
        });
        builder.setTitle("Input Base Url").setView(editText);
        builder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                BridgeWebActivity.this.lambda$onDeviceShake$3(editText, dialogInterface, i);
            }
        });
        String string = ESPUtils.getInstance().getString(SPConstant.TEST_ENV_BASE_URL);
        if (StringUtils.isTrimEmpty(string)) {
            string = "http://";
        }
        editText.setText(string);
        builder.show();
        this.mDebugDialogShow = true;
    }

    public void lambda$onDeviceShake$2(DialogInterface dialogInterface) {
        this.mDebugDialogShow = false;
    }

    public void lambda$onDeviceShake$3(EditText editText, DialogInterface dialogInterface, int i) {
        String obj = editText.getText().toString();
        if (obj.equals("http://")) {
            obj = "";
        }
        ESPUtils.getInstance().put(SPConstant.TEST_ENV_BASE_URL, obj);
        finish();
    }

    private WebViewClient getWebViewClient() {
        return new BridgeWebViewClient(this.binding.webViewWeb, ChannelUtils.isLicenseEnv()) {
            @Override
            public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
                try {
                    BridgeWebActivity.this.binding.statusLayout.showError();
                    sslErrorHandler.cancel();
                } catch (Exception e) {
                    ExpUtils.show(e);
                }
            }

            @Override
            public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
                if (webResourceRequest.isForMainFrame()) {
                    BridgeWebActivity.this.binding.statusLayout.showError();
                }
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String str) {
                if (str != null && (str.startsWith(MailTo.MAILTO_SCHEME) || str.startsWith("tel:"))) {
                    BridgeWebActivity.this.startBrowseAction(str);
                    return true;
                }
                return super.shouldOverrideUrlLoading(webView, str);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
                try {
                    return shouldOverrideUrlLoading(webView, webResourceRequest.getUrl().toString());
                } catch (Exception e) {
                    ExpUtils.show(e);
                    return super.shouldOverrideUrlLoading(webView, webResourceRequest);
                }
            }

            @Override
            protected boolean onCustomShouldOverrideUrlLoading(String str) {
                return super.onCustomShouldOverrideUrlLoading(str);
            }

            @Override
            protected void onCustomPageFinished(WebView webView, String str) {
                super.onCustomPageFinished(webView, str);
            }
        };
    }

    private WebChromeClient getChromeClient() {
        return new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView webView, int i) {
                super.onProgressChanged(webView, i);
                if (i > 0 && i < 100) {
                    BridgeWebActivity.this.binding.webViewProgress.setProgress(i);
                    BridgeWebActivity.this.binding.webViewProgress.setVisibility(0);
                } else {
                    BridgeWebActivity.this.binding.webViewProgress.setVisibility(8);
                }
            }

            @Override
            public void onReceivedTitle(WebView webView, String str) {
                super.onReceivedTitle(webView, str);
            }

            public void openFileChooser(ValueCallback<Uri> valueCallback, String str, String str2) {
                BridgeWebActivity.this.mFileChooserAdapter.openFileChooser(valueCallback, str, str2);
            }

            @Override
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
                return BridgeWebActivity.this.mFileChooserAdapter.onShowFileChooser(webView, valueCallback, fileChooserParams);
            }

            @Override
            public void onPermissionRequest(PermissionRequest permissionRequest) {
                if (permissionRequest.getResources().length > 0) {
                    for (String str : permissionRequest.getResources()) {
                        if (str.equals("android.webkit.resource.VIDEO_CAPTURE")) {
                            permissionRequest.grant(permissionRequest.getResources());
                            return;
                        }
                    }
                }
                permissionRequest.deny();
            }

            @Override
            public Bitmap getDefaultVideoPoster() {
                return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
            }
        };
    }

    public void reloadWebView() {
        if (NetworkUtils.isConnected()) {
            this.binding.webViewWeb.reload();
            this.binding.statusLayout.setStatus(1);
        } else {
            this.binding.statusLayout.setStatus(2);
        }
    }

    @Override
    public void onBackPressed() {
        if (this.binding.webViewWeb.canGoBack()) {
            this.binding.webViewWeb.goBack();
        } else {
            super.onBackPressed();
        }
    }

    private void registerJavaHandlers() {
        OneWayFuncRegister.registerOneWayHandlers(this.binding.webViewWeb, this);
        this.mCallbackBridgeRegister.registerCommonHandlers();
    }

    @Override
    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (this.mFileChooserAdapter.onActivityResult(i, i2, intent)) {
            return;
        }
        try {
            this.mCallbackBridgeRegister.onActivityResult(i, i2, intent);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private DownloadListener getDownloadListener() {
        return new DownloadListener() {
            @Override
            public final void onDownloadStart(String str, String str2, String str3, String str4, long j) {
                BridgeWebActivity.this.lambda$getDownloadListener$4(str, str2, str3, str4, j);
            }
        };
    }

    public void lambda$getDownloadListener$4(String str, String str2, String str3, String str4, long j) {
        startBrowseAction(str);
    }

    public void startBrowseAction(String str) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.addCategory("android.intent.category.BROWSABLE");
            intent.setData(Uri.parse(str));
            startActivity(intent);
        } catch (Exception e) {
            ExpUtils.show(e);
        }
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (i != 2) {
            return;
        }
        PermissionUtils.checkMorePermissions(this.mActivity, strArr, new PermissionUtils.PermissionCheckCallBack() {
            @Override
            public void onHasPermission() {
                BridgeWebActivity.this.dismissStopDialog();
            }

            @Override
            public void onUserHasAlreadyTurnedDown(String... strArr2) {
                if (ESPUtils.getInstance().getBoolean(SPConstant.NEED_STOP)) {
                    BridgeWebActivity.this.showStopDialog(true, strArr2);
                }
            }

            @Override
            public void onUserHasAlreadyTurnedDownAndDontAsk(String... strArr2) {
                if (ESPUtils.getInstance().getBoolean(SPConstant.NEED_STOP)) {
                    BridgeWebActivity.this.showStopDialog(false, strArr2);
                }
            }
        });
    }

    protected void showStopDialog(boolean z, final String... strArr) {
        StopDialog stopDialog = this.stopDialog;
        if (stopDialog == null || !stopDialog.isShowing()) {
            StopDialog stopDialog2 = new StopDialog(this.mActivity);
            this.stopDialog = stopDialog2;
            stopDialog2.setCanceledOnTouchOutside(false);
            this.stopDialog.setCancelable(false);
            if (z) {
                this.stopDialog.setTvEnableClickCallback(new StopDialog.EnableCallback() {
                    @Override
                    public void callback() {
                        PermissionUtils.requestMorePermissions(BridgeWebActivity.this.mActivity, strArr, 2);
                    }
                });
            }
            this.stopDialog.show();
        }
    }

    protected void dismissStopDialog() {
        StopDialog stopDialog = this.stopDialog;
        if (stopDialog == null || !stopDialog.isShowing()) {
            return;
        }
        this.stopDialog.dismiss();
    }

    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);
        this.mShakeDetector.stop();
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        this.binding.webViewWeb.resumeTimers();
        this.binding.webViewWeb.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        this.binding.webViewWeb.pauseTimers();
        this.binding.webViewWeb.onPause();
    }
}