MyRecorder v1.01.90.0219版本的 MD5 值为:c361f51174a0bf833abfa72929caf8d3

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


package net.pubnative.lite.sdk.mraid;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.location.Location;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.ClientCertRequest;
import android.webkit.ConsoleMessage;
import android.webkit.HttpAuthHandler;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.PermissionRequest;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.facebook.internal.security.CertificateUtil;
import com.google.android.exoplayer2.C;
import com.google.api.client.googleapis.media.MediaHttpDownloader;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.sessions.settings.RemoteSettings;
import com.iab.omid.library.pubnativenet.adsession.FriendlyObstructionPurpose;
import com.smaato.sdk.core.injections.CoreModuleInterface;
import com.smaato.sdk.richmedia.mraid.bridge.MraidJsMethods;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.pubnative.lite.sdk.DeviceInfo;
import net.pubnative.lite.sdk.HyBid;
import net.pubnative.lite.sdk.core.R;
import net.pubnative.lite.sdk.location.HyBidLocationManager;
import net.pubnative.lite.sdk.mraid.MRAIDView;
import net.pubnative.lite.sdk.mraid.internal.MRAIDHtmlProcessor;
import net.pubnative.lite.sdk.mraid.internal.MRAIDLog;
import net.pubnative.lite.sdk.mraid.internal.MRAIDNativeFeatureManager;
import net.pubnative.lite.sdk.mraid.internal.MRAIDParser;
import net.pubnative.lite.sdk.mraid.properties.MRAIDOrientationProperties;
import net.pubnative.lite.sdk.mraid.properties.MRAIDResizeProperties;
import net.pubnative.lite.sdk.utils.Logger;
import net.pubnative.lite.sdk.viewability.HyBidViewabilityFriendlyObstruction;
import net.pubnative.lite.sdk.viewability.HyBidViewabilityWebAdSession;
import net.pubnative.lite.sdk.views.PNWebView;
import net.pubnative.lite.sdk.vpaid.helpers.BitmapHelper;
import net.pubnative.lite.sdk.vpaid.helpers.SimpleTimer;
import net.pubnative.lite.sdk.vpaid.widget.CountDownView;
import net.pubnative.lite.sdk.vpaid.widget.CountDownViewFactory;
import org.json.JSONException;
import org.json.JSONObject;
@SuppressLint({"ViewConstructor"})
public class MRAIDView extends FrameLayout {
    private static final int CLOSE_REGION_SIZE = 50;
    private static final String MRAID_VERSION = "3.0";
    public static final int STATE_DEFAULT = 1;
    public static final int STATE_EXPANDED = 2;
    public static final int STATE_HIDDEN = 4;
    public static final int STATE_LOADING = 0;
    public static final int STATE_RESIZED = 3;
    private int activityInitialOrientation;
    private Runnable backButtonClickabilityHandler;
    private final String baseUrl;
    private MRAIDViewCloseLayoutListener closeLayoutListener;
    private ImageButton closeRegion;
    private final ViewGroup contentInfo;
    private boolean contentInfoAdded;
    private int contentViewTop;
    private final Context context;
    private Rect currentPosition;
    private WebView currentWebView;
    private Rect defaultPosition;
    private final DisplayMetrics displayMetrics;
    private RelativeLayout expandedView;
    private final GestureDetector gestureDetector;
    public final Handler handler;
    private final int injections;
    private boolean isActionBarShowing;
    private Boolean isBackClickable;
    private boolean isClosing;
    private final boolean isExpandEnabled;
    private boolean isExpanded;
    private boolean isExpandingFromDefault;
    private boolean isExpandingPart2;
    private boolean isForceNotFullScreen;
    private boolean isForcingFullScreen;
    private boolean isFullScreen;
    private final boolean isInterstitial;
    public boolean isLaidOut;
    public boolean isPageFinished;
    public boolean isViewable;
    public final MRAIDViewListener listener;
    private Integer mBackButtonDelay;
    private SimpleTimer mExpirationTimer;
    private Integer mNativeCloseButtonDelay;
    private SimpleTimer mNativeCloseButtonTimer;
    private CountDownView mSkipCountdownView;
    private Integer mSkipTimeMillis;
    private final HyBidViewabilityWebAdSession mViewabilityAdSession;
    private final List<HyBidViewabilityFriendlyObstruction> mViewabilityFriendlyObstructions;
    private final Size maxSize;
    private String mraidJs;
    private final MRAIDWebChromeClient mraidWebChromeClient;
    private final MRAIDWebViewClient mraidWebViewClient;
    private final MRAIDNativeFeatureListener nativeFeatureListener;
    private final MRAIDNativeFeatureManager nativeFeatureManager;
    private final MRAIDOrientationProperties orientationProperties;
    private int origTitleBarVisibility;
    private final int originalRequestedOrientation;
    private final MRAIDResizeProperties resizeProperties;
    private RelativeLayout resizedView;
    private final Size screenSize;
    private Activity showActivity;
    private Boolean showTimerBeforeEndCard;
    public int state;
    private View titleBar;
    private boolean useCustomClose;
    private boolean wasTouched;
    public final WebView webView;
    private boolean webViewLoaded;
    private WebView webViewPart2;
    private static final String MRAID_LOG_TAG = MRAIDView.class.getSimpleName();
    private static final String[] COMMANDS_WITH_NO_PARAM = {"close", MraidJsMethods.RESIZE};
    private static final String[] COMMANDS_WITH_STRING = {"createCalendarEvent", MraidJsMethods.EXPAND, "open", MraidJsMethods.PLAY_VIDEO, MRAIDNativeFeature.STORE_PICTURE, MraidJsMethods.USE_CUSTOM_CLOSE};
    private static final String[] COMMANDS_WITH_MAP = {dj.j.SET_ORIENTATION_PROPERTIES, "setResizeProperties"};

    @Retention(RetentionPolicy.SOURCE)
    public @interface MRAIDState {
    }

    public class MRAIDWebChromeClient extends WebChromeClient {
        private MRAIDWebChromeClient() {
        }

        private boolean handlePopups(JsResult jsResult) {
            jsResult.cancel();
            return true;
        }

        @Override
        public void onCloseWindow(WebView webView) {
            MRAIDLog.d("hz-m MRAIDView ChromeClient - onCloseWindow");
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            String str;
            if (consoleMessage == null || consoleMessage.message() == null) {
                return false;
            }
            StringBuilder sb2 = new StringBuilder();
            sb2.append(consoleMessage.message());
            if (consoleMessage.sourceId() == null) {
                str = "";
            } else {
                str = " at " + consoleMessage.sourceId();
            }
            sb2.append(str);
            sb2.append(CertificateUtil.DELIMITER);
            sb2.append(consoleMessage.lineNumber());
            MRAIDLog.i("JS console", sb2.toString());
            return true;
        }

        @Override
        public void onExceededDatabaseQuota(String str, String str2, long j10, long j11, long j12, WebStorage.QuotaUpdater quotaUpdater) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onExceededDatabaseQuota");
            quotaUpdater.updateQuota(j10);
        }

