导航菜单

页面标题

页面副标题

OLX India v19.42.007 - MRAIDView.java 源代码

正在查看: OLX India v19.42.007 应用的 MRAIDView.java JAVA 源代码文件

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


package net.pubnative.lite.sdk.mraid;

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.Display;
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.adtmonetize.sdk.code.i1;
import com.adtmonetize.sdk.code.j1;
import com.iab.omid.library.pubnativenet.adsession.FriendlyObstructionPurpose;
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.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.CountdownStyle;
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.models.RemoteConfigFeature;
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.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 olx.com.delorean.domain.Constants;
import org.json.JSONException;
import org.json.JSONObject;

public class MRAIDView extends FrameLayout {
    private static final int CLOSE_REGION_SIZE = 50;
    private static final String MRAID_LOG_TAG = "MRAIDView";
    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 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;
    protected 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;
    protected boolean isLaidOut;
    protected boolean isPageFinished;
    protected boolean isViewable;
    protected final MRAIDViewListener listener;
    private SimpleTimer mAntilockTimer;
    private SimpleTimer mExpirationTimer;
    private boolean mIsExpanding;
    private Integer mNativeCloseButtonDelay;
    private SimpleTimer mNativeCloseButtonTimer;
    private CountDownView mSkipCountdownView;
    private Integer mSkipTimeMillis;
    private 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 final Boolean showTimerBeforeEndCard;
    protected int state;
    private View titleBar;
    private boolean useCustomClose;
    private boolean wasTouched;
    protected final WebView webView;
    private boolean webViewLoaded;
    private WebView webViewPart2;
    private static final CountdownStyle COUNTDOWN_STYLE_DEFAULT = CountdownStyle.PIE_CHART;
    private static final String[] COMMANDS_WITH_NO_PARAM = {"close", "resize"};
    private static final String[] COMMANDS_WITH_STRING = {"createCalendarEvent", "expand", Constants.Notification.Actions.VIEW, "playVideo", MRAIDNativeFeature.STORE_PICTURE, "useCustomClose"};
    private static final String[] COMMANDS_WITH_MAP = {"setOrientationProperties", "setResizeProperties"};

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

    private class MRAIDWebChromeClient extends WebChromeClient {
        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 sb = new StringBuilder();
            sb.append(consoleMessage.message());
            if (consoleMessage.sourceId() == null) {
                str = "";
            } else {
                str = " at " + consoleMessage.sourceId();
            }
            sb.append(str);
            sb.append(Constants.TWO_DOTS);
            sb.append(consoleMessage.lineNumber());
            MRAIDLog.i("JS console", sb.toString());
            return true;
        }

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

