Virtual Trading v2.0.95版本的 MD5 值为:ef0f95d706f7364286da0edbbd29a27d

以下内容为反编译后的 CustomWebView.java 源代码,内容仅作参考


package com.sunny.CustomWebView;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.print.PageRange;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintJob;
import android.print.PrintManager;
import android.util.Base64;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.GeolocationPermissions;
import android.webkit.HttpAuthHandler;
import android.webkit.JavascriptInterface;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.PermissionRequest;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebBackForwardList;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import androidx.core.net.MailTo;
import com.google.android.gms.common.internal.ImagesContract;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.HVArrangement;
import com.google.appinventor.components.runtime.TinyDB;
import com.google.appinventor.components.runtime.util.JsonUtil;
import com.google.appinventor.components.runtime.util.NanoHTTPD;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@UsesPermissions(permissionNames = "android.permission.WRITE_EXTERNAL_STORAGE,android.permission.ACCESS_DOWNLOAD_MANAGER,android.permission.ACCESS_FINE_LOCATION,android.permission.RECORD_AUDIO, android.permission.MODIFY_AUDIO_SETTINGS, android.permission.CAMERA,android.permission.VIBRATE,android.webkit.resource.VIDEO_CAPTURE,android.webkit.resource.AUDIO_CAPTURE,android.launcher.permission.INSTALL_SHORTCUT")
@DesignerComponent(androidMinSdk = 21, category = ComponentCategory.EXTENSION, description = "An extended form of Web Viewer <br> Developed by Sunny Gupta", helpUrl = "https://github.com/vknow360/CustomWebView", iconName = "https://res.cloudinary.com/andromedaviewflyvipul/image/upload/c_scale,h_20,w_20/v1571472765/ktvu4bapylsvnykoyhdm.png", nonVisible = true, version = 11, versionName = "11")
@SimpleObject(external = true)
public final class CustomWebView extends AndroidNonvisibleComponent {
    public static List<String> AD_HOSTS = new ArrayList();
    private String MOBILE_USER_AGENT;
    public String UserAgent;
    public Activity activity;
    public boolean blockAds;
    public Context context;
    public CookieManager cookieManager;
    public boolean deepLinks;
    public boolean desktopMode;
    public float deviceDensity;
    public boolean displayZoom;
    public Message dontSend;
    public boolean followLinks;
    public HttpAuthHandler httpAuthHandler;
    public int iD;
    public boolean isLoading;
    public String jobName;
    public JsResult jsAlert;
    public JsPromptResult jsPromptResult;
    public JsResult jsResult;
    private ValueCallback<Uri[]> mFilePathCallback;
    public PermissionRequest permissionRequest;
    public PrintJob printJob;
    public boolean prompt;
    public Message reSend;
    public Message resultObj;
    public SslErrorHandler sslHandler;
    public GeolocationPermissions.Callback theCallback;
    public String theOrigin;
    public WebView webView;
    public HashMap<Integer, WebView> wv;
    public WebViewInterface wvInterface;
    public boolean zoomEnabled;
    public int zoomPercent;

    class AnonymousClass10 implements Runnable {
        final String val$permissions;

        AnonymousClass10(String str) {
            this.val$permissions = str;
        }

        @Override
        public void run() {
            if (this.val$permissions.isEmpty()) {
                CustomWebView.this.permissionRequest.deny();
            } else {
                CustomWebView.this.permissionRequest.grant(CustomWebView.this.permissionRequest.getResources());
            }
            CustomWebView.this.permissionRequest = null;
        }
    }

    public static class AdBlocker {
        private boolean isAdHost(String str) {
            int indexOf;
            int i;
            if (!str.isEmpty() && (indexOf = str.indexOf(".")) >= 0) {
                return CustomWebView.AD_HOSTS.contains(str) || ((i = indexOf + 1) < str.length() && isAdHost(str.substring(i)));
            }
            return false;
        }

        public WebResourceResponse createEmptyResource() {
            return new WebResourceResponse(NanoHTTPD.MIME_PLAINTEXT, "utf-8", null);
        }

        public boolean isAd(String str) {
            String host;
            if (str != null) {
                try {
                    if (new URL(str).getHost() != null) {
                        host = new URL(str).getHost();
                        return isAdHost(host);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }
            }
            host = "";
            return isAdHost(host);
        }
    }

    public class ChromeClient extends WebChromeClient {
        private final int FULL_SCREEN_SETTING = 3846;
        private View mCustomView;
        private WebChromeClient.CustomViewCallback mCustomViewCallback;
        private int mOriginalOrientation;
        private int mOriginalSystemUiVisibility;

        public ChromeClient() {
        }

        @Override
        public void onCloseWindow(WebView webView) {
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnCloseWindowRequest(customWebView.getIndex(webView));
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            CustomWebView.this.OnConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.lineNumber(), consoleMessage.messageLevel().toString());
            return true;
        }

        @Override
        public boolean onCreateWindow(WebView webView, boolean z, boolean z2, Message message) {
            if (CustomWebView.this.SupportMultipleWindows()) {
                CustomWebView.this.resultObj = message;
                CustomWebView customWebView = CustomWebView.this;
                customWebView.OnNewWindowRequest(customWebView.getIndex(webView), z, z2);
            }
            return CustomWebView.this.SupportMultipleWindows();
        }

        @Override
        public void onGeolocationPermissionsShowPrompt(String str, GeolocationPermissions.Callback callback) {
            if (!CustomWebView.this.prompt) {
                callback.invoke(str, true, true);
                return;
            }
            CustomWebView.this.theCallback = callback;
            CustomWebView.this.theOrigin = str;
            CustomWebView.this.OnGeolocationRequested(str);
        }

        @Override
        public void onHideCustomView() {
            CustomWebView.this.OnHideCustomView();
            ((FrameLayout) CustomWebView.this.activity.getWindow().getDecorView()).removeView(this.mCustomView);
            this.mCustomView = null;
            CustomWebView.this.activity.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
            CustomWebView.this.activity.setRequestedOrientation(this.mOriginalOrientation);
            this.mCustomViewCallback.onCustomViewHidden();
            this.mCustomViewCallback = null;
            CustomWebView.this.activity.setRequestedOrientation(2);
        }

        @Override
        public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnJsAlert(customWebView.getIndex(webView), str, str2);
            CustomWebView.this.jsAlert = jsResult;
            return CustomWebView.this.EnableJS();
        }

        @Override
        public boolean onJsConfirm(WebView webView, String str, String str2, JsResult jsResult) {
            CustomWebView.this.jsResult = jsResult;
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnJsConfirm(customWebView.getIndex(webView), str, str2);
            return CustomWebView.this.EnableJS();
        }

        @Override
        public boolean onJsPrompt(WebView webView, String str, String str2, String str3, JsPromptResult jsPromptResult) {
            CustomWebView.this.jsPromptResult = jsPromptResult;
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnJsPrompt(customWebView.getIndex(webView), str, str2, str3);
            return CustomWebView.this.EnableJS();
        }

        @Override
        public void onPermissionRequest(PermissionRequest permissionRequest) {
            if (!CustomWebView.this.prompt) {
                permissionRequest.grant(permissionRequest.getResources());
                return;
            }
            CustomWebView.this.permissionRequest = permissionRequest;
            CustomWebView.this.OnPermissionRequest(Arrays.asList(permissionRequest.getResources()));
        }