        @Override
        public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
            MRAIDLog.d("JS alert", str2);
            return handlePopups(jsResult);
        }

        @Override
        public boolean onJsBeforeUnload(WebView webView, String str, String str2, JsResult jsResult) {
            MRAIDLog.d("hz-m MRAIDView ChromeClient - onJsBeforeUnload");
            return true;
        }

        @Override
        public boolean onJsConfirm(WebView webView, String str, String str2, JsResult jsResult) {
            MRAIDLog.d("JS confirm", str2);
            return handlePopups(jsResult);
        }

        @Override
        public boolean onJsPrompt(WebView webView, String str, String str2, String str3, JsPromptResult jsPromptResult) {
            MRAIDLog.d("JS prompt", str2);
            return handlePopups(jsPromptResult);
        }

        @Override
        public boolean onJsTimeout() {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onJsTimeout");
            return true;
        }

        @Override
        public void onPermissionRequest(PermissionRequest permissionRequest) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onPermissionRequest");
        }

        @Override
        public void onProgressChanged(WebView webView, int i10) {
            MRAIDLog.d("hz-m MRAIDView ChromeClient - onProgressChanged " + i10 + " wv: " + MRAIDView.this.webView + " view: " + MRAIDView.this);
        }

        @Override
        public void onReachedMaxAppCacheSize(long j10, long j11, WebStorage.QuotaUpdater quotaUpdater) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReachedMaxAppCacheSize");
            quotaUpdater.updateQuota(j11);
        }

        @Override
        public void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
            MRAIDLog.d("hz-m MRAIDView ChromeClient - showCustomView");
        }
    }

    public class MRAIDWebViewClient extends WebViewClient {
        private MRAIDWebViewClient() {
        }

        public void lambda$onPageFinished$1() {
            MRAIDView mRAIDView = MRAIDView.this;
            StringBuilder sb2 = new StringBuilder();
            sb2.append("mraid.setPlacementType('");
            sb2.append(MRAIDView.this.isInterstitial ? "interstitial" : "inline");
            sb2.append("');");
            mRAIDView.injectJavaScript(sb2.toString());
            MRAIDView.this.setSupportedServices();
            MRAIDView.this.setEnvironmentVariables();
            MRAIDView.this.setLocation();
            MRAIDView.this.setScreenSize();
            MRAIDView.this.setDefaultPosition();
            MRAIDLog.d(MRAIDView.MRAID_LOG_TAG, "calling fireStateChangeEvent 2");
            MRAIDView.this.fireStateChangeEvent();
            MRAIDView.this.fireReadyEvent();
            MRAIDView mRAIDView2 = MRAIDView.this;
            if (mRAIDView2.isViewable) {
                mRAIDView2.fireViewableChangeEvent();
            }
            MRAIDView.this.fireExposureChangeEvent();
        }

        public void lambda$shouldInterceptRequest$2() {
            MRAIDView.injectJavaScript(MRAIDView.this.webView, "mraid.logLevel = mraid.LogLevelEnum.DEBUG;");
        }

        @Override
        public void onPageCommitVisible(WebView webView, String str) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onPageCommitVisibile");
        }

        @Override
        public void onPageFinished(WebView webView, String str) {
            super.onPageFinished(webView, str);
            String str2 = MRAIDView.MRAID_LOG_TAG;
            MRAIDLog.d(str2, "onPageFinished: " + str);
            MRAIDView mRAIDView = MRAIDView.this;
            if (mRAIDView.state == 0) {
                mRAIDView.isPageFinished = true;
                if (mRAIDView.isExpandEnabled) {
                    MRAIDView mRAIDView2 = MRAIDView.this;
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append("mraid.setPlacementType('");
                    sb2.append(MRAIDView.this.isInterstitial ? "interstitial" : "inline");
                    sb2.append("');");
                    mRAIDView2.injectJavaScript(sb2.toString());
                } else {
                    MRAIDView mRAIDView3 = MRAIDView.this;
                    StringBuilder sb3 = new StringBuilder();
                    sb3.append("mraid.setPlacementType('");
                    sb3.append(MRAIDView.this.isInterstitial ? "interstitial" : "");
                    sb3.append("');");
                    mRAIDView3.injectJavaScript(sb3.toString());
                }
                MRAIDView.this.setEnvironmentVariables();
                MRAIDView.this.setSupportedServices();
                MRAIDView.this.setLocation();
                MRAIDView mRAIDView4 = MRAIDView.this;
                if (mRAIDView4.isLaidOut) {
                    mRAIDView4.setScreenSize();
                    MRAIDView.this.setMaxSize();
                    MRAIDView.this.setCurrentPosition();
                    MRAIDView.this.setDefaultPosition();
                    if (MRAIDView.this.isInterstitial) {
                        MRAIDView mRAIDView5 = MRAIDView.this;
                        mRAIDView5.showAsInterstitial(mRAIDView5.showActivity, Boolean.FALSE, null);
                    } else {
                        MRAIDView mRAIDView6 = MRAIDView.this;
                        mRAIDView6.state = 1;
                        mRAIDView6.fireStateChangeEvent();
                        MRAIDView.this.fireReadyEvent();
                        MRAIDView mRAIDView7 = MRAIDView.this;
                        if (mRAIDView7.isViewable) {
                            mRAIDView7.fireViewableChangeEvent();
                        }
                    }
                }
                if (!MRAIDView.this.isInterstitial) {
                    MRAIDView mRAIDView8 = MRAIDView.this;
                    mRAIDView8.addContentInfo(mRAIDView8);
                }
                MRAIDView mRAIDView9 = MRAIDView.this;
                if (mRAIDView9.listener != null && !mRAIDView9.webViewLoaded) {
                    MRAIDView.this.mViewabilityAdSession.initAdSession(webView, false);
                    if (MRAIDView.this.contentInfo != null && MRAIDView.this.contentInfoAdded) {
                        MRAIDView mRAIDView10 = MRAIDView.this;
                        mRAIDView10.addViewabilityFriendlyObstruction(mRAIDView10.contentInfo, FriendlyObstructionPurpose.OTHER, "Content info description for the ad");
                        for (HyBidViewabilityFriendlyObstruction hyBidViewabilityFriendlyObstruction : MRAIDView.this.mViewabilityFriendlyObstructions) {
                            MRAIDView.this.mViewabilityAdSession.addFriendlyObstruction(hyBidViewabilityFriendlyObstruction.getView(), hyBidViewabilityFriendlyObstruction.getPurpose(), hyBidViewabilityFriendlyObstruction.getReason());
                        }
                    }
                    MRAIDView.this.webViewLoaded = true;
                    MRAIDView.this.mViewabilityAdSession.fireLoaded();
                    MRAIDView.this.mViewabilityAdSession.fireImpression();
                    MRAIDView mRAIDView11 = MRAIDView.this;
                    mRAIDView11.listener.mraidViewLoaded(mRAIDView11);
                    MRAIDView.this.mSkipCountdownView = new CountDownViewFactory().createCountdownView(MRAIDView.this.context, HyBid.getCountdownStyle(), MRAIDView.this);
                    MRAIDView mRAIDView12 = MRAIDView.this;
                    mRAIDView12.addView(mRAIDView12.mSkipCountdownView);
                    MRAIDView.this.mSkipCountdownView.setVisibility(8);
                    final MRAIDView mRAIDView13 = MRAIDView.this;
                    mRAIDView13.postDelayed(new Runnable() {
                        @Override
                        public final void run() {
                            MRAIDView.access$3700(MRAIDView.this);
                        }
                    }, 500L);
                }
            }
            if (MRAIDView.this.isExpandingPart2) {
                MRAIDView.this.isExpandingPart2 = false;
                MRAIDView.this.handler.post(new Runnable() {
                    @Override
                    public final void run() {
                        MRAIDView.MRAIDWebViewClient.this.lambda$onPageFinished$1();
                    }
                });
            }
        }

        @Override
        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onPageStarted");
        }

        @Override
        public void onReceivedClientCertRequest(WebView webView, ClientCertRequest clientCertRequest) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedClientCertRequest");
        }

        @Override
        public void onReceivedError(WebView webView, int i10, String str, String str2) {
            String str3 = MRAIDView.MRAID_LOG_TAG;
            MRAIDLog.d(str3, "onReceivedError: " + str);
            super.onReceivedError(webView, i10, str, str2);
        }

        @Override
        public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
            if (Build.VERSION.SDK_INT < 23) {
                MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedError: " + webResourceError);
                return;
            }
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedError code: " + webResourceError.getErrorCode());
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedError: " + ((Object) webResourceError.getDescription()));
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView webView, HttpAuthHandler httpAuthHandler, String str, String str2) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedHttpAuthRequest");
            httpAuthHandler.cancel();
        }

        @Override
        public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedHttpError");
        }

        @Override
        public void onReceivedLoginRequest(WebView webView, String str, String str2, String str3) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedLoginRequest");
        }

        @Override
        public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedSslError");
            if (sslErrorHandler != null) {
                sslErrorHandler.cancel();
            }
        }

        @Override
        public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail renderProcessGoneDetail) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onRenderProcessGone");
            MRAIDView mRAIDView = MRAIDView.this;
            MRAIDViewListener mRAIDViewListener = mRAIDView.listener;
            if (mRAIDViewListener != null) {
                mRAIDViewListener.mraidViewError(mRAIDView);
                return true;
            }
            return true;
        }

        @Override
        public void onScaleChanged(WebView webView, float f10, float f11) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onScaleChanged");
        }

        @Override
        public void onTooManyRedirects(WebView webView, Message message, Message message2) {
            message.sendToTarget();
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onTooManyRedirects");
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView webView, String str) {
            MRAIDLog.d("hz-m shouldInterceptRequest - " + str);
            if (str.contains("mraid.js")) {
                MRAIDLog.d("hz-m shouldInterceptRequest - intercepting mraid - " + str);
                MRAIDView.this.handler.post(new Runnable() {
                    @Override
                    public final void run() {
                        MRAIDView.MRAIDWebViewClient.this.lambda$shouldInterceptRequest$2();
                    }
                });
                return new WebResourceResponse("application/javascript", C.UTF8_NAME, MRAIDView.this.getMraidJsStream());
            }
            return null;
        }

        @Override
        public boolean shouldOverrideKeyEvent(WebView webView, KeyEvent keyEvent) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - shouldOverrideKeyEvent");
            return false;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            String str2 = MRAIDView.MRAID_LOG_TAG;
            MRAIDLog.d(str2, "shouldOverrideUrlLoading: " + str);
            if (str.startsWith("mraid://")) {
                MRAIDView.this.parseCommandUrl(str);
            } else if (MRAIDView.this.isVerveCustomExpand(str)) {
                MRAIDView.this.expandCreative(str, true, Boolean.FALSE, null);
            } else if (MRAIDView.this.isCloseSignal(str)) {
                MRAIDView.this.closeOnMainThread();
            } else {
                try {
                    MRAIDView.this.open(URLEncoder.encode(str, C.UTF8_NAME));
                } catch (UnsupportedEncodingException e10) {
                    e10.printStackTrace();
                }
            }
            return true;
        }
    }

    public interface OnExpandCreativeFailListener {
        void onExpandFailed();
    }

    public static class Size {
        public int height;
        public int width;

        private Size() {
        }
    }

    public MRAIDView(Context context, String str, String str2, Boolean bool, String[] strArr, MRAIDViewListener mRAIDViewListener, MRAIDNativeFeatureListener mRAIDNativeFeatureListener, ViewGroup viewGroup, boolean z7, boolean z9) {
        super(context);
        Boolean bool2 = Boolean.FALSE;
        this.showTimerBeforeEndCard = bool2;
        this.mSkipTimeMillis = -1;
        this.mNativeCloseButtonDelay = -1;
        this.mBackButtonDelay = -1;
        this.isBackClickable = bool2;
        this.backButtonClickabilityHandler = null;
        this.activityInitialOrientation = -1;
        this.wasTouched = false;
        this.contentInfoAdded = false;
        this.webViewLoaded = false;
        this.injections = 0;
        this.context = context;
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            this.showActivity = activity;
            this.activityInitialOrientation = activity.getRequestedOrientation();
        }
        String str3 = str == null ? "http://example.com/" : str;
        this.baseUrl = str3;
        this.isInterstitial = z7;
        this.isExpandEnabled = z9;
        this.contentInfo = viewGroup;
        this.state = 0;
        this.isViewable = false;
        this.useCustomClose = false;
        this.orientationProperties = new MRAIDOrientationProperties();
        this.resizeProperties = new MRAIDResizeProperties();
        this.nativeFeatureManager = new MRAIDNativeFeatureManager(context, new ArrayList(Arrays.asList(strArr)));
        this.listener = mRAIDViewListener;
        this.nativeFeatureListener = mRAIDNativeFeatureListener;
        this.showTimerBeforeEndCard = bool;
        WindowManager windowManager = (WindowManager) context.getSystemService("window");
        if (windowManager != null) {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            this.displayMetrics = displayMetrics;
            windowManager.getDefaultDisplay().getMetrics(displayMetrics);
        } else {
            this.displayMetrics = null;
        }
        this.currentPosition = new Rect();
        this.defaultPosition = new Rect();
        this.maxSize = new Size();
        this.screenSize = new Size();
        if (context instanceof Activity) {
            this.originalRequestedOrientation = ((Activity) context).getRequestedOrientation();
        } else {
            this.originalRequestedOrientation = -1;
        }
        String str4 = MRAID_LOG_TAG;
        MRAIDLog.d(str4, "originalRequestedOrientation " + getOrientationString(this.originalRequestedOrientation));
        this.gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float f10, float f11) {
                return true;
            }
        });
        this.handler = new Handler(Looper.getMainLooper());
        this.mViewabilityAdSession = new HyBidViewabilityWebAdSession(HyBid.getViewabilityManager());
        this.mViewabilityFriendlyObstructions = new ArrayList();
        this.mraidWebChromeClient = new MRAIDWebChromeClient();
        this.mraidWebViewClient = new MRAIDWebViewClient();
        WebView createWebView = createWebView();
        this.webView = createWebView;
        if (createWebView == null) {
            if (mRAIDViewListener != null) {
                mRAIDViewListener.mraidViewError(this);
                return;
            }
            return;
        }
        createWebView.setId(R.id.mraid_ad_view);
        this.currentWebView = createWebView;
        if (TextUtils.isEmpty(str2)) {
            MRAIDLog.d("hz-m loading mraid from url: " + str);
            createWebView.loadUrl(str);
            return;
        }
        try {
            String processRawHtml = MRAIDHtmlProcessor.processRawHtml(str2);
            MRAIDLog.d("hz-m loading mraid " + processRawHtml);
            createWebView.loadDataWithBaseURL(str3, processRawHtml, "text/html", C.UTF8_NAME, null);
        } catch (Throwable th2) {
            HyBid.reportException(th2);
            this.listener.mraidViewError(this);
        }
    }

    public static void access$3700(MRAIDView mRAIDView) {
        mRAIDView.startSkipTimer();
    }

    private void addCloseRegion(View view) {
        ImageButton imageButton = new ImageButton(this.context);
        this.closeRegion = imageButton;
        imageButton.setId(R.id.close_view);
        this.closeRegion.setBackgroundColor(0);
        this.closeRegion.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                MRAIDView.this.lambda$addCloseRegion$5(view2);
            }
        });
        if (view == this.expandedView && !this.useCustomClose) {
            showDefaultCloseButton();
        }
        ((ViewGroup) view).addView(this.closeRegion);
    }

    public void addContentInfo(View view) {
        ViewGroup viewGroup = this.contentInfo;
        if (viewGroup == null || this.contentInfoAdded) {
            return;
        }
        ((ViewGroup) view).addView(viewGroup);
        this.contentInfoAdded = true;
    }

    private void calculateMaxSize() {
        if (this.context instanceof Activity) {
            Rect rect = new Rect();
            Window window = ((Activity) this.context).getWindow();
            window.getDecorView().getWindowVisibleDisplayFrame(rect);
            String str = MRAID_LOG_TAG;
            MRAIDLog.d(str, "calculateMaxSize frame [" + rect.left + "," + rect.top + "][" + rect.right + "," + rect.bottom + "] (" + rect.width() + "x" + rect.height() + ")");
            if (window.findViewById(16908290) != null) {
                this.contentViewTop = window.findViewById(16908290).getTop();
            } else {
                this.contentViewTop = rect.top;
            }
            int i10 = rect.top;
            int i11 = this.contentViewTop - i10;
            MRAIDLog.d(str, "calculateMaxSize statusHeight " + i10);
            MRAIDLog.d(str, "calculateMaxSize titleHeight " + i11);
            MRAIDLog.d(str, "calculateMaxSize contentViewTop " + this.contentViewTop);
            int width = rect.width();
            int i12 = this.screenSize.height - this.contentViewTop;
            MRAIDLog.d(str, "calculateMaxSize max size " + width + "x" + i12);
            Size size = this.maxSize;
            if (width == size.width && i12 == size.height) {
                return;
            }
            size.width = width;
            size.height = i12;
            if (this.isPageFinished) {
                setMaxSize();
            }
        }
    }

    private void calculatePosition(boolean z7) {
        View view = z7 ? this.currentWebView : this;
        String str = z7 ? "current" : CoreModuleInterface.NAME_DEFAULT_HTTP_HANDLER;
        int[] iArr = new int[2];
        view.getLocationOnScreen(iArr);
        int i10 = iArr[0];
        int i11 = iArr[1];
        String str2 = MRAID_LOG_TAG;
        MRAIDLog.d(str2, "calculatePosition " + str + " locationOnScreen [" + i10 + "," + i11 + "]");
        StringBuilder sb2 = new StringBuilder();
        sb2.append("calculatePosition ");
        sb2.append(str);
        sb2.append(" contentViewTop ");
        sb2.append(this.contentViewTop);
        MRAIDLog.d(str2, sb2.toString());
        int i12 = i11 - this.contentViewTop;
        int width = view.getWidth();
        int height = view.getHeight();
        MRAIDLog.d(str2, "calculatePosition " + str + " position [" + i10 + "," + i12 + "] (" + width + "x" + height + ")");
        Rect rect = z7 ? this.currentPosition : this.defaultPosition;
        if (i10 == rect.left && i12 == rect.top && width == rect.width() && height == rect.height()) {
            return;
        }
        if (z7) {
            this.currentPosition = new Rect(i10, i12, width + i10, height + i12);
        } else {
            this.defaultPosition = new Rect(i10, i12, width + i10, height + i12);
        }
        if (this.isPageFinished) {
            if (z7) {
                setCurrentPosition();
            } else {
                setDefaultPosition();
            }
        }
    }

    private void calculateScreenSize() {
        boolean z7 = getResources().getConfiguration().orientation == 1;
        String str = MRAID_LOG_TAG;
        StringBuilder sb2 = new StringBuilder();
        sb2.append("calculateScreenSize orientation ");
        sb2.append(z7 ? "portrait" : "landscape");
        MRAIDLog.d(str, sb2.toString());
        DisplayMetrics displayMetrics = this.displayMetrics;
        if (displayMetrics != null) {
            int i10 = displayMetrics.widthPixels;
            int i11 = displayMetrics.heightPixels;
            MRAIDLog.d(str, "calculateScreenSize screen size " + i10 + "x" + i11);
            Size size = this.screenSize;
            if (i10 == size.width && i11 == size.height) {
                return;
            }
            size.width = i10;
            size.height = i11;
            if (this.isPageFinished) {
                setScreenSize();
            }
        }
    }

    public void closeOnMainThread() {
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public final void run() {
                MRAIDView.this.close();
            }
        });
    }

    @JavascriptMRAIDCallback
    private void createCalendarEvent(String str) {
        MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", "createCalendarEvent " + str);
        MRAIDNativeFeatureListener mRAIDNativeFeatureListener = this.nativeFeatureListener;
        if (mRAIDNativeFeatureListener != null) {
            mRAIDNativeFeatureListener.mraidNativeFeatureCreateCalendarEvent(str);
        }
    }

    @SuppressLint({"SetJavaScriptEnabled"})
    public WebView createWebView() {
        try {
            PNWebView pNWebView = new PNWebView(this.context) {
                private static final String TAG = "MRAIDView-WebView";

                @Override
                public void onConfigurationChanged(Configuration configuration) {
                    super.onConfigurationChanged(configuration);
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append("onConfigurationChanged ");
                    sb2.append(configuration.orientation == 1 ? "portrait" : "landscape");
                    MRAIDLog.d(TAG, sb2.toString());
                    if (MRAIDView.this.isInterstitial) {
                        if (Build.VERSION.SDK_INT >= 30) {
                            MRAIDView.this.context.getDisplay().getMetrics(MRAIDView.this.displayMetrics);
                            return;
                        }
                        WindowManager windowManager = (WindowManager) MRAIDView.this.context.getSystemService("window");
                        if (windowManager != null) {
                            windowManager.getDefaultDisplay().getMetrics(MRAIDView.this.displayMetrics);
                        }
                    }
                }

                @Override
                public void onLayout(boolean z7, int i10, int i11, int i12, int i13) {
                    super.onLayout(z7, i10, i11, i12, i13);
                    MRAIDView.this.onLayoutWebView(this, z7, i10, i11, i12, i13);
                }

                @Override
                public void onVisibilityChanged(View view, int i10) {
                    super.onVisibilityChanged(view, i10);
                    MRAIDLog.d(TAG, "onVisibilityChanged " + MRAIDView.getVisibilityString(i10));
                    if (MRAIDView.this.isInterstitial) {
                        MRAIDView.this.setViewable(i10);
                    }
                }

                @Override
                public void onWindowVisibilityChanged(int i10) {
                    super.onWindowVisibilityChanged(i10);
                    int visibility = getVisibility();
                    MRAIDLog.d(TAG, "onWindowVisibilityChanged " + MRAIDView.getVisibilityString(i10) + " (actual " + MRAIDView.getVisibilityString(visibility) + ')');
                    if (MRAIDView.this.isInterstitial) {
                        MRAIDView.this.setViewable(visibility);
                    }
                }

                @Override
                public boolean performClick() {
                    return super.performClick();
                }
            };
            pNWebView.setScrollContainer(false);
            pNWebView.setVerticalScrollBarEnabled(false);
            pNWebView.setHorizontalScrollBarEnabled(false);
            pNWebView.setScrollBarStyle(MediaHttpDownloader.MAXIMUM_CHUNK_SIZE);
            pNWebView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                @SuppressLint({"ClickableViewAccessibility"})
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    MRAIDView.this.wasTouched = true;
                    int action = motionEvent.getAction();
                    if ((action == 0 || action == 1) && !view.hasFocus()) {
                        view.requestFocus();
                        return false;
                    }
                    return false;
                }
            });
            pNWebView.getSettings().setJavaScriptEnabled(true);
            pNWebView.getSettings().setDomStorageEnabled(true);
            pNWebView.getSettings().setAllowContentAccess(false);
            pNWebView.enablePlugins(true);
            pNWebView.getSettings().setSupportZoom(false);
            pNWebView.setWebChromeClient(this.mraidWebChromeClient);
            pNWebView.setWebViewClient(this.mraidWebViewClient);
            pNWebView.setLayerType(2, null);
            pNWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
            return pNWebView;
        } catch (RuntimeException e10) {
            HyBid.reportException((Exception) e10);
            return null;
        }
    }

    private void decodeURL(String str, final boolean z7) {
        try {
            final String decode = URLDecoder.decode(str, C.UTF8_NAME);
            if (!decode.startsWith("http://") && !decode.startsWith("https://")) {
                decode = this.baseUrl + decode;
            }
            new Thread(new Runnable() {
                @Override
                public final void run() {
                    MRAIDView.this.lambda$decodeURL$1(z7, decode);
                }
            }, "2-part-content").start();
        } catch (UnsupportedEncodingException e10) {
            HyBid.reportException((Exception) e10);
            MRAIDLog.d("hz-m MRAIDView - expand - UnsupportedEncodingException " + e10);
        }
    }

    private void expandCreative(String str, boolean z7, Boolean bool) {
        expandCreative(str, z7, bool, null);
    }

    public void expandCreative(String str, boolean z7, Boolean bool, OnExpandCreativeFailListener onExpandCreativeFailListener) {
        MRAIDLog.d("hz-m MRAIDView - expand " + str);
        StringBuilder sb2 = new StringBuilder();
        String str2 = MRAID_LOG_TAG;
        sb2.append(str2);
        sb2.append("-JS callback");
        String sb3 = sb2.toString();
        StringBuilder sb4 = new StringBuilder();
        sb4.append("expand ");
        sb4.append(str != null ? str : "(1-part)");
        MRAIDLog.d(sb3, sb4.toString());
        MRAIDOrientationProperties mRAIDOrientationProperties = this.orientationProperties;
        if (mRAIDOrientationProperties != null) {
            mRAIDOrientationProperties.allowOrientationChange = false;
            applyOrientationProperties();
        }
        if (!HyBid.isMraidExpandEnabled() && !bool.booleanValue()) {
            MRAIDLog.d(str2 + "-JS callback", "expand disabled by the developer");
        } else if (!TextUtils.isEmpty(str)) {
            decodeURL(str, z7);
        } else {
            int i10 = this.state;
            if (i10 == 0 || i10 == 1) {
                if (this.webView.getParent() != null) {
                    ((ViewGroup) this.webView.getParent()).removeView(this.webView);
                } else {
                    removeView(this.webView);
                }
            } else if (i10 == 3) {
                removeResizeView();
            }
            expandHelper(this.webView);
            MRAIDLog.d("hz-m MRAIDView - expand - empty url");
            if (onExpandCreativeFailListener != null) {
                onExpandCreativeFailListener.onExpandFailed();
            }
        }
    }

    @TargetApi(11)
    private void forceFullScreen() {
        if (this.context instanceof Activity) {
            MRAIDLog.d(MRAID_LOG_TAG, "forceFullScreen");
            Activity activity = (Activity) this.context;
            int i10 = activity.getWindow().getAttributes().flags;
            boolean z7 = false;
            this.isFullScreen = (i10 & 1024) != 0;
            this.isForceNotFullScreen = (i10 & 2048) != 0;
            this.origTitleBarVisibility = -9;
            ActionBar actionBar = activity.getActionBar();
            if (actionBar != null) {
                this.isActionBarShowing = actionBar.isShowing();
                actionBar.hide();
                z7 = true;
            }
            if (!z7) {
                this.titleBar = null;
                try {
                    if (activity.findViewById(16908310) != null) {
                        this.titleBar = (View) activity.findViewById(16908310).getParent();
                    }
                } catch (NullPointerException e10) {
                    HyBid.reportException((Exception) e10);
                }
                View view = this.titleBar;
                if (view != null) {
                    this.origTitleBarVisibility = view.getVisibility();
                    this.titleBar.setVisibility(8);
                }
            }
            String str = MRAID_LOG_TAG;
            MRAIDLog.d(str, "isFullScreen " + this.isFullScreen);
            MRAIDLog.d(str, "isForceNotFullScreen " + this.isForceNotFullScreen);
            MRAIDLog.d(str, "isActionBarShowing " + this.isActionBarShowing);
            MRAIDLog.d(str, "origTitleBarVisibility " + getVisibilityString(this.origTitleBarVisibility));
            ((Activity) this.context).getWindow().addFlags(1024);
            ((Activity) this.context).getWindow().clearFlags(2048);
            this.isForcingFullScreen = this.isFullScreen ^ true;
        }
    }

    public InputStream getMraidJsStream() {
        if (TextUtils.isEmpty(this.mraidJs)) {
            this.mraidJs = new String(Base64.decode(Assets.mraidJS, 0));
        }
        return new ByteArrayInputStream(this.mraidJs.getBytes(StandardCharsets.UTF_8));
    }

    private static String getOrientationString(int i10) {
        return i10 != -1 ? i10 != 0 ? i10 != 1 ? "UNKNOWN" : "PORTRAIT" : "LANDSCAPE" : "UNSPECIFIED";
    }

    private String getStringFromFileUrl(String str) {
        StringBuilder sb2 = new StringBuilder();
        String[] split = str.split(RemoteSettings.FORWARD_SLASH_STRING);
        if (!split[3].equals("android_asset")) {
            MRAIDLog.e("Unknown location to fetch file content");
            return "";
        }
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(this.context.getAssets().open(split[4])));
            String readLine = bufferedReader.readLine();
            sb2.append(readLine);
            while (readLine != null) {
                readLine = bufferedReader.readLine();
                sb2.append(readLine);
            }
            bufferedReader.close();
        } catch (IOException e10) {
            MRAIDLog.e("Error fetching file: " + e10.getMessage());
            HyBid.reportException((Exception) e10);
        }
        return sb2.toString();
    }

    private String getStringFromUrl(String str) {
        String str2;
        HttpURLConnection httpURLConnection;
        if (str.startsWith("file:///")) {
            return getStringFromFileUrl(str);
        }
        InputStream inputStream = null;
        String str3 = null;
        inputStream = null;
        inputStream = null;
        try {
        } catch (IOException e10) {
            HyBid.reportException((Exception) e10);
        }
        try {
            try {
                httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
                int responseCode = httpURLConnection.getResponseCode();
                String str4 = MRAID_LOG_TAG;
                MRAIDLog.d(str4, "response code " + responseCode);
                if (responseCode == 200) {
                    MRAIDLog.d(str4, "getContentLength " + httpURLConnection.getContentLength());
                    InputStream inputStream2 = httpURLConnection.getInputStream();
                    try {
                        byte[] bArr = new byte[1500];
                        StringBuilder sb2 = new StringBuilder();
                        while (true) {
                            int read = inputStream2.read(bArr);
                            if (read == -1) {
                                break;
                            }
                            sb2.append(new String(bArr, 0, read));
                        }
                        str3 = sb2.toString();
                        MRAIDLog.d(MRAID_LOG_TAG, "getStringFromUrl ok, length=" + str3.length());
                        str2 = str3;
                        inputStream = inputStream2;
                    } catch (IOException e11) {
                        e = e11;
                        str2 = str3;
                        inputStream = inputStream2;
                        HyBid.reportException((Exception) e);
                        MRAIDLog.e(MRAID_LOG_TAG, "getStringFromUrl failed " + e.getLocalizedMessage());
                        if (inputStream != null) {
                        }
                        return str2;
                    } catch (Throwable th2) {
                        th = th2;
                        inputStream = inputStream2;
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e12) {
                                HyBid.reportException((Exception) e12);
                            }
                        }
                        throw th;
                    }
                } else {
                    str2 = null;
                }
            } catch (IOException e13) {
                e = e13;
                str2 = null;
            }
            try {
                httpURLConnection.disconnect();
            } catch (IOException e14) {
                e = e14;
                HyBid.reportException((Exception) e);
                MRAIDLog.e(MRAID_LOG_TAG, "getStringFromUrl failed " + e.getLocalizedMessage());
                if (inputStream != null) {
                    inputStream.close();
                }
                return str2;
            }
            if (inputStream != null) {
                inputStream.close();
            }
            return str2;
        } catch (Throwable th3) {
            th = th3;
        }
    }

    public static String getVisibilityString(int i10) {
        return i10 != 0 ? i10 != 4 ? i10 != 8 ? "UNKNOWN" : "GONE" : "INVISIBLE" : "VISIBLE";
    }

    public static void injectJavaScript(WebView webView, String str) {
        if (webView == null || TextUtils.isEmpty(str)) {
            return;
        }
        String str2 = MRAID_LOG_TAG;
        MRAIDLog.d(str2, "evaluating js: " + str);
        webView.evaluateJavascript(str, new ValueCallback() {
            @Override
            public final void onReceiveValue(Object obj) {
                MRAIDView.lambda$injectJavaScript$6((String) obj);
            }
        });
    }

    private void injectMraidJs(WebView webView) {
        if (TextUtils.isEmpty(this.mraidJs)) {
            this.mraidJs = new String(Base64.decode(Assets.mraidJS, 0));
        }
        injectJavaScript(this.mraidJs);
    }

    public boolean isCloseSignal(String str) {
        Uri parse;
        List<String> pathSegments;
        if (!str.contains("https://feedback.verve.com") || (parse = Uri.parse(str)) == null || (pathSegments = parse.getPathSegments()) == null || pathSegments.isEmpty()) {
            return false;
        }
        return parse.getPathSegments().contains("close");
    }

    public boolean isVerveCustomExpand(String str) {
        return !TextUtils.isEmpty(str) && str.contains("tags-prod.vrvm.com") && str.contains("type=expandable");
    }

    public void lambda$addCloseRegion$5(View view) {
        close();
    }

    public void lambda$close$0() {
        int i10 = this.state;
        if (i10 != 1 && i10 != 2) {
            if (i10 == 3) {
                closeFromResized();
                return;
            }
            return;
        }
        MRAIDViewCloseLayoutListener mRAIDViewCloseLayoutListener = this.closeLayoutListener;
        if (mRAIDViewCloseLayoutListener != null) {
            mRAIDViewCloseLayoutListener.onClose();
        } else {
            closeFromExpanded();
        }
    }

    public void lambda$closeFromExpanded$2() {
        restoreOriginalOrientation();
        restoreOriginalScreenState();
    }

    public void lambda$closeFromExpanded$3() {
        fireStateChangeEvent();
        MRAIDViewListener mRAIDViewListener = this.listener;
        if (mRAIDViewListener != null) {
            mRAIDViewListener.mraidViewClose(this);
        }
    }

    public void lambda$closeFromResized$4() {
        fireStateChangeEvent();
        MRAIDViewListener mRAIDViewListener = this.listener;
        if (mRAIDViewListener != null) {
            mRAIDViewListener.mraidViewClose(this);
        }
    }

    public void lambda$decodeURL$1(boolean z7, final String str) {
        MRAIDLog.d("hz-m MRAIDView - expand - url loading thread");
        if (z7) {
            Context context = this.context;
            if (context instanceof Activity) {
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        MRAIDView mRAIDView = MRAIDView.this;
                        if (mRAIDView.state == 3) {
                            mRAIDView.removeResizeView();
                            MRAIDView mRAIDView2 = MRAIDView.this;
                            mRAIDView2.addView(mRAIDView2.webView);
                        }
                        MRAIDView.this.webView.setWebChromeClient(null);
                        MRAIDView.this.webView.setWebViewClient(null);
                        MRAIDView mRAIDView3 = MRAIDView.this;
                        mRAIDView3.webViewPart2 = mRAIDView3.createWebView();
                        MRAIDView.this.webViewPart2.loadUrl(str);
                        MRAIDLog.d("hz-m MRAIDView - expand - switching out currentwebview for " + MRAIDView.this.webViewPart2);
                        MRAIDView mRAIDView4 = MRAIDView.this;
                        mRAIDView4.currentWebView = mRAIDView4.webViewPart2;
                        MRAIDView.this.isExpandingPart2 = true;
                        MRAIDView mRAIDView5 = MRAIDView.this;
                        mRAIDView5.expandHelper(mRAIDView5.currentWebView);
                    }
                });
                return;
            }
            MRAIDLog.e("Could not load part 2 expanded content for URL: " + str);
            return;
        }
        final String stringFromUrl = getStringFromUrl(str);
        if (!TextUtils.isEmpty(stringFromUrl)) {
            Context context2 = this.context;
            if (context2 instanceof Activity) {
                ((Activity) context2).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        MRAIDView mRAIDView = MRAIDView.this;
                        if (mRAIDView.state == 3) {
                            mRAIDView.removeResizeView();
                            MRAIDView mRAIDView2 = MRAIDView.this;
                            mRAIDView2.addView(mRAIDView2.webView);
                        }
                        MRAIDView.this.webView.setWebChromeClient(null);
                        MRAIDView.this.webView.setWebViewClient(null);
                        MRAIDView mRAIDView3 = MRAIDView.this;
                        mRAIDView3.webViewPart2 = mRAIDView3.createWebView();
                        MRAIDView.this.webViewPart2.loadDataWithBaseURL(MRAIDView.this.baseUrl, stringFromUrl, "text/html", C.UTF8_NAME, null);
                        MRAIDLog.d("hz-m MRAIDView - expand - switching out currentwebview for " + MRAIDView.this.webViewPart2);
                        MRAIDView mRAIDView4 = MRAIDView.this;
                        mRAIDView4.currentWebView = mRAIDView4.webViewPart2;
                        MRAIDView.this.isExpandingPart2 = true;
                        MRAIDView mRAIDView5 = MRAIDView.this;
                        mRAIDView5.expandHelper(mRAIDView5.currentWebView);
                    }
                });
                return;
            }
        }
        MRAIDLog.e("Could not load part 2 expanded content for URL: " + str);
    }

    public static void lambda$injectJavaScript$6(String str) {
        MRAIDLog.d("Evaluated JS: " + str);
    }

    public void onLayoutWebView(WebView webView, boolean z7, int i10, int i11, int i12, int i13) {
        boolean z9 = webView == this.currentWebView;
        String str = MRAID_LOG_TAG;
        StringBuilder sb2 = new StringBuilder();
        sb2.append("onLayoutWebView ");
        sb2.append(webView == this.webView ? "1 " : "2 ");
        sb2.append(z9);
        sb2.append(" (");
        sb2.append(this.state);
        sb2.append(") ");
        sb2.append(z7);
        sb2.append(" ");
        sb2.append(i10);
        sb2.append(" ");
        sb2.append(i11);
        sb2.append(" ");
        sb2.append(i12);
        sb2.append(" ");
        sb2.append(i13);
        MRAIDLog.w(str, sb2.toString());
        if (!z9) {
            MRAIDLog.d(str, "onLayoutWebView ignored, not current");
            return;
        }
        int i14 = this.state;
        if (i14 == 0 || i14 == 1) {
            calculateScreenSize();
            calculateMaxSize();
        }
        if (!this.isClosing) {
            calculatePosition(true);
            if (this.isInterstitial && !this.defaultPosition.equals(this.currentPosition)) {
                this.defaultPosition = new Rect(this.currentPosition);
                setDefaultPosition();
            }
        }
        if (this.isExpandingFromDefault) {
            this.isExpandingFromDefault = false;
            if (this.isInterstitial) {
                this.state = 1;
                this.isLaidOut = true;
            }
            if (!this.isExpandingPart2) {
                MRAIDLog.d(str, "calling fireStateChangeEvent 1");
                fireStateChangeEvent();
            }
            if (this.isInterstitial) {
                fireReadyEvent();
                if (this.isViewable) {
                    fireViewableChangeEvent();
                }
                fireExposureChangeEvent();
            }
            MRAIDViewListener mRAIDViewListener = this.listener;
            if (mRAIDViewListener != null) {
                mRAIDViewListener.mraidViewExpand(this);
            }
        }
    }

    @JavascriptMRAIDCallback
    public void open(String str) {
        try {
            String decode = URLDecoder.decode(str, C.UTF8_NAME);
            StringBuilder sb2 = new StringBuilder();
            String str2 = MRAID_LOG_TAG;
            sb2.append(str2);
            sb2.append("-JS callback");
            String sb3 = sb2.toString();
            MRAIDLog.d(sb3, "open " + decode + " touched: " + this.wasTouched);
            if (!this.wasTouched) {
                MRAIDLog.d(str2 + "- JS callback", "open called, but no touch recorded, aborting");
            } else if (this.nativeFeatureListener != null) {
                if (decode.startsWith(MRAIDNativeFeature.SMS)) {
                    this.nativeFeatureListener.mraidNativeFeatureSendSms(decode);
                } else if (decode.startsWith(MRAIDNativeFeature.TEL)) {
                    this.nativeFeatureListener.mraidNativeFeatureCallTel(decode);
                } else {
                    this.nativeFeatureListener.mraidNativeFeatureOpenBrowser(decode);
                }
            }
        } catch (UnsupportedEncodingException e10) {
            HyBid.reportException((Exception) e10);
            e10.printStackTrace();
        }
    }

    public void parseCommandUrl(String str) {
        String str2 = MRAID_LOG_TAG;
        MRAIDLog.d(str2, "parseCommandUrl " + str);
        Map<String, String> parseCommandUrl = new MRAIDParser().parseCommandUrl(str);
        String str3 = parseCommandUrl.get("command");
        try {
            if (Arrays.asList(COMMANDS_WITH_NO_PARAM).contains(str3)) {
                try {
                    getClass().getDeclaredMethod(str3, new Class[0]).invoke(this, new Object[0]);
                    return;
                } catch (NoSuchMethodException unused) {
                    getClass().getSuperclass().getDeclaredMethod(str3, new Class[0]).invoke(this, new Object[0]);
                    return;
                }
            } else if (!Arrays.asList(COMMANDS_WITH_STRING).contains(str3)) {
                if (Arrays.asList(COMMANDS_WITH_MAP).contains(str3)) {
                    try {
                        getClass().getDeclaredMethod(str3, Map.class).invoke(this, parseCommandUrl);
                        return;
                    } catch (NoSuchMethodException unused2) {
                        getClass().getSuperclass().getDeclaredMethod(str3, Map.class).invoke(this, parseCommandUrl);
                        return;
                    }
                }
                return;
            } else {
                char c10 = 65535;
                int hashCode = str3.hashCode();
                String str4 = MraidJsMethods.USE_CUSTOM_CLOSE;
                if (hashCode != -733616544) {
                    if (hashCode == 1614272768 && str3.equals(MraidJsMethods.USE_CUSTOM_CLOSE)) {
                        c10 = 1;
                    }
                } else if (str3.equals("createCalendarEvent")) {
                    c10 = 0;
                }
                if (c10 == 0) {
                    str4 = "eventJSON";
                } else if (c10 != 1) {
                    str4 = "url";
                }
                String str5 = parseCommandUrl.get(str4);
                try {
                    getClass().getDeclaredMethod(str3, String.class).invoke(this, str5);
                    return;
                } catch (NoSuchMethodException unused3) {
                    getClass().getSuperclass().getDeclaredMethod(str3, String.class).invoke(this, str5);
                    return;
                }
            }
        } catch (Exception e10) {
            HyBid.reportException(e10);
            e10.printStackTrace();
        }
        HyBid.reportException(e10);
        e10.printStackTrace();
    }

    @JavascriptMRAIDCallback
    private void playVideo(String str) {
        try {
            String decode = URLDecoder.decode(str, C.UTF8_NAME);
            MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", "playVideo " + decode);
            MRAIDNativeFeatureListener mRAIDNativeFeatureListener = this.nativeFeatureListener;
            if (mRAIDNativeFeatureListener != null) {
                mRAIDNativeFeatureListener.mraidNativeFeaturePlayVideo(decode);
            }
        } catch (UnsupportedEncodingException e10) {
            HyBid.reportException((Exception) e10);
            e10.printStackTrace();
        }
    }

    private int px2dip(int i10) {
        DisplayMetrics displayMetrics = this.displayMetrics;
        return displayMetrics != null ? (i10 * 160) / displayMetrics.densityDpi : i10;
    }

    private void removeDefaultCloseButton() {
        ImageButton imageButton = this.closeRegion;
        if (imageButton != null) {
            imageButton.setImageResource(17170445);
        }
    }

    public void removeResizeView() {
        RelativeLayout relativeLayout = this.resizedView;
        if (relativeLayout != null) {
            relativeLayout.removeAllViews();
            Context context = this.context;
            if (context instanceof Activity) {
                ((FrameLayout) ((Activity) context).findViewById(16908290)).removeView(this.resizedView);
                this.resizedView = null;
                this.closeRegion = null;
            }
        }
    }

    @JavascriptMRAIDCallback
    private void resize() {
        MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", MraidJsMethods.RESIZE);
        MRAIDViewListener mRAIDViewListener = this.listener;
        if (mRAIDViewListener == null) {
            return;
        }
        MRAIDResizeProperties mRAIDResizeProperties = this.resizeProperties;
        if (mRAIDViewListener.mraidViewResize(this, mRAIDResizeProperties.width, mRAIDResizeProperties.height, mRAIDResizeProperties.offsetX, mRAIDResizeProperties.offsetY)) {
            this.state = 3;
            if (this.resizedView == null) {
                this.resizedView = new RelativeLayout(this.context);
                removeView(this.webView);
                this.resizedView.addView(this.webView);
                addCloseRegion(this.resizedView);
                ((FrameLayout) getRootView().findViewById(16908290)).addView(this.resizedView);
            }
            setCloseRegionPosition(this.resizedView);
            setResizedViewSize();
            lambda$onLayout$7();
            this.handler.post(new Runnable() {
                @Override
                public final void run() {
                    MRAIDView.this.fireStateChangeEvent();
                }
            });
        }
    }

    private void restoreOriginalOrientation() {
        if (this.context instanceof Activity) {
            MRAIDLog.d(MRAID_LOG_TAG, "restoreOriginalOrientation");
            Activity activity = (Activity) this.context;
            int requestedOrientation = activity.getRequestedOrientation();
            int i10 = this.originalRequestedOrientation;
            if (requestedOrientation != i10) {
                activity.setRequestedOrientation(i10);
            }
        }
    }

    @TargetApi(11)
    private void restoreOriginalScreenState() {
        Context context = this.context;
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (!this.isFullScreen) {
                activity.getWindow().clearFlags(1024);
            }
            if (this.isForceNotFullScreen) {
                activity.getWindow().addFlags(2048);
            }
            if (this.isActionBarShowing) {
                activity.getActionBar().show();
                return;
            }
            View view = this.titleBar;
            if (view != null) {
                view.setVisibility(this.origTitleBarVisibility);
            }
        }
    }

    private void setCloseRegionPosition(View view) {
        DisplayMetrics displayMetrics = this.displayMetrics;
        if (displayMetrics != null) {
            int applyDimension = (int) TypedValue.applyDimension(1, 50.0f, displayMetrics);
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(applyDimension, applyDimension);
            if (view != this.expandedView) {
                if (view == this.resizedView) {
                    switch (this.resizeProperties.customClosePosition) {
                        case 0:
                        case 4:
                            layoutParams.addRule(9);
                            break;
                        case 1:
                        case 3:
                        case 5:
                            layoutParams.addRule(14);
                            break;
                        case 2:
                        case 6:
                            layoutParams.addRule(11);
                            break;
                    }
                    switch (this.resizeProperties.customClosePosition) {
                        case 0:
                        case 1:
                        case 2:
                            layoutParams.addRule(10);
                            break;
                        case 3:
                            layoutParams.addRule(15);
                            break;
                        case 4:
                        case 5:
                        case 6:
                            layoutParams.addRule(12);
                            break;
                    }
                }
            } else {
                layoutParams.addRule(10);
                layoutParams.addRule(20);
            }
            this.closeRegion.setLayoutParams(layoutParams);
        }
    }

    public void setCurrentPosition() {
        Rect rect = this.currentPosition;
        int i10 = rect.left;
        int i11 = rect.top;
        int width = rect.width();
        int height = this.currentPosition.height();
        String str = MRAID_LOG_TAG;
        MRAIDLog.d(str, "setCurrentPosition [" + i10 + "," + i11 + "] (" + width + "x" + height + ")");
        injectJavaScript("mraid.setCurrentPosition(" + px2dip(i10) + "," + px2dip(i11) + "," + px2dip(width) + "," + px2dip(height) + ");");
    }

    public void setDefaultPosition() {
        Rect rect = this.defaultPosition;
        int i10 = rect.left;
        int i11 = rect.top;
        int width = rect.width();
        int height = this.defaultPosition.height();
        String str = MRAID_LOG_TAG;
        MRAIDLog.d(str, "setDefaultPosition [" + i10 + "," + i11 + "] (" + width + "x" + height + ")");
        injectJavaScript("mraid.setDefaultPosition(" + px2dip(i10) + "," + px2dip(i11) + "," + px2dip(width) + "," + px2dip(height) + ");");
    }

    public void setEnvironmentVariables() {
        DeviceInfo deviceInfo = HyBid.getDeviceInfo();
        if (getContext() != null && getContext().getApplicationContext() != null && !TextUtils.isEmpty(getContext().getApplicationContext().getPackageName())) {
            injectJavaScript("mraid.setAppId(\"" + getContext().getApplicationContext().getPackageName() + "\");");
        }
        injectJavaScript("mraid.setSdkVersion(\"2.20.0\");");
        injectJavaScript("mraid.setCoppa(" + HyBid.isCoppaEnabled() + ");");
        if (deviceInfo != null) {
            if (!deviceInfo.limitTracking() && !TextUtils.isEmpty(deviceInfo.getAdvertisingId())) {
                injectJavaScript("mraid.setIfa(\"" + deviceInfo.getAdvertisingId() + "\");");
            }
            injectJavaScript("mraid.setLimitAdTracking(" + deviceInfo.limitTracking() + ");");
        }
    }

    public void setLocation() {
        if (!this.nativeFeatureManager.isLocationSupported()) {
            injectJavaScript("mraid.setLocation(-1);");
            return;
        }
        HyBidLocationManager locationManager = HyBid.getLocationManager();
        if (locationManager == null || locationManager.getUserLocation() == null) {
            injectJavaScript("mraid.setLocation(-1);");
            return;
        }
        Location userLocation = locationManager.getUserLocation();
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("lat", userLocation.getLatitude());
            jSONObject.put("lon", userLocation.getLongitude());
            jSONObject.put("type", 1);
            jSONObject.put("accuracy", userLocation.getAccuracy());
            jSONObject.put("lastfix", (SystemClock.elapsedRealtimeNanos() - userLocation.getElapsedRealtimeNanos()) / C.NANOS_PER_SECOND);
            injectJavaScript("mraid.setLocation(" + jSONObject.toString() + ");");
        } catch (JSONException e10) {
            HyBid.reportException((Exception) e10);
            Logger.e(MRAID_LOG_TAG, "Error passing location to MRAID interface");
            injectJavaScript("mraid.setLocation(-1);");
        }
    }

    public void setMaxSize() {
        String str = MRAID_LOG_TAG;
        MRAIDLog.d(str, "setMaxSize");
        Size size = this.maxSize;
        int i10 = size.width;
        int i11 = size.height;
        MRAIDLog.d(str, "setMaxSize " + i10 + "x" + i11);
        injectJavaScript("mraid.setMaxSize(" + px2dip(i10) + "," + px2dip(i11) + ");");
    }

    private void setOrientationInitialState() {
        Context context = this.context;
        if (context == null || !(context instanceof Activity)) {
            return;
        }
        ((Activity) context).setRequestedOrientation(this.activityInitialOrientation);
    }

    @JavascriptMRAIDCallback
    private void setResizeProperties(Map<String, String> map) {
        int parseInt = Integer.parseInt(map.get("width"));
        int parseInt2 = Integer.parseInt(map.get("height"));
        int parseInt3 = Integer.parseInt(map.get("offsetX"));
        int parseInt4 = Integer.parseInt(map.get("offsetY"));
        String str = map.get("customClosePosition");
        boolean parseBoolean = Boolean.parseBoolean(map.get("allowOffscreen"));
        MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", "setResizeProperties " + parseInt + " " + parseInt2 + " " + parseInt3 + " " + parseInt4 + " " + str + " " + parseBoolean);
        MRAIDResizeProperties mRAIDResizeProperties = this.resizeProperties;
        mRAIDResizeProperties.width = parseInt;
        mRAIDResizeProperties.height = parseInt2;
        mRAIDResizeProperties.offsetX = parseInt3;
        mRAIDResizeProperties.offsetY = parseInt4;
        mRAIDResizeProperties.customClosePosition = MRAIDResizeProperties.customClosePositionFromString(str);
        this.resizeProperties.allowOffscreen = parseBoolean;
    }

    public void lambda$onLayout$7() {
        if (this.displayMetrics != null) {
            MRAIDLog.d(MRAID_LOG_TAG, "setResizedViewPosition");
            if (this.resizedView == null) {
                return;
            }
            MRAIDResizeProperties mRAIDResizeProperties = this.resizeProperties;
            int i10 = mRAIDResizeProperties.width;
            int i11 = mRAIDResizeProperties.height;
            int i12 = mRAIDResizeProperties.offsetX;
            int i13 = mRAIDResizeProperties.offsetY;
            int applyDimension = (int) TypedValue.applyDimension(1, i10, this.displayMetrics);
            int applyDimension2 = (int) TypedValue.applyDimension(1, i11, this.displayMetrics);
            Rect rect = this.defaultPosition;
            int applyDimension3 = rect.left + ((int) TypedValue.applyDimension(1, i12, this.displayMetrics));
            int applyDimension4 = rect.top + ((int) TypedValue.applyDimension(1, i13, this.displayMetrics));
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this.resizedView.getLayoutParams();
            layoutParams.leftMargin = applyDimension3;
            layoutParams.topMargin = applyDimension4;
            this.resizedView.setLayoutParams(layoutParams);
            Rect rect2 = this.currentPosition;
            if (applyDimension3 == rect2.left && applyDimension4 == rect2.top && applyDimension == rect2.width() && applyDimension2 == this.currentPosition.height()) {
                return;
            }
            Rect rect3 = this.currentPosition;
            rect3.left = applyDimension3;
            rect3.top = applyDimension4;
            rect3.right = applyDimension3 + applyDimension;
            rect3.bottom = applyDimension4 + applyDimension2;
            setCurrentPosition();
        }
    }

    private void setResizedViewSize() {
        if (this.displayMetrics != null) {
            String str = MRAID_LOG_TAG;
            MRAIDLog.d(str, "setResizedViewSize");
            MRAIDResizeProperties mRAIDResizeProperties = this.resizeProperties;
            int i10 = mRAIDResizeProperties.width;
            int i11 = mRAIDResizeProperties.height;
            MRAIDLog.d(str, "setResizedViewSize " + i10 + "x" + i11);
            this.resizedView.setLayoutParams(new FrameLayout.LayoutParams((int) TypedValue.applyDimension(1, (float) i10, this.displayMetrics), (int) TypedValue.applyDimension(1, (float) i11, this.displayMetrics)));
        }
    }

    public void setScreenSize() {
        String str = MRAID_LOG_TAG;
        MRAIDLog.d(str, "setScreenSize");
        Size size = this.screenSize;
        int i10 = size.width;
        int i11 = size.height;
        MRAIDLog.d(str, "setScreenSize " + i10 + "x" + i11);
        injectJavaScript("mraid.setScreenSize(" + px2dip(i10) + "," + px2dip(i11) + ");");
    }

    public void setSupportedServices() {
        MRAIDLog.d(MRAID_LOG_TAG, "setSupportedServices");
        injectJavaScript("mraid.setSupports(mraid.SUPPORTED_FEATURES.CALENDAR, " + this.nativeFeatureManager.isCalendarSupported() + ");");
        injectJavaScript("mraid.setSupports(mraid.SUPPORTED_FEATURES.INLINEVIDEO, " + this.nativeFeatureManager.isInlineVideoSupported() + ");");
        injectJavaScript("mraid.setSupports(mraid.SUPPORTED_FEATURES.SMS, " + this.nativeFeatureManager.isSmsSupported() + ");");
        injectJavaScript("mraid.setSupports(mraid.SUPPORTED_FEATURES.STOREPICTURE, " + this.nativeFeatureManager.isStorePictureSupported() + ");");
        injectJavaScript("mraid.setSupports(mraid.SUPPORTED_FEATURES.TEL, " + this.nativeFeatureManager.isTelSupported() + ");");
        injectJavaScript("mraid.setSupports(mraid.SUPPORTED_FEATURES.LOCATION, " + this.nativeFeatureManager.isLocationSupported() + ");");
    }

    public void setViewable(int i10) {
        boolean z7 = i10 == 0;
        if (z7 != this.isViewable) {
            this.isViewable = z7;
            if (this.isPageFinished && this.isLaidOut) {
                fireViewableChangeEvent();
                fireExposureChangeEvent();
            }
        }
    }

    public void showDefaultCloseButton() {
        ImageButton imageButton = this.closeRegion;
        if (imageButton != null) {
            Context context = imageButton.getContext();
            Integer normalCloseXmlResource = HyBid.getNormalCloseXmlResource();
            int i10 = R.mipmap.close;
            Bitmap bitmap = BitmapHelper.toBitmap(context, normalCloseXmlResource, Integer.valueOf(i10));
            if (bitmap != null) {
                this.closeRegion.setImageBitmap(bitmap);
            } else {
                ImageButton imageButton2 = this.closeRegion;
                imageButton2.setImageBitmap(BitmapHelper.decodeResource(imageButton2.getContext(), Integer.valueOf(i10)));
            }
            this.closeRegion.setScaleType(ImageView.ScaleType.FIT_CENTER);
        }
    }

    public void startSkipTimer() {
        Integer num;
        if (this.useCustomClose) {
            handleNativeCloseButtonDelay();
            Runnable runnable = this.backButtonClickabilityHandler;
            if (runnable != null) {
                runnable.run();
            }
            num = this.mNativeCloseButtonDelay;
            CountDownView countDownView = this.mSkipCountdownView;
            if (countDownView != null) {
                countDownView.setVisibility(8);
            }
        } else {
            num = this.mSkipTimeMillis;
            CountDownView countDownView2 = this.mSkipCountdownView;
            if (countDownView2 != null) {
                countDownView2.setVisibility(0);
            }
        }
        if (num.intValue() > 0 && this.showTimerBeforeEndCard.booleanValue()) {
            SimpleTimer simpleTimer = new SimpleTimer(num.intValue(), new SimpleTimer.Listener() {
                @Override
                public void onFinish() {
                    MRAIDView.this.listener.mraidShowCloseButton();
                    if (MRAIDView.this.mSkipCountdownView != null) {
                        MRAIDView.this.mSkipCountdownView.setVisibility(8);
                    }
                }

                @Override
                public void onTick(long j10) {
                    if (MRAIDView.this.mSkipCountdownView != null) {
                        MRAIDView.this.mSkipCountdownView.setProgress((int) (MRAIDView.this.mSkipTimeMillis.intValue() - j10), MRAIDView.this.mSkipTimeMillis.intValue());
                    }
                }
            }, 10L);
            this.mExpirationTimer = simpleTimer;
            simpleTimer.start();
        } else if (num.intValue() == 0) {
            this.listener.mraidShowCloseButton();
        }
        if (this.mBackButtonDelay.intValue() > 0) {
            new SimpleTimer(this.mBackButtonDelay.intValue(), new SimpleTimer.Listener() {
                @Override
                public void onFinish() {
                    MRAIDView.this.isBackClickable = Boolean.TRUE;
                }

                @Override
                public void onTick(long j10) {
                    MRAIDView.this.isBackClickable = Boolean.FALSE;
                }
            }, 10L).start();
        }
    }

    @JavascriptMRAIDCallback
    private void storePicture(String str) {
        try {
            String decode = URLDecoder.decode(str, C.UTF8_NAME);
            MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", "storePicture " + decode);
            MRAIDNativeFeatureListener mRAIDNativeFeatureListener = this.nativeFeatureListener;
            if (mRAIDNativeFeatureListener != null) {
                mRAIDNativeFeatureListener.mraidNativeFeatureStorePicture(decode);
            }
        } catch (UnsupportedEncodingException e10) {
            HyBid.reportException((Exception) e10);
            e10.printStackTrace();
        }
    }

    @JavascriptMRAIDCallback
    @Deprecated
    private void useCustomClose(String str) {
        MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", "useCustomClose " + str);
        boolean parseBoolean = Boolean.parseBoolean(str);
        if (this.useCustomClose != parseBoolean) {
            this.useCustomClose = parseBoolean;
        }
    }

    public void addViewabilityFriendlyObstruction(View view, FriendlyObstructionPurpose friendlyObstructionPurpose, String str) {
        if (view == null || TextUtils.isEmpty(str)) {
            return;
        }
        this.mViewabilityFriendlyObstructions.add(new HyBidViewabilityFriendlyObstruction(view, friendlyObstructionPurpose, str));
    }

    public void applyOrientationProperties() {
        if (this.context instanceof Activity) {
            String str = MRAID_LOG_TAG;
            MRAIDLog.d(str, "applyOrientationProperties " + this.orientationProperties.allowOrientationChange + " " + this.orientationProperties.forceOrientationString());
            Activity activity = (Activity) this.context;
            int i10 = 0;
            int i11 = getResources().getConfiguration().orientation == 1 ? 1 : 0;
            StringBuilder sb2 = new StringBuilder();
            sb2.append("currentOrientation ");
            sb2.append(i11 != 0 ? "portrait" : "landscape");
            MRAIDLog.d(str, sb2.toString());
            MRAIDOrientationProperties mRAIDOrientationProperties = this.orientationProperties;
            int i12 = mRAIDOrientationProperties.forceOrientation;
            if (i12 == 0) {
                i10 = 1;
            } else if (i12 != 1) {
                i10 = mRAIDOrientationProperties.allowOrientationChange ? -1 : i11;
            }
            activity.setRequestedOrientation(i10);
        }
    }

    public void clearView() {
        WebView webView = this.webView;
        if (webView != null) {
            webView.setWebChromeClient(null);
            this.webView.setWebViewClient(null);
            this.webView.loadUrl("about:blank");
        }
    }

    @JavascriptMRAIDCallback
    public void close() {
        MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", "close");
        MRAIDLog.d("hz-m closing wv: " + this.webView);
        this.handler.post(new Runnable() {
            @Override
            public final void run() {
                MRAIDView.this.lambda$close$0();
            }
        });
    }

    public void closeFromExpanded() {
        FrameLayout frameLayout;
        int i10 = this.state;
        if (i10 == 2 || i10 == 3) {
            this.state = 1;
        }
        MRAIDOrientationProperties mRAIDOrientationProperties = this.orientationProperties;
        if (mRAIDOrientationProperties != null) {
            mRAIDOrientationProperties.allowOrientationChange = true;
        }
        setOrientationInitialState();
        this.isClosing = true;
        this.isExpanded = false;
        RelativeLayout relativeLayout = this.expandedView;
        if (relativeLayout != null) {
            relativeLayout.removeAllViews();
        }
        Context context = this.context;
        if (!(context instanceof Activity) || (frameLayout = (FrameLayout) ((Activity) context).findViewById(16908290)) == null) {
            return;
        }
        frameLayout.removeView(this.expandedView);
        this.expandedView = null;
        this.closeRegion = null;
        this.handler.post(new Runnable() {
            @Override
            public final void run() {
                MRAIDView.this.lambda$closeFromExpanded$2();
            }
        });
        WebView webView = this.webViewPart2;
        if (webView == null) {
            if (findViewById(R.id.mraid_ad_view) != null) {
                removeView(this.webView);
            }
            addView(this.webView, 0, new FrameLayout.LayoutParams(-1, -2));
        } else {
            webView.destroy();
            this.webView.setWebChromeClient(this.mraidWebChromeClient);
            this.webView.setWebViewClient(this.mraidWebViewClient);
            MRAIDLog.d("hz-m MRAIDView - closeFromExpanded - setting currentwebview to " + this.webView);
            WebView webView2 = this.webView;
            this.currentWebView = webView2;
            webView2.setLayoutParams(new FrameLayout.LayoutParams(-1, -2));
        }
        this.handler.post(new Runnable() {
            @Override
            public final void run() {
                MRAIDView.this.lambda$closeFromExpanded$3();
            }
        });
    }

    public void closeFromResized() {
        this.state = 1;
        this.isClosing = true;
        removeResizeView();
        addView(this.webView, 0);
        this.handler.post(new Runnable() {
            @Override
            public final void run() {
                MRAIDView.this.lambda$closeFromResized$4();
            }
        });
    }

    public void destroy() {
        if (this.webView != null) {
            MRAIDLog.i("Destroying Main WebView");
            this.webView.destroy();
        }
        if (this.webViewPart2 != null) {
            MRAIDLog.i("Destroying Secondary WebView");
            this.webViewPart2.destroy();
        }
        RelativeLayout relativeLayout = this.expandedView;
        if (relativeLayout != null) {
            ViewGroup viewGroup = (ViewGroup) relativeLayout.getParent();
            if (viewGroup != null) {
                viewGroup.removeView(this.expandedView);
            }
            this.expandedView = null;
        }
        this.currentWebView = null;
        this.contentInfoAdded = false;
        SimpleTimer simpleTimer = this.mExpirationTimer;
        if (simpleTimer != null) {
            simpleTimer.onFinish();
            this.mExpirationTimer = null;
        }
        SimpleTimer simpleTimer2 = this.mNativeCloseButtonTimer;
        if (simpleTimer2 != null) {
            simpleTimer2.onFinish();
            this.mNativeCloseButtonTimer = null;
        }
    }

    @JavascriptMRAIDCallback
    @TargetApi(11)
    @Deprecated
    public void expand(String str) {
        if (this.isExpandEnabled) {
            expandCreative(str, false, Boolean.FALSE);
        }
    }

    public void expand(String str, Boolean bool, OnExpandCreativeFailListener onExpandCreativeFailListener) {
        expandCreative(str, false, bool, onExpandCreativeFailListener);
    }

    public void expandContentInfo(String str) {
        decodeURL(str, false);
    }

    public void expandHelper(WebView webView) {
        applyOrientationProperties();
        forceFullScreen();
        RelativeLayout relativeLayout = new RelativeLayout(this.context);
        this.expandedView = relativeLayout;
        relativeLayout.addView(webView, new RelativeLayout.LayoutParams(-1, -1));
        if (this.isInterstitial) {
            addContentInfo(this.expandedView);
        }
        addCloseRegion(this.expandedView);
        setCloseRegionPosition(this.expandedView);
        MRAIDLog.d("hz-m MRAIDView - expandHelper - adding contentview to activity " + this.context);
        this.showActivity.addContentView(this.expandedView, new RelativeLayout.LayoutParams(-1, -1));
        this.isExpandingFromDefault = true;
        this.isExpanded = true;
    }

    public void fireExposureChangeEvent() {
        double d10 = this.isViewable ? 100.0d : FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
        MRAIDLog.d(MRAID_LOG_TAG, "fireExposureChangeEvent");
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("x", getX());
            jSONObject.put("y", getY());
            jSONObject.put("width", (getWidth() * d10) / 100.0d);
            jSONObject.put("height", (getHeight() * d10) / 100.0d);
        } catch (JSONException e10) {
            HyBid.reportException((Exception) e10);
            e10.printStackTrace();
        }
        injectJavaScript("mraid.fireExposureChangeEvent(" + d10 + "," + jSONObject.toString() + ",null);");
    }

    public void fireReadyEvent() {
        MRAIDLog.d(MRAID_LOG_TAG, "fireReadyEvent");
        injectJavaScript("mraid.fireReadyEvent();");
    }

    @SuppressLint({"DefaultLocale"})
    public void fireStateChangeEvent() {
        MRAIDLog.d(MRAID_LOG_TAG, "fireStateChangeEvent");
        String[] strArr = {"loading", CoreModuleInterface.NAME_DEFAULT_HTTP_HANDLER, "expanded", "resized", "hidden"};
        injectJavaScript("mraid.fireStateChangeEvent('" + strArr[this.state] + "');");
    }

    public void fireViewableChangeEvent() {
        MRAIDLog.d(MRAID_LOG_TAG, "fireViewableChangeEvent");
        injectJavaScript("mraid.fireViewableChangeEvent(" + this.isViewable + ");");
    }

    public int getState() {
        return this.state;
    }

    public void handleNativeCloseButtonDelay() {
        SimpleTimer simpleTimer = new SimpleTimer(this.mNativeCloseButtonDelay.intValue(), new SimpleTimer.Listener() {
            @Override
            public void onFinish() {
                MRAIDViewListener mRAIDViewListener = MRAIDView.this.listener;
                if (mRAIDViewListener != null) {
                    mRAIDViewListener.mraidShowCloseButton();
                }
                MRAIDView.this.showDefaultCloseButton();
            }

            @Override
            public void onTick(long j10) {
            }
        }, 1000L);
        this.mNativeCloseButtonTimer = simpleTimer;
        simpleTimer.start();
    }

    public void injectJavaScript(String str) {
        injectJavaScript(this.currentWebView, str);
    }

    public boolean isExpanded() {
        return this.isExpanded;
    }

    public boolean isLoaded() {
        return this.isPageFinished;
    }

    @Override
    public void onAttachedToWindow() {
        MRAIDLog.d(MRAID_LOG_TAG, "onAttachedToWindow");
        super.onAttachedToWindow();
    }

    public boolean onBackPressed() {
        MRAIDLog.d("hz-m MRAIDView - onBackPressed");
        int i10 = this.state;
        if (i10 == 0 || i10 == 4) {
            MRAIDLog.d("hz-m MRAIDView - onBackPressed - loading or hidden");
            return false;
        } else if (this.isBackClickable.booleanValue()) {
            close();
            return true;
        } else {
            return true;
        }
    }

    @Override
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        String str = MRAID_LOG_TAG;
        StringBuilder sb2 = new StringBuilder();
        sb2.append("onConfigurationChanged ");
        sb2.append(configuration.orientation == 1 ? "portrait" : "landscape");
        MRAIDLog.d(str, sb2.toString());
        WindowManager windowManager = (WindowManager) this.context.getSystemService("window");
        if (windowManager != null) {
            windowManager.getDefaultDisplay().getMetrics(this.displayMetrics);
        }
    }

    @Override
    public void onDetachedFromWindow() {
        MRAIDLog.d(MRAID_LOG_TAG, "onDetachedFromWindow");
        stopAdSession();
        super.onDetachedFromWindow();
    }

    @Override
    @SuppressLint({"DrawAllocation"})
    public void onLayout(boolean z7, int i10, int i11, int i12, int i13) {
        super.onLayout(z7, i10, i11, i12, i13);
        String str = MRAID_LOG_TAG;
        MRAIDLog.w(str, "onLayout (" + this.state + ") " + z7 + " " + i10 + " " + i11 + " " + i12 + " " + i13);
        if (this.isForcingFullScreen) {
            MRAIDLog.d(str, "onLayout ignored");
            return;
        }
        int i14 = this.state;
        if (i14 == 2 || i14 == 3) {
            calculateScreenSize();
            calculateMaxSize();
        }
        if (this.isClosing) {
            this.isClosing = false;
            this.currentPosition = new Rect(this.defaultPosition);
            setCurrentPosition();
        } else {
            calculatePosition(false);
        }
        if (this.state == 3 && z7) {
            this.handler.post(new Runnable() {
                @Override
                public final void run() {
                    MRAIDView.this.lambda$onLayout$7();
                }
            });
        }
        this.isLaidOut = true;
        onLayoutCompleted();
    }

    public void onLayoutCompleted() {
    }

    @Override
    @SuppressLint({"ClickableViewAccessibility"})
    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (this.gestureDetector.onTouchEvent(motionEvent)) {
            motionEvent.setAction(3);
        }
        return super.onTouchEvent(motionEvent);
    }

    @Override
    public void onVisibilityChanged(View view, int i10) {
        super.onVisibilityChanged(view, i10);
        String str = MRAID_LOG_TAG;
        MRAIDLog.d(str, "onVisibilityChanged " + getVisibilityString(i10));
        setViewable(i10);
    }

    @Override
    public void onWindowVisibilityChanged(int i10) {
        super.onWindowVisibilityChanged(i10);
        int visibility = getVisibility();
        String str = MRAID_LOG_TAG;
        MRAIDLog.d(str, "onWindowVisibilityChanged " + getVisibilityString(i10) + " (actual " + getVisibilityString(visibility) + ")");
        setViewable(visibility);
    }

    public void pause() {
        SimpleTimer simpleTimer = this.mExpirationTimer;
        if (simpleTimer != null) {
            simpleTimer.pause();
        }
        SimpleTimer simpleTimer2 = this.mNativeCloseButtonTimer;
        if (simpleTimer2 != null) {
            simpleTimer2.pause();
        }
    }

    public void resume() {
        SimpleTimer simpleTimer = this.mExpirationTimer;
        if (simpleTimer != null) {
            simpleTimer.resume();
        }
        SimpleTimer simpleTimer2 = this.mNativeCloseButtonTimer;
        if (simpleTimer2 != null) {
            simpleTimer2.resume();
        }
    }

    public void setBackButtonClickabilityHandler(Runnable runnable) {
        this.backButtonClickabilityHandler = runnable;
    }

    public void setBackButtonDelay(Integer num) {
        this.mBackButtonDelay = num;
    }

    public void setCloseLayoutListener(MRAIDViewCloseLayoutListener mRAIDViewCloseLayoutListener) {
        this.closeLayoutListener = mRAIDViewCloseLayoutListener;
    }

    public void setNativeCloseButtonDelay(Integer num) {
        this.mNativeCloseButtonDelay = Integer.valueOf(num.intValue() * 1000);
    }

    @JavascriptMRAIDCallback
    public void setOrientationProperties(Map<String, String> map) {
        boolean parseBoolean = Boolean.parseBoolean(map.get("allowOrientationChange"));
        String str = map.get("forceOrientation");
        MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", "setOrientationProperties " + parseBoolean + " " + str);
        MRAIDOrientationProperties mRAIDOrientationProperties = this.orientationProperties;
        mRAIDOrientationProperties.allowOrientationChange = parseBoolean;
        mRAIDOrientationProperties.forceOrientation = MRAIDOrientationProperties.forceOrientationFromString(str);
        if ((this instanceof MRAIDInterstitial) || this.state == 2) {
            applyOrientationProperties();
        }
    }

    public void setSkipOffset(Integer num) {
        this.mSkipTimeMillis = Integer.valueOf(num.intValue() * 1000);
    }

    public void setUseCustomClose(Boolean bool) {
        if (this.useCustomClose != bool.booleanValue()) {
            this.useCustomClose = bool.booleanValue();
        }
    }

    public void showAsInterstitial(Activity activity, Boolean bool, OnExpandCreativeFailListener onExpandCreativeFailListener) {
        MRAIDLog.d("hz-m MRAIDVIEW - showAsInterstitial");
        this.showActivity = activity;
        expand(null, bool, onExpandCreativeFailListener);
    }

    public void showAsInterstitial(Activity activity, Boolean bool, OnExpandCreativeFailListener onExpandCreativeFailListener, String str) {
        MRAIDLog.d("hz-m MRAIDVIEW - showAsInterstitial");
        this.showActivity = activity;
        expand(str, bool, onExpandCreativeFailListener);
    }

    public void stopAdSession() {
        HyBidViewabilityWebAdSession hyBidViewabilityWebAdSession = this.mViewabilityAdSession;
        if (hyBidViewabilityWebAdSession != null) {
            hyBidViewabilityWebAdSession.stopAdSession();
        }
    }

    @JavascriptMRAIDCallback
    public void unload() {
        MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", MraidJsMethods.UNLOAD);
        MRAIDLog.d("hz-m unload wv: " + this.webView);
        MRAIDViewListener mRAIDViewListener = this.listener;
        if (mRAIDViewListener != null) {
            mRAIDViewListener.mraidViewError(this);
        }
    }
}