        @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 i) {
            MRAIDLog.d("hz-m MRAIDView ChromeClient - onProgressChanged " + i + " wv: " + MRAIDView.this.webView + " view: " + MRAIDView.this);
        }

        public void onReachedMaxAppCacheSize(long j, long j2, WebStorage.QuotaUpdater quotaUpdater) {
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReachedMaxAppCacheSize");
            quotaUpdater.updateQuota(j2);
        }

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

        private MRAIDWebChromeClient() {
        }
    }

    class MRAIDWebViewClient extends WebViewClient {
        public void lambda$onPageFinished$1() {
            MRAIDView mRAIDView = MRAIDView.this;
            StringBuilder sb = new StringBuilder();
            sb.append("mraid.setPlacementType('");
            sb.append(MRAIDView.this.isInterstitial ? RemoteConfigFeature.AdFormat.INTERSTITIAL : "inline");
            sb.append("');");
            mRAIDView.injectJavaScript(sb.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);
            MRAIDView.this.cancelAntilockTimer();
            MRAIDLog.d(MRAIDView.MRAID_LOG_TAG, "onPageFinished: " + str);
            MRAIDView mRAIDView = MRAIDView.this;
            if (mRAIDView.state == 0) {
                mRAIDView.isPageFinished = true;
                boolean z = mRAIDView.isExpandEnabled;
                String str2 = RemoteConfigFeature.AdFormat.INTERSTITIAL;
                if (z) {
                    MRAIDView mRAIDView2 = MRAIDView.this;
                    StringBuilder sb = new StringBuilder();
                    sb.append("mraid.setPlacementType('");
                    if (!MRAIDView.this.isInterstitial) {
                        str2 = "inline";
                    }
                    sb.append(str2);
                    sb.append("');");
                    mRAIDView2.injectJavaScript(sb.toString());
                } else {
                    MRAIDView mRAIDView3 = MRAIDView.this;
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append("mraid.setPlacementType('");
                    if (!MRAIDView.this.isInterstitial) {
                        str2 = "";
                    }
                    sb2.append(str2);
                    sb2.append("');");
                    mRAIDView3.injectJavaScript(sb2.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) {
                    if (MRAIDView.this.mViewabilityAdSession != null) {
                        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");
                            if (MRAIDView.this.mViewabilityFriendlyObstructions != null) {
                                for (HyBidViewabilityFriendlyObstruction hyBidViewabilityFriendlyObstruction : MRAIDView.this.mViewabilityFriendlyObstructions) {
                                    if (MRAIDView.this.mViewabilityAdSession != null) {
                                        MRAIDView.this.mViewabilityAdSession.addFriendlyObstruction(hyBidViewabilityFriendlyObstruction.getView(), hyBidViewabilityFriendlyObstruction.getPurpose(), hyBidViewabilityFriendlyObstruction.getReason());
                                    }
                                }
                            }
                        }
                        MRAIDView.this.webViewLoaded = true;
                        if (MRAIDView.this.mViewabilityAdSession != null) {
                            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, MRAIDView.COUNTDOWN_STYLE_DEFAULT, 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.X(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, 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: " + i1.a(webResourceError));
            MRAIDLog.d("hz-m MRAIDView WebViewClient - onReceivedError: " + ((Object) j1.a(webResourceError)));
        }

        @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) {
                return true;
            }
            mRAIDViewListener.mraidViewError(mRAIDView);
            return true;
        }

        @Override
        public void onScaleChanged(WebView webView, float f, float f2) {
            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, WebResourceRequest webResourceRequest) {
            if (webResourceRequest != null && webResourceRequest.getUrl() != null) {
                String uri = webResourceRequest.getUrl().toString();
                MRAIDLog.d("hz-m shouldInterceptRequest - " + uri);
                if (uri.contains("mraid.js")) {
                    MRAIDLog.d("hz-m shouldInterceptRequest - intercepting mraid - " + uri);
                    MRAIDView.this.handler.post(new Runnable() {
                        @Override
                        public final void run() {
                            MRAIDView.MRAIDWebViewClient.this.lambda$shouldInterceptRequest$2();
                        }
                    });
                    return new WebResourceResponse("application/javascript", "UTF-8", MRAIDView.this.getMraidJsStream());
                }
            }
            return super.shouldInterceptRequest(webView, webResourceRequest);
        }

        @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) {
            MRAIDLog.d(MRAIDView.MRAID_LOG_TAG, "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 {
                if (MRAIDView.this.mIsExpanding) {
                    MRAIDView.this.mIsExpanding = false;
                    return false;
                }
                try {
                    MRAIDView.this.open(URLEncoder.encode(str, "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    Logger.e(MRAIDView.MRAID_LOG_TAG, e.getMessage());
                }
            }
            return true;
        }

        private MRAIDWebViewClient() {
        }

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

    public interface OnExpandCreativeFailListener {
        void onExpandFailed();
    }

    private 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 z, boolean z2) {
        super(context);
        this.mSkipTimeMillis = -1;
        this.mNativeCloseButtonDelay = -1;
        this.isBackClickable = Boolean.FALSE;
        this.activityInitialOrientation = -1;
        this.wasTouched = false;
        this.contentInfoAdded = false;
        this.webViewLoaded = false;
        this.mIsExpanding = 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 || str.isEmpty()) ? "https://example.com" : str;
        this.baseUrl = str3;
        this.isInterstitial = z;
        this.isExpandEnabled = z2;
        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;
        }
        MRAIDLog.d(MRAID_LOG_TAG, "originalRequestedOrientation " + getOrientationString(this.originalRequestedOrientation));
        this.gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) {
                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)) {
            if (str != null) {
                MRAIDLog.d("hz-m loading mraid from url: " + str);
                createWebView.loadUrl(str);
                return;
            }
            return;
        }
        try {
            String processRawHtml = MRAIDHtmlProcessor.processRawHtml(str2);
            MRAIDLog.d("hz-m loading mraid " + processRawHtml);
            createWebView.loadDataWithBaseURL(str3, processRawHtml, "text/html", "UTF-8", null);
            handleAntilockDelay();
        } catch (Throwable th) {
            HyBid.reportException(th);
            this.listener.mraidViewError(this);
        }
    }

    public static void X(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$7(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 + Constants.COMMA + rect.top + "][" + rect.right + Constants.COMMA + rect.bottom + "] (" + rect.width() + "x" + rect.height() + ")");
            if (window.findViewById(android.R.id.content) != null) {
                this.contentViewTop = window.findViewById(android.R.id.content).getTop();
            } else {
                this.contentViewTop = rect.top;
            }
            int i = rect.top;
            int i2 = this.contentViewTop - i;
            MRAIDLog.d(str, "calculateMaxSize statusHeight " + i);
            MRAIDLog.d(str, "calculateMaxSize titleHeight " + i2);
            MRAIDLog.d(str, "calculateMaxSize contentViewTop " + this.contentViewTop);
            int width = rect.width();
            int i3 = this.screenSize.height - this.contentViewTop;
            MRAIDLog.d(str, "calculateMaxSize max size " + width + "x" + i3);
            Size size = this.maxSize;
            if (width == size.width && i3 == size.height) {
                return;
            }
            size.width = width;
            size.height = i3;
            if (this.isPageFinished) {
                setMaxSize();
            }
        }
    }

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

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

    public void cancelAntilockTimer() {
        SimpleTimer simpleTimer = this.mAntilockTimer;
        if (simpleTimer != null) {
            simpleTimer.pause();
            this.mAntilockTimer.cancel();
            this.mAntilockTimer = null;
        }
    }

    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);
        }
    }

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

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

                @Override
                protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
                    super.onLayout(z, i, i2, i3, i4);
                    MRAIDView.this.onLayoutWebView(this, z, i, i2, i3, i4);
                }

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

                @Override
                protected void onWindowVisibilityChanged(int i) {
                    super.onWindowVisibilityChanged(i);
                    int visibility = getVisibility();
                    MRAIDLog.d(TAG, "onWindowVisibilityChanged " + MRAIDView.getVisibilityString(i) + " (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(33554432);
            pNWebView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    MRAIDView.this.wasTouched = true;
                    int action = motionEvent.getAction();
                    if ((action != 0 && action != 1) || view.hasFocus()) {
                        return false;
                    }
                    view.requestFocus();
                    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 e) {
            HyBid.reportException((Exception) e);
            return null;
        }
    }

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

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

    private void forceFullScreen() {
        if (this.context instanceof Activity) {
            MRAIDLog.d(MRAID_LOG_TAG, "forceFullScreen");
            Activity activity = (Activity) this.context;
            int i = activity.getWindow().getAttributes().flags;
            this.isFullScreen = (i & 1024) != 0;
            this.isForceNotFullScreen = (i & 2048) != 0;
            this.origTitleBarVisibility = -9;
            ActionBar actionBar = activity.getActionBar();
            if (actionBar != null) {
                this.isActionBarShowing = actionBar.isShowing();
                actionBar.hide();
            } else {
                this.titleBar = null;
                try {
                    if (activity.findViewById(android.R.id.title) != null) {
                        this.titleBar = (View) activity.findViewById(android.R.id.title).getParent();
                    }
                } catch (NullPointerException e) {
                    HyBid.reportException((Exception) e);
                }
                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 i) {
        return i != -1 ? i != 0 ? i != 1 ? "UNKNOWN" : "PORTRAIT" : "LANDSCAPE" : "UNSPECIFIED";
    }

    private String getStringFromFileUrl(String str) {
        StringBuilder sb = new StringBuilder();
        String[] split = str.split(Constants.SLASH);
        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])));
            try {
                String readLine = bufferedReader.readLine();
                sb.append(readLine);
                while (readLine != null) {
                    readLine = bufferedReader.readLine();
                    sb.append(readLine);
                }
                bufferedReader.close();
            } finally {
            }
        } catch (IOException e) {
            MRAIDLog.e("Error fetching file: " + e.getMessage());
            HyBid.reportException((Exception) e);
        }
        return sb.toString();
    }

    private java.lang.String getStringFromUrl(java.lang.String r9) {
        throw new UnsupportedOperationException("Method not decompiled: net.pubnative.lite.sdk.mraid.MRAIDView.getStringFromUrl(java.lang.String):java.lang.String");
    }

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

    private void handleAntilockDelay() {
        SimpleTimer simpleTimer = new SimpleTimer(5000, new SimpleTimer.Listener() {
            @Override
            public void onFinish() {
                MRAIDViewListener mRAIDViewListener = MRAIDView.this.listener;
                if (mRAIDViewListener != null) {
                    mRAIDViewListener.mraidShowCloseButton();
                }
                MRAIDView.this.showDefaultCloseButton();
                MRAIDView.this.isBackClickable = Boolean.TRUE;
            }

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

    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) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return (str.contains("tags-prod.vrvm.com") || str.contains("ad.vrvm.com")) && str.contains("type=expandable");
    }

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

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

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

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

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

    public void lambda$decodeURL$1(String str) {
        if (this.state == 3) {
            removeResizeView();
            addView(this.webView);
        }
        this.webView.setWebChromeClient(null);
        this.webView.setWebViewClient(null);
        WebView createWebView = createWebView();
        this.webViewPart2 = createWebView;
        createWebView.loadUrl(str);
        MRAIDLog.d("hz-m MRAIDView - expand - switching out currentwebview for " + this.webViewPart2);
        WebView webView = this.webViewPart2;
        this.currentWebView = webView;
        this.isExpandingPart2 = true;
        expandHelper(webView);
    }

    public void lambda$decodeURL$2(String str) {
        if (this.state == 3) {
            removeResizeView();
            addView(this.webView);
        }
        this.webView.setWebChromeClient(null);
        this.webView.setWebViewClient(null);
        WebView createWebView = createWebView();
        this.webViewPart2 = createWebView;
        this.mIsExpanding = true;
        createWebView.loadUrl(str);
        MRAIDLog.d("hz-m MRAIDView - expand - switching out currentwebview for " + this.webViewPart2);
        WebView webView = this.webViewPart2;
        this.currentWebView = webView;
        this.isExpandingPart2 = true;
        expandHelper(webView);
    }

    public void lambda$decodeURL$3(boolean z, final String str) {
        MRAIDLog.d("hz-m MRAIDView - expand - url loading thread");
        if (z) {
            Context context = this.context;
            if (context instanceof Activity) {
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public final void run() {
                        MRAIDView.this.lambda$decodeURL$1(str);
                    }
                });
                return;
            }
            MRAIDLog.e("Could not load part 2 expanded content for URL: " + str);
            return;
        }
        Context context2 = this.context;
        if (context2 instanceof Activity) {
            ((Activity) context2).runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    MRAIDView.this.lambda$decodeURL$2(str);
                }
            });
            return;
        }
        MRAIDLog.e("Could not load part 2 expanded content for URL: " + str);
    }

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

    public void onLayoutWebView(WebView webView, boolean z, int i, int i2, int i3, int i4) {
        boolean z2 = webView == this.currentWebView;
        String str = MRAID_LOG_TAG;
        StringBuilder sb = new StringBuilder();
        sb.append("onLayoutWebView ");
        sb.append(webView == this.webView ? "1 " : "2 ");
        sb.append(z2);
        sb.append(" (");
        sb.append(this.state);
        sb.append(") ");
        sb.append(z);
        sb.append(Constants.SPACE_STRING);
        sb.append(i);
        sb.append(Constants.SPACE_STRING);
        sb.append(i2);
        sb.append(Constants.SPACE_STRING);
        sb.append(i3);
        sb.append(Constants.SPACE_STRING);
        sb.append(i4);
        MRAIDLog.w(str, sb.toString());
        if (!z2) {
            MRAIDLog.d(str, "onLayoutWebView ignored, not current");
            return;
        }
        int i5 = this.state;
        if (i5 == 0 || i5 == 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, "UTF-8");
            StringBuilder sb = new StringBuilder();
            String str2 = MRAID_LOG_TAG;
            sb.append(str2);
            sb.append("-JS callback");
            MRAIDLog.d(sb.toString(), "open " + decode + " touched: " + this.wasTouched);
            if (!this.wasTouched) {
                MRAIDLog.d(str2 + "- JS callback", "open called, but no touch recorded, aborting");
                return;
            }
            if (this.nativeFeatureListener != null) {
                if (decode.startsWith("sms")) {
                    this.nativeFeatureListener.mraidNativeFeatureSendSms(decode);
                } else if (decode.startsWith(MRAIDNativeFeature.TEL)) {
                    this.nativeFeatureListener.mraidNativeFeatureCallTel(decode);
                } else {
                    this.nativeFeatureListener.mraidNativeFeatureOpenBrowser(decode);
                }
            }
        } catch (UnsupportedEncodingException e) {
            HyBid.reportException((Exception) e);
            Logger.e(MRAID_LOG_TAG, e.getMessage());
        }
    }

    public void parseCommandUrl(java.lang.String r9) {
        throw new UnsupportedOperationException("Method not decompiled: net.pubnative.lite.sdk.mraid.MRAIDView.parseCommandUrl(java.lang.String):void");
    }

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

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

    private void removeDefaultCloseButton() {
        ImageButton imageButton = this.closeRegion;
        if (imageButton != null) {
            imageButton.setImageResource(android.R.color.transparent);
        }
    }

    private void removeResizeView() {
        RelativeLayout relativeLayout = this.resizedView;
        if (relativeLayout != null) {
            relativeLayout.removeAllViews();
            Context context = this.context;
            if (context instanceof Activity) {
                ((FrameLayout) ((Activity) context).findViewById(android.R.id.content)).removeView(this.resizedView);
                this.resizedView = null;
                this.closeRegion = null;
            }
        }
    }

    @JavascriptMRAIDCallback
    private void resize() {
        MRAIDLog.d(MRAID_LOG_TAG + "-JS callback", "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(android.R.id.content)).addView(this.resizedView);
            }
            setCloseRegionPosition(this.resizedView);
            setResizedViewSize();
            setResizedViewPosition();
            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 i = this.originalRequestedOrientation;
            if (requestedOrientation != i) {
                activity.setRequestedOrientation(i);
            }
        }
    }

    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) {
                ActionBar actionBar = activity.getActionBar();
                if (actionBar != null) {
                    actionBar.show();
                    return;
                }
                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 i = rect.left;
        int i2 = rect.top;
        int width = rect.width();
        int height = this.currentPosition.height();
        MRAIDLog.d(MRAID_LOG_TAG, "setCurrentPosition [" + i + Constants.COMMA + i2 + "] (" + width + "x" + height + ")");
        injectJavaScript("mraid.setCurrentPosition(" + px2dip(i) + Constants.COMMA + px2dip(i2) + Constants.COMMA + px2dip(width) + Constants.COMMA + px2dip(height) + ");");
    }

    public void setDefaultPosition() {
        Rect rect = this.defaultPosition;
        int i = rect.left;
        int i2 = rect.top;
        int width = rect.width();
        int height = this.defaultPosition.height();
        MRAIDLog.d(MRAID_LOG_TAG, "setDefaultPosition [" + i + Constants.COMMA + i2 + "] (" + width + "x" + height + ")");
        injectJavaScript("mraid.setDefaultPosition(" + px2dip(i) + Constants.COMMA + px2dip(i2) + Constants.COMMA + px2dip(width) + Constants.COMMA + 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(\"3.2.1\");");
        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", Math.round(userLocation.getLatitude() * 100.0d) / 100.0d);
            jSONObject.put("lon", Math.round(userLocation.getLongitude() * 100.0d) / 100.0d);
            jSONObject.put("type", 1);
            jSONObject.put("accuracy", userLocation.getAccuracy());
            jSONObject.put("lastfix", (SystemClock.elapsedRealtimeNanos() - userLocation.getElapsedRealtimeNanos()) / 1000000000);
            injectJavaScript("mraid.setLocation(" + jSONObject + ");");
        } catch (JSONException e) {
            HyBid.reportException((Exception) e);
            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 i = size.width;
        int i2 = size.height;
        MRAIDLog.d(str, "setMaxSize " + i + "x" + i2);
        injectJavaScript("mraid.setMaxSize(" + px2dip(i) + Constants.COMMA + px2dip(i2) + ");");
    }

    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 + Constants.SPACE_STRING + parseInt2 + Constants.SPACE_STRING + parseInt3 + Constants.SPACE_STRING + parseInt4 + Constants.SPACE_STRING + str + Constants.SPACE_STRING + 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 setResizedViewPosition() {
        if (this.displayMetrics != null) {
            MRAIDLog.d(MRAID_LOG_TAG, "setResizedViewPosition");
            if (this.resizedView == null) {
                return;
            }
            MRAIDResizeProperties mRAIDResizeProperties = this.resizeProperties;
            int i = mRAIDResizeProperties.width;
            int i2 = mRAIDResizeProperties.height;
            int i3 = mRAIDResizeProperties.offsetX;
            int i4 = mRAIDResizeProperties.offsetY;
            int applyDimension = (int) TypedValue.applyDimension(1, i, this.displayMetrics);
            int applyDimension2 = (int) TypedValue.applyDimension(1, i2, this.displayMetrics);
            int applyDimension3 = (int) TypedValue.applyDimension(1, i3, this.displayMetrics);
            int applyDimension4 = (int) TypedValue.applyDimension(1, i4, this.displayMetrics);
            Rect rect = this.defaultPosition;
            int i5 = rect.left + applyDimension3;
            int i6 = rect.top + applyDimension4;
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this.resizedView.getLayoutParams();
            layoutParams.leftMargin = i5;
            layoutParams.topMargin = i6;
            this.resizedView.setLayoutParams(layoutParams);
            Rect rect2 = this.currentPosition;
            if (i5 == rect2.left && i6 == rect2.top && applyDimension == rect2.width() && applyDimension2 == this.currentPosition.height()) {
                return;
            }
            Rect rect3 = this.currentPosition;
            rect3.left = i5;
            rect3.top = i6;
            rect3.right = i5 + applyDimension;
            rect3.bottom = i6 + applyDimension2;
            setCurrentPosition();
        }
    }

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

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

    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 i) {
        boolean z = i == 0;
        if (z != this.isViewable) {
            this.isViewable = z;
            if (this.isPageFinished && this.isLaidOut) {
                fireViewableChangeEvent();
                fireExposureChangeEvent();
            }
        }
    }

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

    public void startSkipTimer() {
        Integer num;
        if (this.useCustomClose) {
            handleNativeCloseButtonDelay();
            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();
                    MRAIDView.this.isBackClickable = Boolean.TRUE;
                    if (MRAIDView.this.mSkipCountdownView != null) {
                        MRAIDView.this.mSkipCountdownView.setVisibility(8);
                    }
                }

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

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

    @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 (this.mViewabilityFriendlyObstructions == null || view == null || TextUtils.isEmpty(str)) {
            return;
        }
        this.mViewabilityFriendlyObstructions.add(new HyBidViewabilityFriendlyObstruction(view, friendlyObstructionPurpose, str));
    }

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

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

    @JavascriptMRAIDCallback
    protected 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();
            }
        });
    }

    protected void closeFromExpanded() {
        FrameLayout frameLayout;
        int i = this.state;
        if (i == 2 || i == 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(android.R.id.content)) == 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$4();
            }
        });
        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$5();
            }
        });
    }

    protected 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$6();
            }
        });
    }

    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
    @Deprecated
    protected void expand(String str) {
        if (this.isExpandEnabled && this.wasTouched) {
            expandCreative(str, false, Boolean.FALSE);
        }
    }

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

    protected 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;
    }

    protected void fireExposureChangeEvent() {
        double d = this.isViewable ? 100.0d : 0.0d;
        MRAIDLog.d(MRAID_LOG_TAG, "fireExposureChangeEvent");
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("x", getX());
            jSONObject.put("y", getY());
            jSONObject.put("width", (getWidth() * d) / 100.0d);
            jSONObject.put("height", (getHeight() * d) / 100.0d);
        } catch (JSONException e) {
            HyBid.reportException((Exception) e);
            Logger.e(MRAID_LOG_TAG, e.getMessage());
        }
        injectJavaScript("mraid.fireExposureChangeEvent(" + d + Constants.COMMA + jSONObject + ",null);");
    }

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

    protected void fireStateChangeEvent() {
        MRAIDLog.d(MRAID_LOG_TAG, "fireStateChangeEvent");
        injectJavaScript("mraid.fireStateChangeEvent('" + new String[]{"loading", "default", "expanded", "resized", "hidden"}[this.state] + "');");
    }

    protected 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();
                MRAIDView.this.isBackClickable = Boolean.TRUE;
            }

            @Override
            public void onTick(long j) {
            }
        }, 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
    protected void onAttachedToWindow() {
        MRAIDLog.d(MRAID_LOG_TAG, "onAttachedToWindow");
        super.onAttachedToWindow();
    }

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

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

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

    @Override
    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        String str = MRAID_LOG_TAG;
        MRAIDLog.w(str, "onLayout (" + this.state + ") " + z + Constants.SPACE_STRING + i + Constants.SPACE_STRING + i2 + Constants.SPACE_STRING + i3 + Constants.SPACE_STRING + i4);
        if (this.isForcingFullScreen) {
            MRAIDLog.d(str, "onLayout ignored");
            return;
        }
        int i5 = this.state;
        if (i5 == 2 || i5 == 3) {
            calculateScreenSize();
            calculateMaxSize();
        }
        if (this.isClosing) {
            this.isClosing = false;
            this.currentPosition = new Rect(this.defaultPosition);
            setCurrentPosition();
        } else {
            calculatePosition(false);
        }
        if (this.state == 3 && z) {
            this.handler.post(new Runnable() {
                @Override
                public final void run() {
                    MRAIDView.this.setResizedViewPosition();
                }
            });
        }
        this.isLaidOut = true;
        onLayoutCompleted();
    }

    protected void onLayoutCompleted() {
    }

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

    @Override
    protected void onVisibilityChanged(View view, int i) {
        super.onVisibilityChanged(view, i);
        MRAIDLog.d(MRAID_LOG_TAG, "onVisibilityChanged " + getVisibilityString(i));
        setViewable(i);
    }

    @Override
    protected void onWindowVisibilityChanged(int i) {
        super.onWindowVisibilityChanged(i);
        int visibility = getVisibility();
        MRAIDLog.d(MRAID_LOG_TAG, "onWindowVisibilityChanged " + getVisibilityString(i) + " (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();
        }
        SimpleTimer simpleTimer3 = this.mAntilockTimer;
        if (simpleTimer3 != null) {
            simpleTimer3.pause();
        }
    }

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

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

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

    @JavascriptMRAIDCallback
    protected 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 + Constants.SPACE_STRING + 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();
        }
    }

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

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

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

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

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

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

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