        @Override
        public void onProgressChanged(WebView webView, int i) {
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnProgressChanged(customWebView.getIndex(webView), i);
        }

        @Override
        public void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
            CustomWebView.this.OnShowCustomView();
            if (this.mCustomView != null) {
                onHideCustomView();
                return;
            }
            this.mCustomView = view;
            this.mOriginalSystemUiVisibility = CustomWebView.this.activity.getWindow().getDecorView().getSystemUiVisibility();
            this.mOriginalOrientation = CustomWebView.this.activity.getRequestedOrientation();
            this.mCustomViewCallback = customViewCallback;
            ((FrameLayout) CustomWebView.this.activity.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
            CustomWebView.this.activity.getWindow().getDecorView().setSystemUiVisibility(3846);
            CustomWebView.this.activity.setRequestedOrientation(2);
            this.mCustomView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
                @Override
                public void onSystemUiVisibilityChange(int i) {
                    ChromeClient.this.updateControls();
                }
            });
        }

        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
            CustomWebView.this.mFilePathCallback = valueCallback;
            CustomWebView customWebView = CustomWebView.this;
            customWebView.FileUploadNeeded(customWebView.getIndex(webView), fileChooserParams.getAcceptTypes()[0], fileChooserParams.isCaptureEnabled());
            return CustomWebView.this.FileAccess();
        }

        void updateControls() {
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this.mCustomView.getLayoutParams();
            layoutParams.bottomMargin = 0;
            layoutParams.topMargin = 0;
            layoutParams.leftMargin = 0;
            layoutParams.rightMargin = 0;
            layoutParams.height = -1;
            layoutParams.width = -1;
            this.mCustomView.setLayoutParams(layoutParams);
            CustomWebView.this.activity.getWindow().getDecorView().setSystemUiVisibility(3846);
        }
    }

    public class PrintDocumentAdapterWrapper extends PrintDocumentAdapter {
        private final PrintDocumentAdapter delegate;

        public PrintDocumentAdapterWrapper(PrintDocumentAdapter printDocumentAdapter) {
            this.delegate = printDocumentAdapter;
        }

        @Override
        public void onFinish() {
            this.delegate.onFinish();
            CustomWebView customWebView = CustomWebView.this;
            customWebView.GotPrintResult(customWebView.jobName, CustomWebView.this.printJob.isCompleted(), CustomWebView.this.printJob.isFailed(), CustomWebView.this.printJob.isBlocked());
        }

        @Override
        public void onLayout(PrintAttributes printAttributes, PrintAttributes printAttributes2, CancellationSignal cancellationSignal, PrintDocumentAdapter.LayoutResultCallback layoutResultCallback, Bundle bundle) {
            this.delegate.onLayout(printAttributes, printAttributes2, cancellationSignal, layoutResultCallback, bundle);
        }

        @Override
        public void onWrite(PageRange[] pageRangeArr, ParcelFileDescriptor parcelFileDescriptor, CancellationSignal cancellationSignal, PrintDocumentAdapter.WriteResultCallback writeResultCallback) {
            this.delegate.onWrite(pageRangeArr, parcelFileDescriptor, cancellationSignal, writeResultCallback);
        }
    }

    public class WebClient extends WebViewClient {
        public HashMap<String, Boolean> loadedUrls = new HashMap<>();

        public WebClient() {
        }

        @Override
        public void onFormResubmission(WebView webView, Message message, Message message2) {
            CustomWebView.this.dontSend = message;
            CustomWebView.this.reSend = message2;
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnFormResubmission(customWebView.getIndex(webView));
        }

        @Override
        public void onPageFinished(WebView webView, String str) {
            if (CustomWebView.this.wv.get(Integer.valueOf(CustomWebView.this.CurrentId())) == webView && CustomWebView.this.isLoading) {
                CustomWebView.this.isLoading = false;
                CustomWebView customWebView = CustomWebView.this;
                customWebView.PageLoaded(customWebView.getIndex(webView));
            }
        }

        @Override
        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            if (CustomWebView.this.isLoading) {
                return;
            }
            CustomWebView customWebView = CustomWebView.this;
            customWebView.PageStarted(customWebView.getIndex(webView), str);
            CustomWebView.this.isLoading = true;
        }

        @Override
        public void onReceivedError(WebView webView, int i, String str, String str2) {
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnErrorReceived(customWebView.getIndex(webView), str, i, str2);
        }

        @Override
        public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnErrorReceived(customWebView.getIndex(webView), webResourceError.getDescription().toString(), webResourceError.getErrorCode(), webResourceRequest.getUrl().toString());
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView webView, HttpAuthHandler httpAuthHandler, String str, String str2) {
            CustomWebView.this.httpAuthHandler = httpAuthHandler;
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnReceivedHttpAuthRequest(customWebView.getIndex(webView), str, str2);
        }

        @Override
        public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
            CustomWebView customWebView = CustomWebView.this;
            customWebView.OnErrorReceived(customWebView.getIndex(webView), webResourceResponse.getReasonPhrase(), webResourceResponse.getStatusCode(), webResourceRequest.getUrl().toString());
        }

        @Override
        public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
            CustomWebView.this.sslHandler = sslErrorHandler;
            CustomWebView.this.OnReceivedSslError(sslError.getPrimaryError());
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
            boolean booleanValue;
            if (!CustomWebView.this.blockAds) {
                return null;
            }
            AdBlocker adBlocker = new AdBlocker();
            String uri = webResourceRequest.getUrl().toString();
            if (this.loadedUrls.containsKey(uri)) {
                booleanValue = this.loadedUrls.get(uri).booleanValue();
            } else {
                booleanValue = adBlocker.isAd(uri);
                this.loadedUrls.put(uri, Boolean.valueOf(booleanValue));
            }
            if (booleanValue) {
                return adBlocker.createEmptyResource();
            }
            return null;
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView webView, String str) {
            boolean booleanValue;
            if (!CustomWebView.this.blockAds) {
                return null;
            }
            AdBlocker adBlocker = new AdBlocker();
            if (this.loadedUrls.containsKey(str)) {
                booleanValue = this.loadedUrls.get(str).booleanValue();
            } else {
                booleanValue = adBlocker.isAd(str);
                this.loadedUrls.put(str, Boolean.valueOf(booleanValue));
            }
            if (booleanValue) {
                return adBlocker.createEmptyResource();
            }
            return null;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
            String uri = webResourceRequest.getUrl().toString();
            if (uri.startsWith("http")) {
                return !CustomWebView.this.followLinks;
            }
            if (CustomWebView.this.deepLinks) {
                return CustomWebView.this.DeepLinkParser(uri);
            }
            return false;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            if (str.startsWith("http")) {
                return !CustomWebView.this.followLinks;
            }
            if (CustomWebView.this.deepLinks) {
                return CustomWebView.this.DeepLinkParser(str);
            }
            return false;
        }
    }

    public class WebViewInterface {
        String webViewString = "";

        WebViewInterface() {
        }

        @JavascriptInterface
        public String getWebViewString() {
            return this.webViewString;
        }

        @JavascriptInterface
        public void setWebViewString(final String str) {
            this.webViewString = str;
            CustomWebView.this.activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    CustomWebView.this.WebViewStringChanged(str);
                }
            });
        }

        public void setWebViewStringFromBlocks(String str) {
            this.webViewString = str;
        }
    }

    public CustomWebView(ComponentContainer componentContainer) {
        super(componentContainer.$form());
        this.followLinks = true;
        this.prompt = true;
        this.UserAgent = "";
        this.MOBILE_USER_AGENT = "";
        this.deepLinks = false;
        this.jobName = "";
        this.isLoading = false;
        this.wv = new HashMap<>();
        this.blockAds = false;
        this.iD = 0;
        this.desktopMode = false;
        this.zoomPercent = 100;
        this.zoomEnabled = true;
        this.displayZoom = true;
        Activity $context = componentContainer.$context();
        this.activity = $context;
        this.context = $context;
        this.wvInterface = new WebViewInterface();
        this.cookieManager = CookieManager.getInstance();
        this.deviceDensity = componentContainer.$form().deviceDensity();
        WebView webView = new WebView(this.context);
        this.webView = webView;
        resetWebView(webView);
    }

    @SimpleProperty(description = "Sets the ad hosts which will be blocked")
    @DesignerProperty(defaultValue = "", editorType = "string")
    public void AdHosts(String str) {
        AD_HOSTS.addAll(Arrays.asList(str.split(",")));
    }

    @SimpleEvent(description = "Event raised after 'SaveArchive' method.If 'success' is true then returns file path else empty string.")
    public void AfterArchiveSaved(boolean z, String str) {
        EventDispatcher.dispatchEvent(this, "AfterArchiveSaved", Boolean.valueOf(z), str);
    }

    @SimpleEvent(description = "Event raised after evaluating Js and returns result.")
    public void AfterJavaScriptEvaluated(String str) {
        EventDispatcher.dispatchEvent(this, "AfterJavaScriptEvaluated", str);
    }

    @SimpleFunction
    public void AllowGeolocationAccess(boolean z, boolean z2) {
        GeolocationPermissions.Callback callback = this.theCallback;
        if (callback != null) {
            callback.invoke(this.theOrigin, z, z2);
            this.theCallback = null;
            this.theOrigin = "";
        }
    }

    @SimpleProperty(description = "Sets whether the WebView should load image resources")
    public void AutoLoadImages(boolean z) {
        this.webView.getSettings().setBlockNetworkImage(!z);
        this.webView.getSettings().setLoadsImagesAutomatically(z);
    }

    @SimpleProperty(description = "Returnss whether the WebView should load image resources")
    public boolean AutoLoadImages() {
        return this.webView.getSettings().getLoadsImagesAutomatically();
    }

    @SimpleProperty(description = "Sets whether the WebView requires a user gesture to play media")
    public void AutoplayMedia(boolean z) {
        this.webView.getSettings().setMediaPlaybackRequiresUserGesture(z);
    }

    @SimpleProperty(description = "Returns whether the WebView requires a user gesture to play media")
    public boolean AutoplayMedia() {
        return this.webView.getSettings().getMediaPlaybackRequiresUserGesture();
    }

    @SimpleProperty(description = "Sets background color of webview")
    public void BackgroundColor(int i) {
        this.webView.setBackgroundColor(i);
    }

    @SimpleProperty(description = "Sets whether to block ads or not")
    @DesignerProperty(defaultValue = "False", editorType = "boolean")
    public void BlockAds(boolean z) {
        this.blockAds = z;
    }

    @SimpleProperty(description = "Sets whether the WebView should not load resources from the network.Use this to save data.")
    public void BlockNetworkLoads(boolean z) {
        this.webView.getSettings().setBlockNetworkLoads(z);
    }

    @SimpleProperty(description = "Returns whether the WebView should not load resources from the network")
    public boolean BlockNetworkLoads() {
        return this.webView.getSettings().getBlockNetworkLoads();
    }

    @SimpleProperty(description = "Gets cache mode of active webview")
    public int CacheMode() {
        return this.webView.getSettings().getCacheMode();
    }

    @SimpleProperty(description = "Sets cache mode for active webview")
    public void CacheMode(int i) {
        this.webView.getSettings().setCacheMode(i);
    }

    @SimpleFunction(description = "Gets whether this WebView has a back history item")
    public boolean CanGoBack() {
        return this.webView.canGoBack();
    }

    @SimpleFunction(description = "Gets whether the page can go back or forward the given number of steps.")
    public boolean CanGoBackOrForward(int i) {
        return this.webView.canGoBackOrForward(i);
    }

    @SimpleFunction(description = "Gets whether this WebView has a forward history item.")
    public boolean CanGoForward() {
        return this.webView.canGoForward();
    }

    public void CancelJsRequests() {
        JsResult jsResult = this.jsAlert;
        if (jsResult != null) {
            jsResult.cancel();
            this.jsAlert = null;
            return;
        }
        JsResult jsResult2 = this.jsResult;
        if (jsResult2 != null) {
            jsResult2.cancel();
            this.jsResult = null;
            return;
        }
        JsPromptResult jsPromptResult = this.jsPromptResult;
        if (jsPromptResult != null) {
            jsPromptResult.cancel();
            this.jsPromptResult = null;
            return;
        }
        ValueCallback<Uri[]> valueCallback = this.mFilePathCallback;
        if (valueCallback != null) {
            valueCallback.onReceiveValue(null);
            this.mFilePathCallback = null;
        }
    }

    @SimpleFunction(description = "Cancels current print job. You can request cancellation of a queued, started, blocked, or failed print job.")
    public void CancelPrinting() throws Exception {
        this.printJob.cancel();
    }

    @SimpleFunction(description = "Clears the resource cache.")
    public void ClearCache() {
        this.webView.clearCache(true);
    }

    @SimpleFunction(description = "Removes all cookies and raises 'CookiesRemoved' event")
    public void ClearCookies() {
        this.cookieManager.removeAllCookies(new ValueCallback<Boolean>() {
            @Override
            public void onReceiveValue(Boolean bool) {
                CustomWebView.this.CookiesRemoved(bool.booleanValue());
            }
        });
        this.cookieManager.flush();
    }

    @SimpleFunction(description = "Tells this WebView to clear its internal back/forward list.")
    public void ClearInternalHistory() {
        this.webView.clearHistory();
    }

    @SimpleFunction(description = "Clear all location preferences.")
    public void ClearLocation() {
        GeolocationPermissions.getInstance().clearAll();
    }

    @SimpleFunction(description = "Clears the highlighting surrounding text matches.")
    public void ClearMatches() {
        this.webView.clearMatches();
    }

    @SimpleFunction(description = "Whether to proceed JavaScript originated request")
    public void ConfirmJs(boolean z) {
        JsResult jsResult = this.jsResult;
        if (jsResult != null) {
            if (z) {
                jsResult.confirm();
            } else {
                jsResult.cancel();
            }
            this.jsResult = null;
        }
    }

    @SimpleFunction(description = "Gets height of HTML content")
    public int ContentHeight() {
        return d2p(this.webView.getContentHeight());
    }

    @SimpleFunction(description = "Inputs a confirmation response to Js")
    public void ContinueJs(String str) {
        JsPromptResult jsPromptResult = this.jsPromptResult;
        if (jsPromptResult != null) {
            jsPromptResult.confirm(str);
            this.jsPromptResult = null;
        }
    }

    @SimpleEvent(description = "Event raised after 'ClearCokies' method with result")
    public void CookiesRemoved(boolean z) {
        EventDispatcher.dispatchEvent(this, "CookiesRemoved", Boolean.valueOf(z));
    }

    @SimpleFunction(description = "Creates a shortcut of given website on home screen")
    public void CreateShortcut(String str, String str2, String str3) {
        try {
            Bitmap decodeFile = BitmapFactory.decodeFile(str2);
            if (decodeFile != null) {
                String string = this.context.getSharedPreferences(TinyDB.DEFAULT_NAMESPACE, 0).getString("ssn", "");
                String packageName = this.context.getPackageName();
                Intent intent = new Intent();
                ResolveInfo resolveActivity = this.context.getPackageManager().resolveActivity(this.context.getPackageManager().getLaunchIntentForPackage(packageName), 0);
                resolveActivity.getClass();
                intent.setClassName(this.context, resolveActivity.activityInfo.name.replaceAll("Screen1", string.length() == 0 ? "Screen1" : JsonUtil.getObjectFromJson(string, true).toString()));
                ArrayList arrayList = new ArrayList();
                arrayList.add(str);
                arrayList.add(Component.CHIP_TYPE_FILTER);
                intent.putExtra("APP_INVENTOR_START", JsonUtil.getJsonRepresentation(arrayList));
                if (Build.VERSION.SDK_INT >= 26) {
                    ShortcutManager shortcutManager = (ShortcutManager) this.context.getSystemService("shortcut");
                    if (shortcutManager.isRequestPinShortcutSupported()) {
                        ShortcutInfo build = new ShortcutInfo.Builder(this.context, str3).setShortLabel(str3).setIcon(Icon.createWithBitmap(decodeFile)).setIntent(intent).build();
                        shortcutManager.requestPinShortcut(build, PendingIntent.getBroadcast(this.context, 0, shortcutManager.createShortcutResultIntent(build), 0).getIntentSender());
                        return;
                    }
                    return;
                }
                Intent intent2 = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
                intent2.putExtra("android.intent.extra.shortcut.INTENT", intent);
                intent2.putExtra("android.intent.extra.shortcut.NAME", str3);
                intent2.putExtra("android.intent.extra.shortcut.ICON", decodeFile);
                intent2.putExtra("duplicate", false);
                this.context.sendBroadcast(intent2);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @SimpleFunction(description = "Creates the webview in given arrangement with id")
    public void CreateWebView(HVArrangement hVArrangement, int i) {
        if (this.wv.containsKey(Integer.valueOf(i)) && hVArrangement == null) {
            return;
        }
        View view = hVArrangement.getView();
        if (this.wv.containsKey(Integer.valueOf(i))) {
            return;
        }
        WebView webView = new WebView(this.context);
        resetWebView(webView);
        ((FrameLayout) view).addView(webView, new FrameLayout.LayoutParams(-1, -1));
        this.wv.put(Integer.valueOf(i), webView);
    }

    @SimpleFunction(description = "Returns current id")
    public int CurrentId() {
        return this.iD;
    }

    @SimpleProperty(category = PropertyCategory.BEHAVIOR, description = "Title of the page currently viewed")
    public String CurrentPageTitle() {
        return this.webView.getTitle() == null ? "" : this.webView.getTitle();
    }

    @SimpleProperty(description = "URL of the page currently viewed")
    public String CurrentUrl() {
        return this.webView.getUrl() == null ? "" : this.webView.getUrl();
    }

    public boolean DeepLinkParser(String str) {
        PackageManager packageManager = this.context.getPackageManager();
        if (str.startsWith("tel:")) {
            this.activity.startActivity(new Intent("android.intent.action.DIAL", Uri.parse(str)));
            return true;
        }
        if (str.startsWith(MailTo.MAILTO_SCHEME) || str.startsWith("sms:")) {
            this.activity.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
            return true;
        }
        if (str.startsWith("whatsapp:")) {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(str));
            intent.setPackage("com.whatsapp");
            this.activity.startActivity(intent);
            return true;
        }
        if (str.startsWith("geo:")) {
            Intent intent2 = new Intent("android.intent.action.VIEW", Uri.parse(str));
            intent2.setPackage("com.google.android.apps.maps");
            if (intent2.resolveActivity(packageManager) == null) {
                return false;
            }
            this.activity.startActivity(intent2);
            return true;
        }
        if (str.startsWith("intent:")) {
            try {
                Intent parseUri = Intent.parseUri(str, 1);
                if (parseUri.resolveActivity(packageManager) != null) {
                    this.activity.startActivity(parseUri);
                    return true;
                }
                String stringExtra = parseUri.getStringExtra("browser_fallback_url");
                if (stringExtra != null) {
                    this.webView.loadUrl(stringExtra);
                }
                Intent data = new Intent("android.intent.action.VIEW").setData(Uri.parse("market://details?id=" + parseUri.getPackage()));
                if (data.resolveActivity(packageManager) == null) {
                    return false;
                }
                this.activity.startActivity(data);
                return true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    @SimpleProperty(description = "Sets whether to enable deep links or not i.e. tel: , whatsapp: , sms: , etc.")
    @DesignerProperty(defaultValue = "False", editorType = "boolean")
    public void DeepLinks(boolean z) {
        this.deepLinks = z;
    }

    @SimpleProperty(description = "Returns whether deep links are enabled or not")
    public boolean DeepLinks() {
        return this.deepLinks;
    }

    @SimpleProperty(description = "Sets whether to load content in desktop mode")
    public void DesktopMode(boolean z) {
        String str = this.UserAgent;
        this.UserAgent = z ? str.replace("Android", "diordnA").replace("Mobile", "eliboM") : str.replace("diordnA", "Android").replace("eliboM", "Mobile");
        this.webView.getSettings().setUserAgentString(this.UserAgent);
        this.desktopMode = z;
    }

    @SimpleProperty(description = "Returns whether to load content in desktop mode")
    public boolean DesktopMode() {
        return this.desktopMode;
    }

    @SimpleFunction(description = "Dismiss previously requested Js alert")
    public void DismissJsAlert() {
        JsResult jsResult = this.jsAlert;
        if (jsResult != null) {
            jsResult.cancel();
            this.jsAlert = null;
        }
    }

    @SimpleProperty(description = "Sets whether the WebView should display on-screen zoom controls")
    @DesignerProperty(defaultValue = "True", editorType = "boolean")
    public void DisplayZoom(boolean z) {
        this.displayZoom = z;
    }

    @SimpleProperty(description = "Gets whether the WebView should display on-screen zoom controls")
    public boolean DisplayZoom() {
        return this.displayZoom;
    }

    @SimpleProperty(description = "Tells the WebView to enable JavaScript execution.")
    public void EnableJS(boolean z) {
        this.webView.getSettings().setJavaScriptEnabled(z);
    }

    @SimpleProperty(description = "Returns whether webview supports JavaScript execution")
    public boolean EnableJS() {
        return this.webView.getSettings().getJavaScriptEnabled();
    }

    @SimpleFunction(description = "Asynchronously evaluates JavaScript in the context of the currently displayed page.")
    public void EvaluateJavaScript(String str) {
        this.webView.evaluateJavascript(str, new ValueCallback<String>() {
            @Override
            public void onReceiveValue(String str2) {
                CustomWebView.this.AfterJavaScriptEvaluated(str2);
            }
        });
    }

    @SimpleProperty(description = "Sets whether webview can access local files.Use this to enable file uploading and loading files using HTML")
    public void FileAccess(boolean z) {
        this.webView.getSettings().setAllowFileAccess(z);
        this.webView.getSettings().setAllowFileAccessFromFileURLs(z);
        this.webView.getSettings().setAllowUniversalAccessFromFileURLs(z);
        this.webView.getSettings().setAllowContentAccess(z);
    }

    @SimpleProperty(description = "Returns whether webview can access local files")
    public boolean FileAccess() {
        return this.webView.getSettings().getAllowFileAccess();
    }

    @SimpleEvent(description = "Event raised when file uploading is needed")
    public void FileUploadNeeded(int i, String str, boolean z) {
        EventDispatcher.dispatchEvent(this, "FileUploadNeeded", Integer.valueOf(i), str, Boolean.valueOf(z));
    }

    @SimpleFunction(description = "Finds all instances of find on the page and highlights them, asynchronously. Successive calls to this will cancel any pending searches.")
    public void Find(String str) {
        this.webView.findAllAsync(str);
    }

    @SimpleFunction(description = "Highlights and scrolls to the next match if 'forward' is true else scrolls to previous match.")
    public void FindNext(boolean z) {
        this.webView.findNext(z);
    }

    @SimpleEvent(description = "Event raised after 'Find' method with int 'activeMatchOrdinal','numberOfMatches' and 'isDoneCounting'")
    public void FindResultReceived(int i, int i2, int i3, boolean z) {
        EventDispatcher.dispatchEvent(this, "FindResultReceived", Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), Boolean.valueOf(z));
    }

    @SimpleProperty(description = "Sets whether to follow links or not")
    @DesignerProperty(defaultValue = "True", editorType = "boolean")
    public void FollowLinks(boolean z) {
        this.followLinks = z;
    }

    @SimpleProperty(description = "Determines whether to follow links when they are tapped in the WebViewer.If you follow links, you can use GoBack and GoForward to navigate the browser history")
    public boolean FollowLinks() {
        return this.followLinks;
    }

    @SimpleProperty(description = "Returns the font size of text")
    public int FontSize() {
        return this.webView.getSettings().getDefaultFontSize();
    }

    @SimpleProperty(description = "Sets the default font size of text. The default is 16.")
    public void FontSize(int i) {
        this.webView.getSettings().setDefaultFontSize(i);
    }

    @SimpleFunction(description = "Get cookies for specific url")
    public String GetCookies(String str) {
        String cookie = CookieManager.getInstance().getCookie(str);
        return cookie != null ? cookie : "";
    }

    @SimpleFunction(description = "Returns a list of used ids")
    public List<Integer> GetIds() {
        return new ArrayList(this.wv.keySet());
    }

    @SimpleFunction(description = "Get internal history of given webview.")
    public List<String> GetInternalHistory(int i) {
        ArrayList arrayList = new ArrayList();
        if (this.wv.containsKey(Integer.valueOf(i))) {
            WebBackForwardList copyBackForwardList = this.wv.get(Integer.valueOf(i)).copyBackForwardList();
            for (int i2 = 0; i2 < copyBackForwardList.getSize(); i2++) {
                arrayList.add(copyBackForwardList.getItemAtIndex(i2).getUrl());
            }
        }
        return arrayList;
    }

    @SimpleFunction(description = "Gets the progress for the given webview")
    public int GetProgress(int i) {
        return this.wv.get(Integer.valueOf(i)).getProgress();
    }

    @SimpleFunction(description = "Return the scrolled left position of the webview")
    public int GetScrollX() {
        return d2p(this.webView.getScrollX());
    }

    @SimpleFunction(description = "Return the scrolled top position of the webview")
    public int GetScrollY() {
        return d2p(this.webView.getScrollY());
    }

    @SimpleFunction(description = "Gets the SSL certificate for the main top-level page and raises 'GotCertificate' event")
    public void GetSslCertificate() {
        SslCertificate certificate = this.webView.getCertificate();
        if (certificate != null) {
            GotCertificate(true, certificate.getIssuedBy().getDName(), certificate.getIssuedTo().getDName(), certificate.getValidNotAfterDate().toString());
        } else {
            GotCertificate(false, "", "", "");
        }
    }

    @SimpleFunction(description = "Returns webview object from id")
    public Object GetWebView(int i) {
        if (this.wv.containsKey(Integer.valueOf(i))) {
            return this.wv.get(Integer.valueOf(i));
        }
        return null;
    }

    @SimpleFunction(description = "Goes back in the history of this WebView.")
    public void GoBack() {
        if (CanGoBack()) {
            this.webView.goBack();
        }
    }

    @SimpleFunction(description = "Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.")
    public void GoBackOrForward(int i) {
        if (CanGoBackOrForward(i)) {
            this.webView.goBackOrForward(i);
        }
    }

    @SimpleFunction(description = "Goes forward in the history of this WebView.")
    public void GoForward() {
        if (CanGoForward()) {
            this.webView.goForward();
        }
    }

    @SimpleFunction(description = "Loads the given URL.")
    public void GoToUrl(String str) {
        CancelJsRequests();
        this.webView.loadUrl(str);
    }

    @SimpleEvent(description = "Event raised after getting SSL certificate of current displayed url/website with boolean 'isSecure' and Strings 'issuedBy','issuedTo' and 'validTill'.If 'isSecure' is false and other values are empty then assume that website is not secure")
    public void GotCertificate(boolean z, String str, String str2, String str3) {
        EventDispatcher.dispatchEvent(this, "GotCertificate", Boolean.valueOf(z), str, str2, str3);
    }

    @SimpleEvent(description = "Event raised after getting previus print's result.")
    public void GotPrintResult(String str, boolean z, boolean z2, boolean z3) {
        EventDispatcher.dispatchEvent(this, "GotPrintResult", str, Boolean.valueOf(z), Boolean.valueOf(z2), Boolean.valueOf(z3));
    }

    @SimpleFunction(description = "Grants given permissions to webview.Use empty list to deny the request.")
    public void GrantPermission(String str) {
        if (this.permissionRequest != null) {
            if (str.isEmpty()) {
                this.permissionRequest.deny();
            } else {
                PermissionRequest permissionRequest = this.permissionRequest;
                permissionRequest.grant(permissionRequest.getResources());
            }
            this.permissionRequest = null;
        }
    }

    @SimpleFunction(description = "Hides previously shown custom view")
    public void HideCustomView() {
        this.webView.getWebChromeClient().onHideCustomView();
    }

    @SimpleProperty(description = "Sets the initial scale for active WebView. 0 means default. If initial scale is greater than 0, WebView starts with this value as initial scale.")
    public void InitialScale(int i) {
        this.webView.setInitialScale(i);
    }

    @SimpleFunction(description = "Invokes the graphical zoom picker widget for this WebView. This will result in the zoom widget appearing on the screen to control the zoom level of this WebView.Note that it does not checks whether zoom is enabled or not.")
    public void InvokeZoomPicker() {
        this.webView.invokeZoomPicker();
    }

    @SimpleProperty(description = "")
    public int LayerType() {
        return this.webView.getLayerType();
    }

    @SimpleProperty(description = "")
    public void LayerType(int i) {
        this.webView.setLayerType(i, null);
    }

    @SimpleFunction(description = "Loads the given data into this WebView using a 'data' scheme URL.")
    public void LoadHtml(String str) {
        CancelJsRequests();
        this.webView.loadData(Base64.encodeToString(str.getBytes(), 1), NanoHTTPD.MIME_HTML, "base64");
    }

    @SimpleFunction(description = "Loads requested url in given webview")
    public void LoadInNewWindow(int i) {
        if (!this.wv.containsKey(Integer.valueOf(i)) || this.resultObj == null) {
            return;
        }
        ((WebView.WebViewTransport) this.resultObj.obj).setWebView(this.wv.get(Integer.valueOf(i)));
        this.resultObj.sendToTarget();
        this.resultObj = null;
    }

    @SimpleFunction(description = "Loads the given URL with the specified additional HTTP headers defined is list of lists.")
    public void LoadWithHeaders(String str, List<List<String>> list) {
        if (list.size() == 0 || list.get(0).size() != 2) {
            GoToUrl(str);
            return;
        }
        HashMap hashMap = new HashMap();
        for (List<String> list2 : list) {
            hashMap.put(list2.get(0), list2.get(1));
        }
        this.webView.loadUrl(str, hashMap);
    }

    @SimpleProperty(description = "Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width. This setting is taken into account when the content width is greater than the width of the WebView control.")
    public void LoadWithOverviewMode(boolean z) {
        this.webView.getSettings().setLoadWithOverviewMode(z);
    }

    @SimpleProperty(description = "Returns whether the WebView loads pages in overview mode")
    public boolean LoadWithOverviewMode() {
        return this.webView.getSettings().getLoadWithOverviewMode();
    }

    @SimpleProperty(description = "Sets whether to enable text selection and context menu")
    @DesignerProperty(defaultValue = "True", editorType = "boolean")
    public void LongClickable(boolean z) {
        this.webView.setLongClickable(!z);
    }

    @SimpleProperty(description = "Returns whether text selection and context menu are enabled or not")
    public boolean LongClickable() {
        return !this.webView.isLongClickable();
    }

    @SimpleEvent(description = "Event raised when something is long clicked in webview with item(image,string,empty,etc) and type(item type like 0,1,8,etc)")
    public void LongClicked(int i, String str, String str2, int i2) {
        EventDispatcher.dispatchEvent(this, "LongClicked", Integer.valueOf(i), str, str2, Integer.valueOf(i2));
    }

    @SimpleEvent(description = "Event triggered when a window needs to be closed")
    public void OnCloseWindowRequest(int i) {
        EventDispatcher.dispatchEvent(this, "OnCloseWindowRequest", Integer.valueOf(i));
    }

    @SimpleEvent(description = "Event raised after getting console message.")
    public void OnConsoleMessage(String str, int i, int i2, String str2) {
        EventDispatcher.dispatchEvent(this, "OnConsoleMessage", str, Integer.valueOf(i), Integer.valueOf(i2), str2);
    }

    @SimpleEvent(description = "Event raised when downloading is needed.")
    public void OnDownloadNeeded(int i, String str, String str2, String str3, long j) {
        EventDispatcher.dispatchEvent(this, "OnDownloadNeeded", Integer.valueOf(i), str, str2, str3, Long.valueOf(j));
    }

    @SimpleEvent(description = "Event raised when any error is received during loading url and returns message,error code and failing url")
    public void OnErrorReceived(int i, String str, int i2, String str2) {
        EventDispatcher.dispatchEvent(this, "OnErrorReceived", Integer.valueOf(i), str, Integer.valueOf(i2), str2);
    }

    @SimpleEvent(description = "Event raised when resubmission of form is needed")
    public void OnFormResubmission(int i) {
        EventDispatcher.dispatchEvent(this, "OnFormResubmission", Integer.valueOf(i));
    }

    @SimpleEvent
    public void OnGeolocationRequested(String str) {
        EventDispatcher.dispatchEvent(this, "OnGeolocationRequested", str);
    }

    @SimpleEvent(description = "Event raised when current page exits from full screen mode")
    public void OnHideCustomView() {
        EventDispatcher.dispatchEvent(this, "OnHideCustomView", new Object[0]);
    }

    @SimpleEvent(description = "Event raised when Js have to show an alert to user")
    public void OnJsAlert(int i, String str, String str2) {
        EventDispatcher.dispatchEvent(this, "OnJsAlert", Integer.valueOf(i), str, str2);
    }

    @SimpleEvent(description = "Tells to display a confirm dialog to the user.")
    public void OnJsConfirm(int i, String str, String str2) {
        EventDispatcher.dispatchEvent(this, "OnJsConfirm", Integer.valueOf(i), str, str2);
    }

    @SimpleEvent(description = "Event raised when JavaScript needs input from user")
    public void OnJsPrompt(int i, String str, String str2, String str3) {
        EventDispatcher.dispatchEvent(this, "OnJsPrompt", Integer.valueOf(i), str, str2, str3);
    }

    @SimpleEvent(description = "Event raised when new window is requested by webview with boolean 'isDialog' and 'isPopup'")
    public void OnNewWindowRequest(int i, boolean z, boolean z2) {
        EventDispatcher.dispatchEvent(this, "OnNewWindowRequest", Integer.valueOf(i), Boolean.valueOf(z), Boolean.valueOf(z2));
    }

    @SimpleEvent(description = "Event raised when a website asks for specific permission(s) in list format.")
    public void OnPermissionRequest(List<String> list) {
        EventDispatcher.dispatchEvent(this, "OnPermissionRequest", list);
    }

    @SimpleEvent(description = "Event raised when page loading progress has changed.")
    public void OnProgressChanged(int i, int i2) {
        EventDispatcher.dispatchEvent(this, "OnProgressChanged", Integer.valueOf(i), Integer.valueOf(i2));
    }

    @SimpleEvent(description = "Notifies that the WebView received an HTTP authentication request.")
    public void OnReceivedHttpAuthRequest(int i, String str, String str2) {
        EventDispatcher.dispatchEvent(this, "OnReceivedHttpAuthRequest", Integer.valueOf(i), str, str2);
    }

    @SimpleEvent
    public void OnReceivedSslError(int i) {
        EventDispatcher.dispatchEvent(this, "OnReceivedSslError", Integer.valueOf(i));
    }

    @SimpleEvent(description = "Event raised when webview gets scrolled")
    public void OnScrollChanged(int i, int i2, int i3, int i4, int i5, boolean z, boolean z2) {
        EventDispatcher.dispatchEvent(this, "OnScrollChanged", Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), Integer.valueOf(i4), Integer.valueOf(i5), Boolean.valueOf(z), Boolean.valueOf(z2));
    }

    @SimpleEvent(description = "Event raised when current page enters in full screen mode")
    public void OnShowCustomView() {
        EventDispatcher.dispatchEvent(this, "OnShowCustomView", new Object[0]);
    }

    @SimpleProperty(description = "")
    public int OverScrollMode() {
        return this.webView.getOverScrollMode();
    }

    @SimpleProperty(description = "")
    public void OverScrollMode(int i) {
        this.webView.setOverScrollMode(i);
    }

    @SimpleFunction(description = "Scrolls the contents of the WebView down by half the page size")
    public void PageDown(boolean z) {
        this.webView.pageDown(z);
    }

    @SimpleEvent(description = "Event raised when page loading has finished.")
    public void PageLoaded(int i) {
        EventDispatcher.dispatchEvent(this, "PageLoaded", Integer.valueOf(i));
    }

    @SimpleEvent(description = "Event indicating that page loading has started in web view.")
    public void PageStarted(int i, String str) {
        EventDispatcher.dispatchEvent(this, "PageStarted", Integer.valueOf(i), str);
    }

    @SimpleFunction(description = "Scrolls the contents of the WebView up by half the page size")
    public void PageUp(boolean z) {
        this.webView.pageUp(z);
    }

    @SimpleFunction(description = "Does a best-effort attempt to pause any processing that can be paused safely, such as animations and geolocation. Note that this call does not pause JavaScript.")
    public void PauseWebView(int i) {
        this.wv.get(Integer.valueOf(i)).onPause();
    }

    @SimpleFunction(description = "Loads the URL with postData using 'POST' method into active WebView.")
    public void PostData(String str, String str2) {
        this.webView.postUrl(str, str2.getBytes(StandardCharsets.UTF_8));
    }

    @SimpleFunction(description = "Prints the content of webview with given document name")
    public void PrintWebContent(String str) throws Exception {
        PrintManager printManager = (PrintManager) this.context.getSystemService("print");
        if (str.isEmpty()) {
            str = this.webView.getTitle() + "_Document";
        }
        this.jobName = str;
        PrintDocumentAdapterWrapper printDocumentAdapterWrapper = new PrintDocumentAdapterWrapper(this.webView.createPrintDocumentAdapter(this.jobName));
        if (printManager != null) {
            this.printJob = printManager.print(this.jobName, printDocumentAdapterWrapper, new PrintAttributes.Builder().build());
        }
    }

    @SimpleFunction(description = "Instructs the WebView to proceed with the authentication with the given credentials.If both parameters are empty then it will cancel the request.")
    public void ProceedHttpAuthRequest(String str, String str2) {
        if (this.httpAuthHandler != null) {
            if (str.isEmpty() && str2.isEmpty()) {
                this.httpAuthHandler.cancel();
            } else {
                this.httpAuthHandler.proceed(str, str2);
            }
            this.httpAuthHandler = null;
        }
    }

    @SimpleFunction
    public void ProceedSslError(boolean z) {
        SslErrorHandler sslErrorHandler = this.sslHandler;
        if (sslErrorHandler != null) {
            if (z) {
                sslErrorHandler.proceed();
            } else {
                sslErrorHandler.cancel();
            }
            this.sslHandler = null;
        }
    }

    @SimpleProperty(description = "Sets whether webview will prompt for permission and raise 'OnPermissionRequest' event or not else assume permission is granted.")
    @DesignerProperty(defaultValue = "True", editorType = "boolean")
    public void PromptForPermission(boolean z) {
        this.prompt = z;
    }

    @SimpleProperty(description = "Returns whether webview will prompt for permission and raise 'OnPermissionRequest' event or not")
    public boolean PromptForPermission() {
        return this.prompt;
    }

    @SimpleFunction(description = "Reloads the current URL.")
    public void Reload() {
        CancelJsRequests();
        this.webView.reload();
    }

    @SimpleFunction(description = "Destroys the webview and removes it completely from view system")
    public void RemoveWebView(int i) {
        if (this.wv.containsKey(Integer.valueOf(i))) {
            WebView webView = this.wv.get(Integer.valueOf(i));
            ((FrameLayout) webView.getParent()).removeView(webView);
            webView.destroy();
            this.wv.remove(Integer.valueOf(i));
            this.iD = 0;
        }
    }

    @SimpleFunction(description = "Restarts current/previous print job. You can request restart of a failed print job.")
    public void RestartPrinting() throws Exception {
        this.printJob.restart();
    }

    @SimpleFunction(description = "Whether to resubmit form or not.")
    public void ResubmitForm(boolean z) {
        Message message;
        Message message2 = this.reSend;
        if (message2 == null || (message = this.dontSend) == null) {
            return;
        }
        if (z) {
            message2.sendToTarget();
        } else {
            message.sendToTarget();
        }
        this.reSend = null;
        this.dontSend = null;
    }

    @SimpleFunction(description = "Resumes the previously paused WebView.")
    public void ResumeWebView(int i) {
        this.wv.get(Integer.valueOf(i)).onResume();
    }

    @SimpleProperty
    public float RotationAngle() {
        return this.webView.getRotation();
    }

    @SimpleProperty
    public void RotationAngle(float f) {
        this.webView.setRotation(f);
    }

    @SimpleFunction(description = "Saves the current site as a web archive")
    public void SaveArchive(String str) {
        this.webView.saveWebArchive(str, true, new ValueCallback<String>() {
            @Override
            public void onReceiveValue(String str2) {
                if (str2 == null) {
                    CustomWebView.this.AfterArchiveSaved(false, "");
                } else {
                    CustomWebView.this.AfterArchiveSaved(true, str2);
                }
            }
        });
    }

    @SimpleProperty(description = "Whether to display horizonatal and vertical scrollbars or not")
    public void ScrollBar(boolean z) {
        this.webView.setVerticalScrollBarEnabled(z);
        this.webView.setHorizontalScrollBarEnabled(z);
    }

    @SimpleProperty(description = "")
    public int ScrollBarStyle() {
        return this.webView.getScrollBarStyle();
    }

    @SimpleProperty(description = "")
    public void ScrollBarStyle(int i) {
        this.webView.setScrollBarStyle(i);
    }

    @SimpleFunction(description = "Scrolls the webview to given position")
    public void ScrollTo(final int i, final int i2) {
        this.webView.postDelayed(new Runnable() {
            @Override
            public void run() {
                CustomWebView.this.webView.scrollTo(CustomWebView.this.p2d(i), CustomWebView.this.p2d(i2));
            }
        }, 300L);
    }

    @SimpleFunction(description = "Sets cookies for given url")
    public void SetCookies(String str, String str2) {
        try {
            CookieManager.getInstance().setCookie(str, str2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @SimpleFunction(description = "Sets the visibility of webview by id")
    public void SetVisibility(int i, boolean z) {
        WebView webView;
        int i2;
        if (this.wv.containsKey(Integer.valueOf(i))) {
            if (z) {
                webView = this.wv.get(Integer.valueOf(i));
                i2 = 0;
            } else {
                webView = this.wv.get(Integer.valueOf(i));
                i2 = 8;
            }
            webView.setVisibility(i2);
        }
    }

    @SimpleFunction(description = "Set specific webview to current webview by id")
    public void SetWebView(int i) {
        if (this.wv.containsKey(Integer.valueOf(i))) {
            WebView webView = this.wv.get(Integer.valueOf(i));
            this.webView = webView;
            webView.setVisibility(0);
            this.iD = i;
        }
    }

    @SimpleFunction(description = "Stops the current load.")
    public void StopLoading() {
        this.webView.stopLoading();
    }

    @SimpleProperty(description = "Sets whether the WebView supports multiple windows")
    public void SupportMultipleWindows(boolean z) {
        this.webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(z);
        this.webView.getSettings().setSupportMultipleWindows(z);
    }

    @SimpleProperty(description = "Returns whether the WebView supports multiple windows")
    public boolean SupportMultipleWindows() {
        return this.webView.getSettings().getJavaScriptCanOpenWindowsAutomatically();
    }

    @SimpleFunction(description = "Uploads the given file from content uri.Use empty string to cancel the upload request.")
    public void UploadFile(String str) {
        if (this.mFilePathCallback != null) {
            if (str.isEmpty()) {
                this.mFilePathCallback.onReceiveValue(null);
            } else {
                this.mFilePathCallback.onReceiveValue(new Uri[]{Uri.parse(str)});
            }
            this.mFilePathCallback = null;
        }
    }

    @SimpleProperty(description = "Sets whether the WebView should enable support for the 'viewport' HTML meta tag or should use a wide viewport.")
    public void UseWideViewPort(boolean z) {
        this.webView.getSettings().setUseWideViewPort(z);
    }

    @SimpleProperty(description = "Returns whether the WebView should enable support for the 'viewport' HTML meta tag or should use a wide viewport.")
    public boolean UseWideViewPort() {
        return this.webView.getSettings().getUseWideViewPort();
    }

    @SimpleProperty(category = PropertyCategory.BEHAVIOR, description = "Get webview user agent")
    public String UserAgent() {
        return this.UserAgent;
    }

    @SimpleProperty(description = "Sets the WebView's user-agent string. If the string is null or empty, the system default value will be used. ")
    public void UserAgent(String str) {
        if (str.isEmpty()) {
            str = this.MOBILE_USER_AGENT;
        }
        this.UserAgent = str;
        this.webView.getSettings().setUserAgentString(this.UserAgent);
    }

    @SimpleProperty(description = "Whether or not to give the application permission to use the Javascript geolocation API")
    public void UsesLocation(boolean z) {
        this.webView.getSettings().setGeolocationEnabled(z);
    }

    @SimpleProperty(description = "Returns the visibility of current webview")
    public boolean Visible() {
        return this.webView.getVisibility() == 0;
    }

    @SimpleProperty(category = PropertyCategory.BEHAVIOR, description = "Get webview string")
    public String WebViewString() {
        return this.wvInterface.webViewString;
    }

    @SimpleProperty(category = PropertyCategory.BEHAVIOR, description = "Set webview string")
    public void WebViewString(String str) {
        this.wvInterface.setWebViewStringFromBlocks(str);
    }

    @SimpleEvent(description = "When the JavaScript calls AppInventor.setWebViewString this event is run.")
    public void WebViewStringChanged(String str) {
        EventDispatcher.dispatchEvent(this, "WebViewStringChanged", str);
    }

    @SimpleFunction(description = "Performs a zoom operation in the WebView by given zoom percent")
    public void ZoomBy(int i) {
        this.webView.zoomBy(i);
    }

    @SimpleProperty(description = "Sets whether the WebView should support zooming using its on-screen zoom controls and gestures")
    @DesignerProperty(defaultValue = "True", editorType = "boolean")
    public void ZoomEnabled(boolean z) {
        this.zoomEnabled = z;
    }

    @SimpleProperty(description = "Gets whether the WebView should support zooming using its on-screen zoom controls and gestures")
    public boolean ZoomEnabled() {
        return this.zoomEnabled;
    }

    @SimpleFunction(description = "Performs zoom in in the WebView")
    public void ZoomIn() {
        this.webView.zoomIn();
    }

    @SimpleFunction(description = "Performs zoom out in the WebView")
    public void ZoomOut() {
        this.webView.zoomOut();
    }

    @SimpleProperty(description = "Gets the zoom of the page in percent")
    public int ZoomPercent() {
        return this.zoomPercent;
    }

    @SimpleProperty(description = "Sets the zoom of the page in percent. The default is 100")
    @DesignerProperty(defaultValue = "100", editorType = "integer")
    public void ZoomPercent(int i) {
        this.zoomPercent = i;
    }

    public int d2p(int i) {
        return Math.round(i / this.deviceDensity);
    }

    public int getIndex(WebView webView) {
        return ((Integer) new ArrayList(this.wv.keySet()).get(new ArrayList(this.wv.values()).indexOf(webView))).intValue();
    }

    public int p2d(int i) {
        return Math.round(i * this.deviceDensity);
    }

    public void resetWebView(final WebView webView) {
        webView.addJavascriptInterface(this.wvInterface, "AppInventor");
        this.MOBILE_USER_AGENT = webView.getSettings().getUserAgentString();
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
        webView.getSettings().setCacheMode(-1);
        webView.setFocusable(true);
        webView.setWebViewClient(new WebClient());
        webView.setWebChromeClient(new ChromeClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDisplayZoomControls(this.displayZoom);
        webView.getSettings().setAllowFileAccess(false);
        webView.getSettings().setAllowFileAccessFromFileURLs(false);
        webView.getSettings().setAllowUniversalAccessFromFileURLs(false);
        webView.getSettings().setAllowContentAccess(false);
        webView.getSettings().setSupportZoom(this.zoomEnabled);
        webView.getSettings().setBuiltInZoomControls(this.zoomEnabled);
        webView.setLongClickable(false);
        webView.getSettings().setTextZoom(this.zoomPercent);
        this.cookieManager.setAcceptThirdPartyCookies(webView, true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.setVerticalScrollBarEnabled(true);
        webView.setHorizontalScrollBarEnabled(true);
        webView.getSettings().setDefaultFontSize(16);
        webView.getSettings().setBlockNetworkImage(false);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setBlockNetworkLoads(false);
        webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.getSettings().setSupportMultipleWindows(true);
        webView.getSettings().setGeolocationDatabasePath(null);
        webView.getSettings().setDatabaseEnabled(false);
        webView.getSettings().setGeolocationEnabled(false);
        if (this.UserAgent.isEmpty()) {
            this.UserAgent = this.MOBILE_USER_AGENT;
        }
        webView.getSettings().setUserAgentString(this.UserAgent);
        webView.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String str, String str2, String str3, String str4, long j) {
                CustomWebView customWebView = CustomWebView.this;
                customWebView.OnDownloadNeeded(customWebView.getIndex(webView), str, str3, str4, j);
            }
        });
        webView.setFindListener(new WebView.FindListener() {
            @Override
            public void onFindResultReceived(int i, int i2, boolean z) {
                CustomWebView customWebView = CustomWebView.this;
                customWebView.FindResultReceived(customWebView.getIndex(webView), i, i2, z);
            }
        });
        webView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                int action = motionEvent.getAction();
                if ((action != 0 && action != 1) || view.hasFocus()) {
                    return false;
                }
                view.requestFocus();
                return false;
            }
        });
        webView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                WebView.HitTestResult hitTestResult = CustomWebView.this.webView.getHitTestResult();
                String extra = hitTestResult.getExtra();
                int type = hitTestResult.getType();
                if (type == 0) {
                    return false;
                }
                String str = "";
                if (extra == null) {
                    extra = "";
                }
                if (type == 8) {
                    Message obtainMessage = new Handler().obtainMessage();
                    webView.requestFocusNodeHref(obtainMessage);
                    str = (String) obtainMessage.getData().get(ImagesContract.URL);
                }
                CustomWebView customWebView = CustomWebView.this;
                customWebView.LongClicked(customWebView.getIndex(webView), extra, str, type);
                return CustomWebView.this.webView.isLongClickable();
            }
        });
        webView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
            @Override
            public void onScrollChange(View view, int i, int i2, int i3, int i4) {
                CustomWebView customWebView = CustomWebView.this;
                customWebView.OnScrollChanged(customWebView.getIndex(webView), i, i2, i3, i4, webView.canScrollHorizontally(-1), webView.canScrollHorizontally(1));
            }
        });
    }
}