NClientV2.apk(点击下载) / CustomWebView.java


package com.dar.nclientv2.components.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.media.c;
import android.util.AttributeSet;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.dar.nclientv2.settings.Global;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CustomWebView extends WebView {
    private final MyJavaScriptInterface javaScriptInterface = new MyJavaScriptInterface();

    public interface HtmlFetcher {
        void fetchUrl(String str, String str2);
    }

    public static class MyJavaScriptInterface {

        /* renamed from: a  reason: collision with root package name */
        public List<HtmlFetcher> f2963a = new ArrayList(5);

        /* JADX WARN: Type inference failed for: r0v0, types: [java.util.List<com.dar.nclientv2.components.views.CustomWebView$HtmlFetcher>, java.util.ArrayList] */
        /* JADX WARNING: Unknown variable types count: 1 */
        public void addFetcher(@NonNull HtmlFetcher htmlFetcher) {
            this.f2963a.add(htmlFetcher);
        }

        /* JADX WARN: Type inference failed for: r0v0, types: [java.util.List<com.dar.nclientv2.components.views.CustomWebView$HtmlFetcher>, java.util.ArrayList] */
        /* JADX WARNING: Unknown variable types count: 1 */
        public void removeFetcher(@NonNull HtmlFetcher htmlFetcher) {
            this.f2963a.remove(htmlFetcher);
        }

        /* JADX WARN: Type inference failed for: r0v0, types: [java.util.List<com.dar.nclientv2.components.views.CustomWebView$HtmlFetcher>, java.util.ArrayList] */
        /* JADX WARNING: Unknown variable types count: 1 */
        @JavascriptInterface
        public void showHTML(String str, String str2) {
            Iterator it = this.f2963a.iterator();
            while (it.hasNext()) {
                ((HtmlFetcher) it.next()).fetchUrl(str, str2);
            }
        }
    }

    public CustomWebView(Context context) {
        super(context.getApplicationContext());
        context.getApplicationContext();
        initialize();
    }

    @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
    private void initialize() {
        getSettings().setJavaScriptEnabled(true);
        getSettings().setUserAgentString(Global.getUserAgent());
        addJavascriptInterface(this.javaScriptInterface, "HtmlViewer");
        setWebViewClient(new WebViewClient() {
            /* class com.dar.nclientv2.components.views.CustomWebView.AnonymousClass1 */

            public void onPageFinished(WebView webView, String str) {
                CustomWebView.this.loadUrl(c.a("javascript:window.HtmlViewer.showHTML('", str, "','<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');"));
            }

            public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
                super.onPageStarted(webView, str, bitmap);
            }
        });
        addFetcher(a.f2971a);
    }

    /* access modifiers changed from: private */
    public static /* synthetic */ void lambda$initialize$0(String str, String str2) {
    }

    public void addFetcher(@Nullable HtmlFetcher htmlFetcher) {
        if (htmlFetcher != null) {
            this.javaScriptInterface.addFetcher(htmlFetcher);
        }
    }

    public void loadUrl(String str) {
        super.loadUrl(str);
    }

    public void removeFetcher(@Nullable HtmlFetcher htmlFetcher) {
        if (htmlFetcher != null) {
            this.javaScriptInterface.removeFetcher(htmlFetcher);
        }
    }

    public CustomWebView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        context.getApplicationContext();
        initialize();
    }

    public CustomWebView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        context.getApplicationContext();
        initialize();
    }
}