导航菜单

页面标题

页面副标题

Petal Maps v4.7.0.310001 - MapProgressWebView.java 源代码

正在查看: Petal Maps v4.7.0.310001 应用的 MapProgressWebView.java JAVA 源代码文件

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


package com.huawei.maps.commonui.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.GeolocationPermissions;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;
import com.huawei.maps.businessbase.R;
import com.huawei.maps.commonui.view.MapProgressWebView;
import com.huawei.secure.android.common.intent.IntentUtils;
import com.huawei.secure.android.common.intent.SafeIntent;
import com.huawei.secure.android.common.ssl.WebViewSSLCheck;
import com.huawei.secure.android.common.webview.SafeWebSettings;
import com.huawei.secure.android.common.webview.SafeWebView;
import defpackage.ct3;
import defpackage.cz9;
import defpackage.j65;
import defpackage.o9a;
import java.util.Optional;
import java.util.function.Consumer;

public class MapProgressWebView extends LinearLayout {
    public MapHorizontalProgressBar a;
    public MapSafeWebView b;
    public boolean c;
    public boolean d;
    public WebPageTitleListener e;
    public PageLoadFinishListener f;
    public CheckShouldOverrideUrlLoadingListener g;
    public boolean h;
    public boolean i;
    public float j;
    public boolean k;
    public boolean l;

    public interface CheckShouldOverrideUrlLoadingListener {
        boolean checkShouldOverrideUrlLoading(String str);
    }

    public interface PageLoadFinishListener {
        void onPageFinish();
    }

    public interface WebPageTitleListener {
        void onTitleObtained(String str);
    }

    public @interface WebViewLifeState {
        public static final int WEB_VIEW_LIFE_ON_DESTROY = 2;
        public static final int WEB_VIEW_LIFE_ON_PAUSE = 1;
        public static final int WEB_VIEW_LIFE_ON_RESUME = 0;
    }

    public class a extends j65 {
        public a() {
        }

        @Override
        public void onPageFinished(WebView webView, String str) {
            super.onPageFinished(webView, str);
            if (MapProgressWebView.this.f != null) {
                MapProgressWebView.this.f.onPageFinish();
            }
        }

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

