Idle Tower v2.48版本的 MD5 值为:56f20496f6a85726b376356ed2ecee23

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


package com.kidoz.sdk.api.ui_views.html_view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RelativeLayout;
import com.kidoz.events.Event;
import com.kidoz.events.EventManager;
import com.kidoz.events.EventParameters;
import com.kidoz.sdk.api.KidozSDK;
import com.kidoz.sdk.api.dialogs.AboutKidozDialog;
import com.kidoz.sdk.api.dialogs.ParentalLockDialog;
import com.kidoz.sdk.api.general.ContentExecutionHandler;
import com.kidoz.sdk.api.general.EventMessage;
import com.kidoz.sdk.api.general.WidgetEventMessage;
import com.kidoz.sdk.api.general.cache.CacheWebViewFactory;
import com.kidoz.sdk.api.general.database.DatabaseManager;
import com.kidoz.sdk.api.general.enums.ContentType;
import com.kidoz.sdk.api.general.enums.WidgetType;
import com.kidoz.sdk.api.general.utils.ConstantDef;
import com.kidoz.sdk.api.general.utils.KidozParams;
import com.kidoz.sdk.api.general.utils.SDKLogger;
import com.kidoz.sdk.api.general.utils.ScreenUtils;
import com.kidoz.sdk.api.general.utils.SdkCookieManager;
import com.kidoz.sdk.api.general.utils.StorageLife;
import com.kidoz.sdk.api.general.utils.Utils;
import com.kidoz.sdk.api.players.web_player.WebViewVisibilityListener;
import com.kidoz.sdk.api.server_connect.SdkAPIManager;
import com.kidoz.sdk.api.structure.ContentItem;
import com.kidoz.sdk.api.structure.IsEventRecord;
import com.kidoz.sdk.api.ui_views.loading_progress_view.LoadingProgressView;
import com.kidoz.sdk.api.ui_views.one_item_view.ItemViewPagerAdapter;
import com.kidoz.sdk.api.ui_views.web_view_clients.KidozWebChromeClient;
import com.unity3d.services.core.request.metrics.MetricCommonTags;
import java.lang.ref.SoftReference;
import java.net.URLDecoder;
import java.util.LinkedHashMap;
import java.util.Locale;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class HtmlViewWrapper extends RelativeLayout implements HtmlJavaScriptInterafce {
    private static final String JS_OBJECT_NAME = "KidozAndroid";
    protected static final float LOADING_PROGRESS_DEFAULT_RATIO = 0.35f;
    protected static final int ON_AD_STATE_CHANGE = 8;
    protected static final int ON_CLOSE = 3;
    protected static final int ON_LOAD_FINISHED = 0;
    protected static final int ON_LOAD_STARTED = 1;
    protected static final int ON_NOTIFY_AD_READY = 9;
    protected static final int ON_NOTIFY_VAST_AD_READY = 5;
    protected static final int ON_RECEIVED_ERROR = 4;
    protected static final int ON_REWARDED = 6;
    protected static final int ON_REWARDED_STARTED = 7;
    protected static final int ON_VIEW_READY = 2;
    protected static final int ON_VIEW_READY_2 = 10;
    protected static final String TAG = HtmlViewWrapper.class.getSimpleName();
    private boolean blockClick;
    protected AdState mAdState;
    protected boolean mAllowClickHandling;
    private boolean mAllowJSResize;
    private BannerInvokeUrlInterface mBannerInvokeUrlInterface;
    private BannerLoadJSInterface mBannerLoadJSInterface;
    private BannerShowJSInterface mBannerShowJSInterface;
    protected ContentItem mContentItem;
    protected Handler mEventHandler;
    protected Handler mExecutionHandler;
    private GetAdvertiserIdInterface mGetAdvertiserIdInterface;
    protected String mHtmlPageUrl;
    protected IOnHtmlWebViewInterface mHtmlWeViewListener;
    protected SoftReference<Context> mInFocusActivityContext;
    protected boolean mIsShowClose;
    private String mLastOverloadUrl;
    protected LoadingProgressView mLoadingProgressView;
    private int mPreviousOrientation;
    protected IOnInitFinishedListener mSdkInitListener;
    protected String mStyleId;
    protected ItemViewPagerAdapter.ViewPagerItemClickListener mViewPagerItemClickListener;
    public HtmlFiveWebView mWebView;
    protected String mWidgetType;
    public boolean webViewInitialized;

    public enum AdState {
        AD_PLAYING,
        AD_STOPED
    }

    public interface BannerInvokeUrlInterface {
        void onResponse(String str);
    }

    public interface BannerLoadJSInterface {
        void onError(String str);

        void onNoOffers();

        void onSuccess();
    }

    public interface BannerShowJSInterface {
        void onError(String str);

        void onSuccess();
    }

    public interface GetAdvertiserIdInterface {
        void onGetAdvertiserId(String str);
    }

    public interface IOnInitFinishedListener {
        void onInitFinished();
    }

    public void pauseWebView() {
        HtmlFiveWebView htmlFiveWebView = this.mWebView;
        if (htmlFiveWebView != null) {
            htmlFiveWebView.onPause();
        }
    }

    public void resumeWebView() {
        HtmlFiveWebView htmlFiveWebView = this.mWebView;
        if (htmlFiveWebView != null) {
            htmlFiveWebView.onResume();
        }
    }

    public HtmlViewWrapper(Context context, boolean z) {
        super(context);
        this.mWidgetType = "";
        this.mAllowClickHandling = true;
        this.mLastOverloadUrl = "";
        this.mIsShowClose = true;
        this.mAdState = AdState.AD_STOPED;
        this.mAllowJSResize = false;
        this.blockClick = false;
        this.webViewInitialized = false;
        this.mExecutionHandler = new Handler(Looper.getMainLooper());
        try {
            initView(z);
            this.webViewInitialized = true;
        } catch (Throwable th) {
            Log.e(TAG, "Failed to init WebView:\n" + th.getMessage());
        }
    }

    public void setWidgetType(String str) {
        this.mWidgetType = str;
    }

    public String getWidgetType() {
        return this.mWidgetType;
    }

    public void setStyleID(String str) {
        this.mStyleId = str;
    }

    public void setData(ContentItem contentItem) {
        this.mContentItem = contentItem;
        this.mHtmlPageUrl = contentItem.getData();
        setAndApplyExternalProperties(contentItem.getExtraParameters());
    }

    public void setInFocusActivityContext(Context context) {
        if (context != null) {
            try {
                if (context instanceof Activity) {
                    this.mPreviousOrientation = ((Activity) context).getRequestedOrientation();
                    this.mInFocusActivityContext = new SoftReference<>(context);
                }
            } catch (Exception e) {
                Log.d(TAG, "setInFocusActivityContext | exception: " + e.getLocalizedMessage());
            }
        }
    }

    private void setAndApplyExternalProperties(JSONObject jSONObject) {
        JSONObject optJSONObject;
        HtmlFiveWebView htmlFiveWebView;
        if (jSONObject != null) {
            if (jSONObject.has("webview_properties") && !jSONObject.isNull("webview_properties") && (optJSONObject = jSONObject.optJSONObject("webview_properties")) != null && (htmlFiveWebView = this.mWebView) != null) {
                htmlFiveWebView.applyProperties(optJSONObject);
            }
            this.mIsShowClose = jSONObject.optBoolean("showClose", false);
        }
    }

    public void reloadHtml() {
        loadHtml(this.mHtmlPageUrl);
    }

    public void loadHtml(String str) {
        setBlockClick(false);
        try {
            CacheWebViewFactory cacheWebViewFactory = CacheWebViewFactory.getInstance();
            if (!cacheWebViewFactory.hasCache(str)) {
                cacheWebViewFactory.addCacheAsync(str, str, null);
                this.mLastOverloadUrl = "";
                this.mHtmlPageUrl = str;
                if (str.startsWith("http://")) {
                    return;
                }
                if (this.mHtmlPageUrl != null) {
                    ScreenUtils.getScreenSize(getContext());
                    this.mHtmlPageUrl.contains("?");
                    if (this.mWebView != null) {
                        this.mWebView.loadUrl(str);
                    }
                }
            } else if (this.mWebView != null) {
                this.mWebView.loadDataWithBaseURL(cacheWebViewFactory.getCache(str).getWebUrl(), cacheWebViewFactory.getCache(str).getWebViewContent(), "text/html", "utf-8", null);
            }
        } catch (Exception unused) {
        }
    }

    private void initView(boolean z) throws Exception {
        initHandler();
        initWebView(z);
        initProgressLoadingView();
    }

    private void initHandler() {
        this.mEventHandler = new Handler(Looper.getMainLooper()) {
            @Override
            public void handleMessage(Message message) {
                super.handleMessage(message);
                HtmlViewWrapper.this.onHandleLocalUiThreadedEvents(message);
            }
        };
    }

    protected void onHandleLocalUiThreadedEvents(Message message) {
        WidgetEventMessage widgetEventMessage = null;
        r5 = null;
        r5 = null;
        JSONObject jSONObject = null;
        r5 = null;
        r5 = null;
        JSONObject jSONObject2 = null;
        widgetEventMessage = null;
        switch (message.what) {
            case 0:
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface != null) {
                    iOnHtmlWebViewInterface.onHtmlFinishedLoading();
                }
                IOnInitFinishedListener iOnInitFinishedListener = this.mSdkInitListener;
                if (iOnInitFinishedListener != null) {
                    iOnInitFinishedListener.onInitFinished();
                    this.mSdkInitListener = null;
                    return;
                }
                return;
            case 1:
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface2 = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface2 != null) {
                    iOnHtmlWebViewInterface2.onHtmlStartLoading();
                    return;
                }
                return;
            case 2:
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface3 = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface3 != null) {
                    iOnHtmlWebViewInterface3.onViewReady();
                    return;
                }
                return;
            case 3:
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface4 = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface4 != null) {
                    iOnHtmlWebViewInterface4.onClose();
                }
                String str = this.mWidgetType;
                if (str != null && str.equals(WidgetType.WIDGET_TYPE_INTERSTITIAL_REWARDED.getStringValue())) {
                    widgetEventMessage = new WidgetEventMessage(EventMessage.MessageType.INTERSTITIAL_AD_CLOSE, WidgetType.WIDGET_TYPE_INTERSTITIAL_REWARDED);
                } else {
                    String str2 = this.mWidgetType;
                    if (str2 != null && str2.equals(WidgetType.WIDGET_TYPE_INTERSTITIAL.getStringValue())) {
                        widgetEventMessage = new WidgetEventMessage(EventMessage.MessageType.INTERSTITIAL_AD_CLOSE, WidgetType.WIDGET_TYPE_INTERSTITIAL);
                    }
                }
                if (widgetEventMessage != null) {
                    EventBus.getDefault().post(widgetEventMessage);
                }
                clearCache();
                return;
            case 4:
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface5 = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface5 != null) {
                    iOnHtmlWebViewInterface5.onErrorReceived();
                    return;
                }
                return;
            case 5:
                if (this.mHtmlWeViewListener != null) {
                    if (message.obj != null && (message.obj instanceof String)) {
                        try {
                            jSONObject2 = new JSONObject((String) message.obj);
                        } catch (JSONException unused) {
                            SDKLogger.printErrorLog(HtmlViewWrapper.class.getCanonicalName(), "Error parsing vast properties!");
                        }
                    }
                    if (message.arg1 == 1) {
                        this.mHtmlWeViewListener.onNotifyVastReady(true, jSONObject2);
                        return;
                    } else {
                        this.mHtmlWeViewListener.onNotifyVastReady(false, jSONObject2);
                        return;
                    }
                }
                return;
            case 6:
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface6 = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface6 != null) {
                    iOnHtmlWebViewInterface6.onRewarded();
                    return;
                }
                return;
            case 7:
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface7 = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface7 != null) {
                    iOnHtmlWebViewInterface7.onRewardedVideoStarted();
                    return;
                }
                return;
            case 8:
                try {
                    this.mAdState = AdState.values()[message.arg1];
                } catch (Exception unused2) {
                }
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface8 = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface8 != null) {
                    iOnHtmlWebViewInterface8.onAdStateChanged(this.mAdState);
                    return;
                }
                return;
            case 9:
                if (this.mHtmlWeViewListener != null) {
                    if (message.obj != null && (message.obj instanceof String)) {
                        try {
                            jSONObject = new JSONObject((String) message.obj);
                        } catch (JSONException unused3) {
                            SDKLogger.printErrorLog(HtmlViewWrapper.class.getCanonicalName(), "Error parsing vast properties!");
                        }
                    }
                    if (message.arg1 == 1) {
                        this.mHtmlWeViewListener.onNotifyAdReady(true, jSONObject);
                        return;
                    } else {
                        this.mHtmlWeViewListener.onNotifyAdReady(false, jSONObject);
                        return;
                    }
                }
                return;
            case 10:
                IOnHtmlWebViewInterface iOnHtmlWebViewInterface9 = this.mHtmlWeViewListener;
                if (iOnHtmlWebViewInterface9 != null) {
                    iOnHtmlWebViewInterface9.onViewReady2();
                    return;
                }
                return;
            default:
                return;
        }
    }

    private void initWebView(boolean z) throws Exception {
        try {
            this.mWebView = new HtmlFiveWebView(getContext());
            if (z) {
                clearCache();
            }
            this.mWebView.setWebViewVisibilityListener(new WebViewVisibilityListener() {
                @Override
                public void onWebViewBecameVisible(boolean z2) {
                    if (z2) {
                        HtmlViewWrapper.this.invokeJSfunction("javascript:focus()");
                    } else {
                        HtmlViewWrapper.this.invokeJSfunction("javascript:blur()");
                    }
                }
            });
            applyJavaScriptInterfaces();
            this.mWebView.setWebViewClient(new WebViewClient() {
                @Override
                public void onLoadResource(WebView webView, String str) {
                }

                @Override
                public WebResourceResponse shouldInterceptRequest(WebView webView, String str) {
                    if (str.startsWith("http://")) {
                        return new WebResourceResponse(null, null, null);
                    }
                    return super.shouldInterceptRequest(webView, str);
                }

                @Override
                public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
                    super.onPageStarted(webView, str, bitmap);
                    HtmlViewWrapper.this.mEventHandler.sendEmptyMessage(1);
                }

                @Override
                public void onPageFinished(WebView webView, String str) {
                    super.onPageFinished(webView, str);
                    HtmlViewWrapper.this.mEventHandler.sendEmptyMessage(0);
                    if (HtmlViewWrapper.this.mAllowJSResize) {
                        SDKLogger.printDebugLog("KidozBannerPresenter | onPageFinished | calling js.resize");
                        HtmlViewWrapper.this.mWebView.loadUrl("javascript:KidozAndroid.resize(document.body.getBoundingClientRect().width, document.body.getBoundingClientRect().height)");
                    }
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView webView, String str) {
                    if (HtmlViewWrapper.this.blockClick || str.startsWith("http://")) {
                        return true;
                    }
                    HtmlViewWrapper.this.mLastOverloadUrl = str;
                    SDKLogger.printDebugLog("KidozBannerPresenter | shouldOverrideUrlLoading | url: " + str);
                    if (HtmlViewWrapper.this.mContentItem != null && HtmlViewWrapper.this.mContentItem.getContentType() != null && HtmlViewWrapper.this.mContentItem.getContentType() == ContentType.ROVIO_ITEM) {
                        return super.shouldOverrideUrlLoading(webView, str);
                    }
                    return HtmlViewWrapper.this.handleOverrideUrlLoading(webView, str);
                }

                @Override
                public void onReceivedError(WebView webView, int i, String str, String str2) {
                    SDKLogger.printDebugLog("KidozBannerPresenter | onReceivedError: " + i + ", description: " + str);
                    Event event = new Event();
                    if (HtmlViewWrapper.this.mContentItem != null) {
                        event.addParameterToJsonObject(EventParameters.ITEM_ID, HtmlViewWrapper.this.mContentItem.getId());
                        event.addParameterToJsonObject(EventParameters.ADVERTISER_ID, HtmlViewWrapper.this.mContentItem.getAdvertiserID());
                    }
                    EventManager.getInstance(HtmlViewWrapper.this.getContext()).logEvent(HtmlViewWrapper.this.getContext(), HtmlViewWrapper.this.mWidgetType, HtmlViewWrapper.this.mStyleId, EventManager.LOG_CRITICAL_LEVEL, event, EventParameters.CATEGORY_WEB_VIEW_ERROR, String.valueOf(i).concat(": ").concat(str), str2);
                }
            });
            this.mWebView.setWebChromeClient(new KidozWebChromeClient());
            addView(this.mWebView, new RelativeLayout.LayoutParams(-1, -1));
        } catch (Throwable th) {
            String str = "Failed to init WebView:\n" + th.getMessage();
            Log.e(TAG, str);
            throw new Exception(str);
        }
    }

    protected void applyJavaScriptInterfaces() {
        this.mWebView.addJavascriptInterface(this, JS_OBJECT_NAME);
    }

    protected boolean handleOverrideUrlLoading(WebView webView, String str) {
        openGooglePlayStore(str);
        return true;
    }

    protected void openGooglePlayStore(String str) {
        try {
            if (this.mContentItem != null && this.mContentItem.getContentType() != null) {
                int i = AnonymousClass30.$SwitchMap$com$kidoz$sdk$api$general$enums$ContentType[this.mContentItem.getContentType().ordinal()];
                if (i == 1) {
                    openGooglePlayInBackground(str);
                } else if (i == 2) {
                    if (this.mContentItem.getJSONitem() != null) {
                        try {
                            if (this.mContentItem.getJSONitem().getJSONObject(11).optBoolean("cpi_play", false)) {
                                openGooglePlayInBackground(str);
                            } else {
                                openGooglePlayInForground(str);
                            }
                        } catch (Exception unused) {
                            openGooglePlayInForground(str);
                        }
                    } else {
                        openGooglePlayInForground(str);
                    }
                } else {
                    openGooglePlayInForground(str);
                }
            } else {
                openGooglePlayInForground(str);
            }
        } catch (Exception e) {
            SDKLogger.printErrorLog(TAG, "Error when trying to open google start for promoted app: \n" + e.getMessage());
        }
    }

    public static class AnonymousClass30 {
        static final int[] $SwitchMap$com$kidoz$sdk$api$general$enums$ContentType;

        static {
            int[] iArr = new int[ContentType.values().length];
            $SwitchMap$com$kidoz$sdk$api$general$enums$ContentType = iArr;
            try {
                iArr[ContentType.PROMOTED_PLAY_APPLICATION.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$kidoz$sdk$api$general$enums$ContentType[ContentType.HTML.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
        }
    }

    protected void openGooglePlayInForground(final String str) {
        final Context context = this.mInFocusActivityContext.get();
        if (context == null) {
            context = getContext();
        }
        getAdvertiserId(new GetAdvertiserIdInterface() {
            @Override
            public void onGetAdvertiserId(String str2) {
                if (str2 == null || str2.equals("")) {
                    return;
                }
                String str3 = null;
                Uri parse = Uri.parse(str);
                parse.getHost();
                String uri = parse.toString();
                if (uri != null) {
                    if (uri.contains("play.google.com") || uri.contains("market.android.com") || uri.contains("market://")) {
                        try {
                            str3 = URLDecoder.decode(parse.getQueryParameter("id"), "UTF-8");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (str3 == null || str3.equals("")) {
                            return;
                        }
                        IsEventRecord isEventRecord = new IsEventRecord();
                        isEventRecord.setPackageName(str3);
                        isEventRecord.setContentType(ContentType.PROMOTED_PLAY_APPLICATION.toString());
                        isEventRecord.setName("");
                        isEventRecord.setPositionIndex(0);
                        isEventRecord.setAdvertiserId(str2);
                        isEventRecord.setTimeStamp(System.currentTimeMillis() + "");
                        isEventRecord.setWidgetType(HtmlViewWrapper.this.mWidgetType);
                        isEventRecord.setStyleId(HtmlViewWrapper.this.mStyleId);
                        DatabaseManager.getInstance(context).getIsEventTable().insertRecord(isEventRecord);
                    }
                }
            }
        });
        ContentExecutionHandler.checkForParentalLock(context, new ContentExecutionHandler.IOnParentalLockStatusListener() {
            @Override
            public void onLockActive(boolean z) {
                if (z) {
                    Intent intent = new Intent("android.intent.action.VIEW");
                    intent.setData(Uri.parse(str));
                    if (context != null) {
                        intent.addFlags(268435456);
                        context.startActivity(intent);
                        return;
                    }
                    return;
                }
                EventManager.getInstance(context).logEvent(context, HtmlViewWrapper.this.mWidgetType, HtmlViewWrapper.this.mStyleId, EventManager.LOG_NORMAL_LEVEL, null, EventParameters.CATEGORY_SPONSORED_CONTENT, EventParameters.ACTION_PARENTAL_INCORRECT_PASSWORD, "");
            }

            @Override
            public void onLockNotActive() {
                Intent intent = new Intent("android.intent.action.VIEW");
                intent.setData(Uri.parse(str));
                if (context != null) {
                    intent.addFlags(268435456);
                    context.startActivity(intent);
                }
            }
        });
    }

    protected void openGooglePlayInBackground(String str) {
        Context context = this.mInFocusActivityContext.get();
        if (context == null) {
            context = getContext();
        }
        ContentItem contentItem = new ContentItem();
        contentItem.setContentType(ContentType.PROMOTED_PLAY_APPLICATION);
        contentItem.setData(str);
        contentItem.setId(this.mContentItem.getId());
        ContentExecutionHandler.handleContentItemClick(context, contentItem, this.mWidgetType, this.mStyleId, 0, false, null);
    }

    private void initProgressLoadingView() {
        this.mLoadingProgressView = new LoadingProgressView(getContext());
        Point screenSize = Utils.getScreenSize(getContext());
        int min = (int) (Math.min(screenSize.x, screenSize.y) * LOADING_PROGRESS_DEFAULT_RATIO);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(min, min);
        layoutParams.addRule(13);
        addView(this.mLoadingProgressView, layoutParams);
    }

    protected void invokeOnImpressionServed(final String str, final String str2, final String str3, final String str4) {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                int i;
                try {
                    i = Integer.parseInt(str4);
                } catch (Exception e) {
                    SDKLogger.printErrorLog(HtmlViewWrapper.TAG, "Error when trying to parse positionIndex: " + e.getMessage());
                    i = 0;
                }
                EventManager.getInstance(HtmlViewWrapper.this.getContext()).logSponsoredContentImpressionEvent(HtmlViewWrapper.this.getContext(), HtmlViewWrapper.this.mWidgetType, HtmlViewWrapper.this.mStyleId, EventParameters.ACTION_IMPRESSION, str2, str3, str, i);
            }
        });
    }

    protected void invokeOnSimulateClick(final String str, final int i) {
        if (str != null) {
            this.mExecutionHandler.post(new Runnable() {
                @Override
                public void run() {
                    ContentItem contentItem = null;
                    try {
                        JSONArray jSONArray = new JSONArray(str);
                        if (jSONArray.length() > 1) {
                            JSONArray jSONArray2 = jSONArray.getJSONArray(0);
                            LinkedHashMap linkedHashMap = new LinkedHashMap();
                            if (jSONArray2 != null && jSONArray2.length() > 0) {
                                for (int i2 = 0; i2 < jSONArray2.length(); i2++) {
                                    linkedHashMap.put(jSONArray2.getString(i2), Integer.valueOf(i2));
                                }
                            }
                            if (!linkedHashMap.isEmpty() && jSONArray.getJSONArray(1) != null) {
                                contentItem = new ContentItem(jSONArray.getJSONArray(1), linkedHashMap);
                            }
                        }
                    } catch (JSONException e) {
                        String localizedMessage = e.getLocalizedMessage();
                        if (!TextUtils.isEmpty(localizedMessage)) {
                            SDKLogger.printErrorLog(localizedMessage);
                        }
                    }
                    ContentItem contentItem2 = contentItem;
                    if (contentItem2 == null || !HtmlViewWrapper.this.mAllowClickHandling) {
                        return;
                    }
                    HtmlViewWrapper.this.mAllowClickHandling = false;
                    if (HtmlViewWrapper.this.mInFocusActivityContext == null || HtmlViewWrapper.this.mInFocusActivityContext.get() == null) {
                        return;
                    }
                    ContentExecutionHandler.handleContentItemClick(HtmlViewWrapper.this.mInFocusActivityContext.get(), contentItem2, HtmlViewWrapper.this.mWidgetType, HtmlViewWrapper.this.mStyleId, i, true, new ContentExecutionHandler.IOnHandleClickListener() {
                        @Override
                        public void onRestoreClick() {
                            HtmlViewWrapper.this.mAllowClickHandling = true;
                        }
                    });
                }
            });
        }
    }

    protected void invokeAboutClick() {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                HtmlViewWrapper.this.startAboutKidozDialog();
            }
        });
    }

    protected void invokeParentalClick() {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                HtmlViewWrapper.this.startParentalLockDialog();
            }
        });
    }

    protected void invokeMaximizedClick() {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                if (HtmlViewWrapper.this.mHtmlWeViewListener != null) {
                    HtmlViewWrapper.this.mHtmlWeViewListener.onOpenMaximized();
                }
            }
        });
    }

    protected void invokeInitiateWebViewProperties(final String str) {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                try {
                    HtmlViewWrapper.this.mWebView.applyProperties(new JSONObject(str));
                } catch (JSONException unused) {
                }
            }
        });
    }

    protected void onInvokeConversionServed(final String str, final String str2, final String str3, final String str4, final String str5, final String str6) {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                int i;
                int i2;
                int i3;
                try {
                    i = Integer.parseInt(str4);
                } catch (Exception e) {
                    SDKLogger.printErrorLog(HtmlViewWrapper.TAG, "Error when trying to parse positionIndex: " + e.getMessage());
                    i = 0;
                }
                try {
                    i2 = Integer.parseInt(str5);
                } catch (Exception e2) {
                    SDKLogger.printErrorLog(HtmlViewWrapper.TAG, "Error when trying to parse rewardKey: " + e2.getMessage());
                    i2 = 0;
                }
                try {
                    i3 = Integer.parseInt(str6);
                } catch (Exception e3) {
                    SDKLogger.printErrorLog(HtmlViewWrapper.TAG, "Error when trying to parse rewardValue: " + e3.getMessage());
                    i3 = 0;
                }
                EventManager.getInstance(HtmlViewWrapper.this.getContext()).logSponsoredConversionEvent(HtmlViewWrapper.this.getContext(), HtmlViewWrapper.this.mWidgetType, HtmlViewWrapper.this.mStyleId, new Event(), str2, str3, str, i, i2, i3);
            }
        });
    }

    protected void onRequestStoreLocalParam(final String str, final String str2, final String str3) {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                SdkCookieManager.saveData(HtmlViewWrapper.this.getContext(), HtmlViewWrapper.this.mWidgetType, HtmlViewWrapper.this.mHtmlPageUrl, str, str2, StorageLife.valueOf(str3));
            }
        });
    }

    protected void onGetLocalParam(final String str, final String str2) {
        final String loadData = SdkCookieManager.loadData(getContext(), this.mWidgetType, this.mHtmlPageUrl, str2);
        if (str == null) {
            str = "kidozReturnedValue";
        }
        this.mEventHandler.post(new Runnable() {
            @Override
            public void run() {
                HtmlViewWrapper.this.invokeJSfunction("javascript:" + str + "('" + str2 + "','" + loadData + "'  );");
            }
        });
    }

    private void onGetDonePlayback() {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                if (HtmlViewWrapper.this.mHtmlWeViewListener != null) {
                    HtmlViewWrapper.this.mHtmlWeViewListener.onDonePlayBack();
                }
            }
        });
    }

    private void onGetParentalLockState(final String str) {
        if (str != null) {
            final boolean isParentalLockActive = ParentalLockDialog.isParentalLockActive(getContext());
            this.mExecutionHandler.post(new Runnable() {
                @Override
                public void run() {
                    HtmlViewWrapper.this.invokeJSfunction("javascript:" + str + "('" + isParentalLockActive + "');");
                }
            });
        }
    }

    protected void onForwardToGooglePlay(final String str, final String str2, final String str3, final String str4, final String str5, final String str6) {
        if (str3.startsWith("http://")) {
            return;
        }
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                int i;
                try {
                    i = Integer.parseInt(str6);
                } catch (Exception e) {
                    SDKLogger.printErrorLog(HtmlViewWrapper.TAG, "Error when trying to parse item index: " + e.getMessage());
                    i = 0;
                }
                ContentItem contentItem = new ContentItem();
                contentItem.setId(str2);
                contentItem.setName("");
                contentItem.setData(str3);
                contentItem.setContentType(ContentType.PROMOTED_PLAY_APPLICATION);
                contentItem.setAdvertiserID(str);
                contentItem.setIsPromoted(true);
                if (HtmlViewWrapper.this.mViewPagerItemClickListener != null) {
                    HtmlViewWrapper.this.mViewPagerItemClickListener.onClickEnd(contentItem, i);
                } else {
                    if (HtmlViewWrapper.this.mInFocusActivityContext == null || HtmlViewWrapper.this.mInFocusActivityContext.get() == null) {
                        return;
                    }
                    ContentExecutionHandler.handleContentItemClick(HtmlViewWrapper.this.mInFocusActivityContext.get(), contentItem, str4, str5, i, false, null);
                }
            }
        });
    }

    protected void invokeSetDeviceOrientation(final int i) {
        SoftReference<Context> softReference = this.mInFocusActivityContext;
        if (softReference == null || softReference.get() == null || !(this.mInFocusActivityContext.get() instanceof Activity)) {
            return;
        }
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                int i2 = i;
                if (i2 == 0) {
                    i2 = 6;
                }
                ((Activity) HtmlViewWrapper.this.mInFocusActivityContext.get()).setRequestedOrientation(i2);
            }
        });
    }

    protected void onInvokeSendEvent(final String str, final String str2, final String str3, final String str4, final String str5) {
        if (str2 == null || str3 == null) {
            return;
        }
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                SDKLogger.printDebugLog("RONY", "type = " + str);
                SDKLogger.printDebugLog("RONY", "category = " + str2);
                SDKLogger.printDebugLog("RONY", "action = " + str3);
                SDKLogger.printDebugLog("RONY", "label = " + str4);
                SDKLogger.printDebugLog("RONY", "jsonData = " + str5);
                SDKLogger.printDebugLog("RONY", "mStyleId = " + HtmlViewWrapper.this.mStyleId);
                SDKLogger.printDebugLog("RONY", "mWidgetType = " + HtmlViewWrapper.this.mWidgetType);
                Event event = new Event();
                event.setLogLevel(EventManager.LOG_NORMAL_LEVEL);
                String str6 = str5;
                if (str6 != null) {
                    event.addParameterToJsonObject(str6);
                }
                EventManager.getInstance(HtmlViewWrapper.this.getContext()).logEvent(HtmlViewWrapper.this.getContext(), HtmlViewWrapper.this.mWidgetType, HtmlViewWrapper.this.mStyleId, EventManager.LOG_NORMAL_LEVEL, event, str2, str3, str4);
            }
        });
    }

    protected void onToggleLoadingState(final boolean z) {
        if (this.mLoadingProgressView != null) {
            this.mExecutionHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (z) {
                        HtmlViewWrapper.this.mLoadingProgressView.startLoadingAnimation();
                    } else {
                        HtmlViewWrapper.this.mLoadingProgressView.stopLoadingAnimation();
                    }
                }
            });
        }
    }

    protected void onNotifyIsVastAdReady(boolean z, String str) {
        Message obtain = Message.obtain();
        obtain.what = 5;
        if (z) {
            obtain.arg1 = 1;
        } else {
            obtain.arg1 = 0;
        }
        if (str != null) {
            obtain.obj = str;
        }
        this.mEventHandler.sendMessage(obtain);
    }

    protected void onNotifyAdReady(boolean z, String str) {
        Message obtain = Message.obtain();
        obtain.what = 9;
        if (z) {
            obtain.arg1 = 1;
        } else {
            obtain.arg1 = 0;
        }
        if (str != null) {
            obtain.obj = str;
        }
        this.mEventHandler.sendMessage(obtain);
    }

    protected void onNotifyIsVastAdReady(boolean z) {
        Message obtain = Message.obtain();
        obtain.what = 5;
        if (z) {
            obtain.arg1 = 1;
        } else {
            obtain.arg1 = 0;
        }
        this.mEventHandler.sendMessage(obtain);
    }

    protected void setParentalLockState(boolean z) {
        invokeJSfunction("javascript:kidozOnParentalLockStateChanged('" + z + "');");
    }

    protected void startParentalLockDialog() {
        SoftReference<Context> softReference = this.mInFocusActivityContext;
        if (softReference == null || softReference.get() == null) {
            return;
        }
        ParentalLockDialog.startParentalDialog(this.mInFocusActivityContext.get(), false, 0.5f, 0.5f, new ParentalLockDialog.IOnParentalDialogListener() {
            @Override
            public void onCloseDialog() {
                HtmlViewWrapper.this.updateLockIcon();
            }

            @Override
            public void onInputPass(boolean z) {
                HtmlViewWrapper.this.updateLockIcon();
            }
        });
        updateLockIcon();
    }

    protected void startAboutKidozDialog() {
        int[] iArr = {(int) (ScreenUtils.getScreenSize(getContext(), true) * 0.5f), (int) (ScreenUtils.getScreenSize(getContext(), false) * 0.5f)};
        SoftReference<Context> softReference = this.mInFocusActivityContext;
        if (softReference == null || softReference.get() == null) {
            return;
        }
        new AboutKidozDialog(this.mInFocusActivityContext.get(), iArr).openDialog();
    }

    protected void updateLockIcon() {
        try {
            if (ParentalLockDialog.isParentalLockActive(getContext())) {
                setParentalLockState(true);
            } else {
                setParentalLockState(false);
            }
        } catch (Exception e) {
            SDKLogger.printErrorLog(TAG, "Error when trying to load parental lock image: " + e.getMessage());
        }
    }

    public void requestFocusOn(boolean z) {
        invokeJSfunction("javascript:toonsWebApi.appForeground()");
        ContentItem contentItem = this.mContentItem;
        if (contentItem != null) {
            JSONArray jSONitem = contentItem.getJSONitem();
            try {
                jSONitem.put(1, jSONitem.getString(1).replace("\"", ""));
            } catch (Exception unused) {
            }
            invokeJSfunction("javascript:kidozOnFocusOn('" + this.mContentItem.getId() + "','" + jSONitem.toString() + "','" + z + "','" + this.mWidgetType + "','" + this.mContentItem.getRealViewIndex() + "');");
        }
    }

    public void requestFocusOff() {
        invokeJSfunction("javascript:toonsWebApi.appBackground()");
        if (this.mContentItem != null) {
            invokeJSfunction("javascript:kidozOnFocusOff('" + this.mContentItem.getId() + "');");
        }
    }

    public void requestMaximize() {
        invokeJSfunction("javascript:kidozOnMaximize();");
    }

    public void requestMinimize() {
        invokeJSfunction("javascript:kidozOnMinimize();");
    }

    public void requestWidgetOpen(String str) {
        if (str != null) {
            invokeJSfunction("javascript:kidozOnWidgetOpen('" + str + "');");
        }
    }

    public void requestWidgetClose(String str) {
        if (str != null) {
            invokeJSfunction("javascript:kidozOnWidgetClose('" + str + "');");
        }
    }

    public void requestVastAds(int i) {
        invokeJSfunction("javascript:requestAds('" + i + "');");
    }

    public void startVastAd() {
        invokeJSfunction("javascript:startVastAd();");
    }

    public void startAd() {
        invokeJSfunction("javascript:startAd();");
    }

    public void getAdvertiserId() {
        invokeJSfunction("javascript:getAdvertiserId();");
    }

    public void getAdvertiserId(GetAdvertiserIdInterface getAdvertiserIdInterface) {
        this.mGetAdvertiserIdInterface = getAdvertiserIdInterface;
        invokeJSfunction("javascript:getAdvertiserId();");
    }

    public void stopVastAd() {
        invokeJSfunction("javascript:stopVastAd();");
    }

    public void stopAd() {
        invokeJSfunction("javascript:stopAd();");
    }

    public void pauseVastAd() {
        invokeJSfunction("javascript:pauseVastAd();");
    }

    public void resumeVastAd() {
        invokeJSfunction("javascript:resumeVastAd();");
    }

    public void loadContent(String str, String str2) {
        invokeJSfunction("javascript:loadContent('" + str + "','" + str2 + "');");
    }

    public void clearHtmlView() {
        this.mWebView.loadUrl("");
    }

    public void destroy() {
        try {
            removeView(this.mWebView);
            this.mWebView.destroy();
        } catch (Exception unused) {
        } catch (Throwable th) {
            this.mWebView = null;
            throw th;
        }
        this.mWebView = null;
    }

    public void setHtmlWebViewListener(IOnHtmlWebViewInterface iOnHtmlWebViewInterface) {
        this.mHtmlWeViewListener = iOnHtmlWebViewInterface;
    }

    public void setSdkInitListener(IOnInitFinishedListener iOnInitFinishedListener) {
        this.mSdkInitListener = iOnInitFinishedListener;
    }

    public void loadBanner(JSONObject jSONObject, BannerLoadJSInterface bannerLoadJSInterface) {
        this.mBannerLoadJSInterface = bannerLoadJSInterface;
        invokeJSfunction("javascript:loadBanner(" + jSONObject + ");");
    }

    public void showBanner(BannerShowJSInterface bannerShowJSInterface) {
        this.mBannerShowJSInterface = bannerShowJSInterface;
        invokeJSfunction("javascript:showBanner();");
    }

    public void hideBanner() {
        invokeJSfunction("javascript:hideBanner();");
    }

    @JavascriptInterface
    public void invokeJavaBannerLoad(boolean z, String str) {
        onJSBannerLoad(z, str);
    }

    private void onJSBannerLoad(boolean z, final String str) {
        if (this.mBannerLoadJSInterface == null) {
            SDKLogger.printErrorLog("JS called banner load on Java but the load listener was empty.");
            return;
        }
        Log.d("kidozbanner", "onJSBannerLoad called from JS. success = " + z);
        if (z) {
            this.mExecutionHandler.post(new Runnable() {
                @Override
                public void run() {
                    HtmlViewWrapper.this.mBannerLoadJSInterface.onSuccess();
                }
            });
        } else {
            this.mExecutionHandler.post(new Runnable() {
                @Override
                public void run() {
                    HtmlViewWrapper.this.mBannerLoadJSInterface.onError(str);
                    HtmlViewWrapper.this.mBannerLoadJSInterface.onNoOffers();
                }
            });
        }
    }

    @JavascriptInterface
    public void invokeJavaBannerShow(boolean z, String str) {
        onJSBannerShow(z, str);
    }

    private void onJSBannerShow(boolean z, final String str) {
        if (this.mBannerShowJSInterface == null) {
            SDKLogger.printErrorLog("JS called banner show on Java but the load listener was empty.");
        } else if (z) {
            this.mExecutionHandler.post(new Runnable() {
                @Override
                public void run() {
                    HtmlViewWrapper.this.mBannerShowJSInterface.onSuccess();
                }
            });
        } else {
            this.mExecutionHandler.post(new Runnable() {
                @Override
                public void run() {
                    HtmlViewWrapper.this.mBannerShowJSInterface.onError(str);
                }
            });
        }
    }

    public void invokeUrl(String str, BannerInvokeUrlInterface bannerInvokeUrlInterface) {
        this.mBannerInvokeUrlInterface = bannerInvokeUrlInterface;
        invokeJSfunction("javascript:" + str);
    }

    @JavascriptInterface
    public void onInvokeUrlResponse(String str) {
        BannerInvokeUrlInterface bannerInvokeUrlInterface = this.mBannerInvokeUrlInterface;
        if (bannerInvokeUrlInterface != null) {
            bannerInvokeUrlInterface.onResponse(str);
        }
    }

    public void invokeJSfunction(final String str) {
        try {
            this.mExecutionHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (Build.VERSION.SDK_INT >= 19) {
                            if (HtmlViewWrapper.this.mWebView != null) {
                                HtmlViewWrapper.this.mWebView.evaluateJavascript(str, new ValueCallback<String>() {
                                    @Override
                                    public void onReceiveValue(String str2) {
                                        SDKLogger.printDebugLog("KidozBannerPresenter invokeJSfunction (" + str + ") | evaluateJS return value = " + str2);
                                    }
                                });
                            }
                        } else if (HtmlViewWrapper.this.mWebView != null) {
                            HtmlViewWrapper.this.mWebView.loadUrl(str);
                        }
                    } catch (Exception unused) {
                        if (HtmlViewWrapper.this.mWebView != null) {
                            HtmlViewWrapper.this.mWebView.loadUrl(str);
                        }
                    }
                }
            });
        } catch (Exception e) {
            SDKLogger.printDebugLog("HtmlViewWrapper | invokeJS exception: " + e.getLocalizedMessage());
        }
    }

    public boolean isShowClose() {
        return this.mIsShowClose;
    }

    public void showLoadingProgressView() {
        LoadingProgressView loadingProgressView = this.mLoadingProgressView;
        if (loadingProgressView != null) {
            loadingProgressView.startLoadingAnimation();
        }
    }

    public void hideLoadingProgressView() {
        LoadingProgressView loadingProgressView = this.mLoadingProgressView;
        if (loadingProgressView != null) {
            loadingProgressView.stopLoadingAnimation();
        }
    }

    public void stopAndReleaseWebView() {
        HtmlFiveWebView htmlFiveWebView = this.mWebView;
        if (htmlFiveWebView != null) {
            htmlFiveWebView.stopAndReleaseWebView();
        }
    }

    @Override
    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        int min = (int) (Math.min(i, i2) * LOADING_PROGRESS_DEFAULT_RATIO);
        LoadingProgressView loadingProgressView = this.mLoadingProgressView;
        if (loadingProgressView != null) {
            loadingProgressView.getLayoutParams().height = min;
            this.mLoadingProgressView.getLayoutParams().width = min;
            this.mLoadingProgressView.setCircleWidthRelativeToSize(min);
        }
    }

    public void setViewPagerItemClickListener(ItemViewPagerAdapter.ViewPagerItemClickListener viewPagerItemClickListener) {
        this.mViewPagerItemClickListener = viewPagerItemClickListener;
    }

    public void clearCache() {
        HtmlFiveWebView htmlFiveWebView = this.mWebView;
        if (htmlFiveWebView != null) {
            htmlFiveWebView.clearCache(true);
            this.mWebView.clearHistory();
        }
    }

    public String getLastOverloadUrl() {
        return this.mLastOverloadUrl;
    }

    @Override
    @JavascriptInterface
    public void onGetAdvertiserId(String str) {
        GetAdvertiserIdInterface getAdvertiserIdInterface = this.mGetAdvertiserIdInterface;
        if (getAdvertiserIdInterface != null) {
            getAdvertiserIdInterface.onGetAdvertiserId(str);
        }
    }

    @JavascriptInterface
    public String getParams() {
        Context context = getContext();
        Point screenSize = ScreenUtils.getScreenSize(context);
        KidozParams.ParamBuilder paramBuilder = new KidozParams.ParamBuilder();
        paramBuilder.setPublisherId(KidozSDK.getPublisherID()).setAuthToken(KidozSDK.getAuthToken()).setPackageId(KidozSDK.getAppId() != null ? KidozSDK.getAppId() : context.getPackageName()).setSdkVersion(ConstantDef.SDK_CONTENT_VERSION).setActualSdkVersion("8.9.9").setOsVersion(Build.VERSION.SDK_INT).setOsType(MetricCommonTags.METRIC_COMMON_TAG_PLATFORM_ANDROID).setExtensionType(ConstantDef.SDK_EXTENSION_TYPE).setAppVersionCode(Utils.getAppVersionCode(context)).setAppVersionName(Utils.getAppVersionName(context)).setDeviceType(Utils.getDeviceType(context)).setDeviceLang(Locale.getDefault().getLanguage()).setDeviceHash(Utils.getSessionId(context)).setManufacturer(Build.MANUFACTURER).setModel(Build.MODEL).setWebviewVersion(Utils.getWebViewVersion()).setScreenSize(ScreenUtils.getDeviceScreenSizeInInches(context)).setDpi(ScreenUtils.getScreenDpi(context)).setScreenCategory(ScreenUtils.getScreenCategory(context)).setWifiMode(Utils.getWifiOn(context)).setCarrierName(Utils.getCarrierName(context)).setNetworkType(Utils.getNetworkType(context)).setResolutionHeight(screenSize.y).setResolutionWidth(screenSize.x);
        paramBuilder.setWidgetType(this.mWidgetType).setCacheBuster(Utils.getCacheBuster());
        return paramBuilder.build().toString();
    }

    @Override
    @JavascriptInterface
    public void onViewReady() {
        this.mEventHandler.sendEmptyMessage(2);
    }

    @Override
    @JavascriptInterface
    public void onViewReady2() {
        this.mEventHandler.sendEmptyMessage(10);
    }

    @Override
    @JavascriptInterface
    public void simulateClick(String str, int i) {
        try {
            invokeOnSimulateClick(str, i);
        } catch (Exception e) {
            String localizedMessage = e.getLocalizedMessage();
            if (TextUtils.isEmpty(localizedMessage)) {
                return;
            }
            SDKLogger.printErrorLog(localizedMessage);
        }
    }

    @Override
    @JavascriptInterface
    public void onSendImpressionEvent(String str, String str2, String str3, String str4) {
        try {
            invokeOnImpressionServed(str, str2, str3, str4);
        } catch (Exception e) {
            if (TextUtils.isEmpty(e.getLocalizedMessage())) {
                return;
            }
            SDKLogger.printErrorLog("onSendImpressionEvent: " + e.getLocalizedMessage());
        }
    }

    @Override
    @JavascriptInterface
    public void onInvokeAboutClick() {
        invokeAboutClick();
    }

    @Override
    @JavascriptInterface
    public void onInvokeParentalClick() {
        invokeParentalClick();
    }

    @Override
    @JavascriptInterface
    public void onInvokeCloseClick() {
        this.mEventHandler.sendEmptyMessage(3);
    }

    @Override
    @JavascriptInterface
    public void toggleWidgetState(final boolean z) {
        this.mEventHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (HtmlViewWrapper.this.mHtmlWeViewListener != null) {
                    HtmlViewWrapper.this.mHtmlWeViewListener.toggleWidgetState(z);
                }
            }
        }, 0L);
    }

    @Override
    @JavascriptInterface
    public void onInvokeMaximize() {
        invokeMaximizedClick();
    }

    @Override
    @JavascriptInterface
    public void onInitWebViewWithProperties(String str) {
        try {
            invokeInitiateWebViewProperties(str);
        } catch (Exception e) {
            if (TextUtils.isEmpty(e.getLocalizedMessage())) {
                return;
            }
            SDKLogger.printErrorLog("onInitWebViewWithProperties error: " + e.getLocalizedMessage());
        }
    }

    @Override
    @JavascriptInterface
    public void onSendConversionEvent(String str, String str2, String str3, String str4, String str5, String str6) {
        try {
            onInvokeConversionServed(str, str2, str3, str4, str5, str6);
        } catch (Exception e) {
            Log.d(TAG, "HtmlViewWrapper | onStoreLocalParameter | error: " + e.getLocalizedMessage());
        }
    }

    @Override
    @JavascriptInterface
    public void onStoreLocalParameter(String str, String str2, String str3) {
        try {
            onRequestStoreLocalParam(str, str2, str3);
        } catch (Exception e) {
            Log.d(TAG, "HtmlViewWrapper | onStoreLocalParameter | error: " + e.getLocalizedMessage());
        }
    }

    @Override
    @JavascriptInterface
    public void getLocalParameter(String str, String str2) {
        try {
            onGetLocalParam(str, str2);
        } catch (Exception e) {
            Log.d(TAG, "HtmlViewWrapper | onStoreLocalParameter | error: " + e.getLocalizedMessage());
        }
    }

    @Override
    @JavascriptInterface
    public void onDone() {
        try {
            onGetDonePlayback();
        } catch (Exception e) {
            Log.d(TAG, "HtmlViewWrapper | onStoreLocalParameter | error: " + e.getLocalizedMessage());
        }
    }

    @Override
    @JavascriptInterface
    public void getParentalLockStatus(String str) {
        try {
            onGetParentalLockState(str);
        } catch (Exception e) {
            Log.d(TAG, "HtmlViewWrapper | onStoreLocalParameter | error: " + e.getLocalizedMessage());
        }
    }

    @Override
    @JavascriptInterface
    public void forwardToGooglePlay(String str, String str2, String str3, String str4, String str5, String str6) {
        if (this.blockClick) {
            return;
        }
        onForwardToGooglePlay(str, str2, str3, str4, str5, str6);
    }

    @Override
    @JavascriptInterface
    public void sendEvent(String str, String str2, String str3, String str4, String str5) {
        onInvokeSendEvent(str, str2, str3, str4, str5);
    }

    @Override
    @JavascriptInterface
    public void toggleLoadingState(String str) {
        try {
            onToggleLoadingState(Boolean.parseBoolean(str));
        } catch (Exception e) {
            SDKLogger.printErrorLog(TAG, "Error when trying to parse isLoading parameter: " + e.getMessage());
        }
    }

    @Override
    @JavascriptInterface
    public void notifyIsVastAdReady(boolean z, String str) {
        onNotifyIsVastAdReady(z, str);
    }

    @Override
    @JavascriptInterface
    public void notifyIsAdReady(boolean z, String str) {
        onNotifyAdReady(z, str);
    }

    @Override
    @JavascriptInterface
    public void notifyIsVastAdReady(boolean z) {
        onNotifyIsVastAdReady(z);
    }

    @Override
    @JavascriptInterface
    public void onRewarded() {
        Message obtain = Message.obtain();
        obtain.what = 6;
        this.mEventHandler.sendMessage(obtain);
    }

    @Override
    @JavascriptInterface
    public void onRewardedVideoStarted() {
        Message obtain = Message.obtain();
        obtain.what = 7;
        this.mEventHandler.sendMessage(obtain);
    }

    @Override
    @JavascriptInterface
    public void onAdStateChanged(int i) {
        Message obtain = Message.obtain();
        obtain.what = 8;
        obtain.arg1 = i;
        this.mEventHandler.sendMessage(obtain);
    }

    @Override
    @JavascriptInterface
    public void setDeviceOrientation(int i) {
        invokeSetDeviceOrientation(i);
    }

    @Override
    @JavascriptInterface
    public void setBlockClick(boolean z) {
        this.blockClick = z;
    }

    @Override
    @JavascriptInterface
    public void sendURLEvent(String str) {
        SdkAPIManager.getSdkApiInstance(this.mInFocusActivityContext.get()).callGetURL(this.mInFocusActivityContext.get(), str, null);
    }

    @Override
    @JavascriptInterface
    public void playVideo(final String str) {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                if (HtmlViewWrapper.this.mInFocusActivityContext == null || HtmlViewWrapper.this.mInFocusActivityContext.get() == null) {
                    return;
                }
                Intent intent = new Intent("android.intent.action.VIEW");
                intent.setDataAndType(Uri.parse(str), "video/mp4");
                HtmlViewWrapper.this.mInFocusActivityContext.get().startActivity(intent);
            }
        });
    }

    @JavascriptInterface
    public void resize(final float f, final float f2) {
        this.mExecutionHandler.post(new Runnable() {
            @Override
            public void run() {
                SDKLogger.printDebugLog("HtmlViewWrapper", "resize: w= " + f + ", h= " + f2);
                if (f == 0.0f || f2 == 0.0f) {
                    HtmlViewWrapper.this.mHtmlWeViewListener.onErrorReceived();
                    SDKLogger.printErrorLog(HtmlViewWrapper.TAG, "JS called resize with width = " + f + ", height = " + f2);
                    return;
                }
                ViewGroup.LayoutParams layoutParams = HtmlViewWrapper.this.getLayoutParams();
                layoutParams.width = (int) ScreenUtils.convertDpToPixel(f);
                layoutParams.height = (int) ScreenUtils.convertDpToPixel(f2);
                HtmlViewWrapper.this.setLayoutParams(layoutParams);
                HtmlViewWrapper.this.postInvalidate();
            }
        });
    }

    public void setAllowJSResize(boolean z) {
        this.mAllowJSResize = z;
    }
}