        @Override
        public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
            if (sslErrorHandler == null || sslError == null) {
                return;
            }
            WebViewSSLCheck.checkServerCertificateNew(sslErrorHandler, sslError, o41.c());
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            if (MapProgressWebView.this.g != null && !MapProgressWebView.this.g.checkShouldOverrideUrlLoading(str)) {
                return false;
            }
            if (!MapProgressWebView.this.c) {
                return super.shouldOverrideUrlLoading(webView, str);
            }
            try {
                Intent safeIntent = new SafeIntent(new Intent("android.intent.action.VIEW", !TextUtils.isEmpty(str) ? Uri.parse(str) : null));
                if (o41.b().getPackageManager().queryIntentActivities(safeIntent, 0).size() <= 0) {
                    cz9.j(R.string.no_web);
                    return true;
                }
                safeIntent.addFlags(268435456);
                if (IntentUtils.safeStartActivity(o41.c(), safeIntent)) {
                    return true;
                }
                cz9.j(R.string.no_web);
                return true;
            } catch (NullPointerException unused) {
                hm4.h("MapSafeWebView", "parse url err");
                return true;
            }
        }
    }

    public static class b {
        public Object a;
        public String b;

        public b(Object obj, String str) {
            this.a = obj;
            this.b = str;
        }
    }

    public static class c {
        @JavascriptInterface
        public String getLanguage() {
            return br3.a();
        }
    }

    public static class d {
        @JavascriptInterface
        public String getAuthInfo() {
            return "";
        }
    }

    public static class e {
        @JavascriptInterface
        public String getBackgroundMode() {
            return o9a.d() ? "black" : "white";
        }
    }

    public MapProgressWebView(Context context) {
        this(context, null);
    }

    @SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
    public void g(b bVar) {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return;
        }
        safeWebView.addJavascriptInterface(bVar.a, bVar.b);
    }

    public boolean h() {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return false;
        }
        return safeWebView.canGoBack();
    }

    public void i() {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return;
        }
        safeWebView.goBack();
    }

    public final void j(Context context, AttributeSet attributeSet, int i) {
        if (attributeSet != null) {
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MapProgressWebView);
            this.h = obtainStyledAttributes.getBoolean(R.styleable.MapProgressWebView_useNestedWebView, false);
            obtainStyledAttributes.recycle();
        }
        setOrientation(1);
        ?? mapHorizontalProgressBar = new MapHorizontalProgressBar(context);
        this.a = mapHorizontalProgressBar;
        mapHorizontalProgressBar.setProgressDrawable(context.getDrawable(R.drawable.hwprogressbar_horizontal_emui));
        addView((View) this.a, new LinearLayout.LayoutParams(-1, ct3.b(context, 2.0f)));
        this.a.setVisibility(8);
        try {
            if (this.h) {
                this.b = new NestedScrollingWebView(context);
            } else {
                this.b = new MapSafeWebView(context);
            }
            addView((View) this.b, new LinearLayout.LayoutParams(-1, -1));
            l();
        } catch (Exception e2) {
            o05.c(e2, true);
            hm4.p("MapSafeWebView", "mSafeWebView int Exception");
        }
    }

    public final void k() {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return;
        }
        safeWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onGeolocationPermissionsShowPrompt(String str, GeolocationPermissions.Callback callback) {
                if (MapProgressWebView.this.i && sl4.e()) {
                    callback.invoke(str, true, true);
                }
            }

            @Override
            public void onProgressChanged(WebView webView, int i) {
                super.onProgressChanged(webView, i);
                if (i != 100) {
                    if (8 == MapProgressWebView.this.a.getVisibility() && MapProgressWebView.this.l) {
                        MapProgressWebView.this.a.setVisibility(0);
                    }
                    MapProgressWebView.this.a.setProgress(i);
                    return;
                }
                MapProgressWebView.this.a.setVisibility(8);
                WebPageTitleListener webPageTitleListener = MapProgressWebView.this.e;
                if (webPageTitleListener != null) {
                    webPageTitleListener.onTitleObtained(webView.getTitle());
                }
            }
        });
        this.b.setWebViewClient(new a(), false);
    }

    @SuppressLint({"SetJavaScriptEnabled"})
    public final void l() {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return;
        }
        SafeWebSettings.initWebviewAndSettings(safeWebView);
        WebSettings settings = this.b.getSettings();
        settings.setCacheMode(2);
        settings.setJavaScriptEnabled(true);
        settings.setDatabaseEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setAllowFileAccess(false);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setMixedContentMode(2);
        settings.setSupportZoom(true);
        this.b.setVerticalScrollBarEnabled(false);
        this.b.setHorizontalScrollBarEnabled(false);
        this.b.addJavascriptInterface(new e(), "agrattr");
        this.b.addJavascriptInterface(new d(), "hwop");
        this.b.addJavascriptInterface(new c(), "htmlLanguage");
        this.b.getSettings().setTextZoom(100);
        settings.setGeolocationEnabled(this.i && sl4.e());
        k();
    }

    public boolean m() {
        return this.l;
    }

    public final void n(String str) {
        this.b.loadUrl(str);
    }

    public void o(String str, String str2, String str3, String str4, String str5) {
        MapSafeWebView mapSafeWebView = this.b;
        if (mapSafeWebView == null) {
            return;
        }
        mapSafeWebView.loadDataWithBaseURL(str, str2, str3, str4, str5);
    }

    @Override
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        if (this.b == null || Float.compare(configuration.fontScale, this.j) == 0 || !this.k) {
            return;
        }
        this.j = configuration.fontScale;
        Optional.ofNullable(this.b.getUrl()).ifPresent(new Consumer() {
            @Override
            public final void accept(Object obj) {
                MapProgressWebView.this.n((String) obj);
            }
        });
    }

    @Override
    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return super.onKeyDown(i, keyEvent);
        }
        if (i != 4 || this.d || !safeWebView.canGoBack()) {
            return super.onKeyDown(i, keyEvent);
        }
        this.b.goBack();
        return true;
    }

    public void p(String str) {
        if (this.b == null) {
            return;
        }
        hm4.p("MapSafeWebView", "loadUrl");
        this.b.loadUrl(str);
    }

    public void q() {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            removeAllViews();
        } else {
            safeWebView.destroy();
            removeAllViews();
        }
    }

    public void r() {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return;
        }
        safeWebView.onPause();
    }

    public void s() {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return;
        }
        safeWebView.onResume();
    }

    public void setBottomRadius(int i) {
        MapSafeWebView mapSafeWebView = this.b;
        if (mapSafeWebView != null) {
            mapSafeWebView.setBottomRadius(i);
        }
    }

    public void setCanRefreshWeb(boolean z) {
        this.k = z;
    }

    public void setCheckShouldOverrideUrlLoadingListener(CheckShouldOverrideUrlLoadingListener checkShouldOverrideUrlLoadingListener) {
        this.g = checkShouldOverrideUrlLoadingListener;
    }

    public void setDefaultErrorPage(String str) {
        MapSafeWebView mapSafeWebView = this.b;
        if (mapSafeWebView == null) {
            return;
        }
        mapSafeWebView.setDefaultErrorPage(str);
    }

    public void setExit(boolean z) {
        this.d = z;
    }

    public void setGeolocationEnabled(boolean z) {
        this.i = z;
        SafeWebView safeWebView = this.b;
        if (safeWebView != null) {
            safeWebView.getSettings().setGeolocationEnabled(this.i && sl4.e());
        }
    }

    public void setLifeState(@WebViewLifeState int i) {
        if (i == 0) {
            s();
        } else if (i == 1) {
            r();
        } else if (i == 2) {
            q();
        }
    }

    public void setOpenBrowser(boolean z) {
        this.c = z;
    }

    public void setPageFinishListener(PageLoadFinishListener pageLoadFinishListener) {
        this.f = pageLoadFinishListener;
    }

    public void setRadius(int i) {
        MapSafeWebView mapSafeWebView = this.b;
        if (mapSafeWebView != null) {
            mapSafeWebView.setRadius(i);
        }
    }

    public void setShowProgressBar(boolean z) {
        this.l = z;
    }

    public void setTitleListener(WebPageTitleListener webPageTitleListener) {
        this.e = webPageTitleListener;
    }

    public void setTrustlist(String[] strArr) {
        MapSafeWebView mapSafeWebView = this.b;
        if (mapSafeWebView == null) {
            return;
        }
        mapSafeWebView.setWhitelistWithPath(strArr);
    }

    public void setWebColor(int i) {
        SafeWebView safeWebView = this.b;
        if (safeWebView == null) {
            return;
        }
        safeWebView.setBackgroundColor(i);
    }

    public void t() {
        if (this.b != null && WebViewFeature.isFeatureSupported("FORCE_DARK")) {
            if (o9a.f()) {
                WebSettingsCompat.setForceDark(this.b.getSettings(), 2);
            } else {
                WebSettingsCompat.setForceDark(this.b.getSettings(), 0);
            }
        }
    }

    public MapProgressWebView(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public MapProgressWebView(Context context, @Nullable AttributeSet attributeSet, int i) {
        this(context, attributeSet, i, 0);
    }

    public MapProgressWebView(Context context, AttributeSet attributeSet, int i, int i2) {
        super(context, attributeSet, i, i2);
        this.h = false;
        this.i = true;
        this.l = true;
        j(context, attributeSet, i);
    }
}