Wolves Themes v1.0版本的 MD5 值为:cddc92b47f6b7c4a195c9625507eb51c
以下内容为反编译后的 MRAIDView.java 源代码,内容仅作参考
package org.nexage.sourcekit.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.Point;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.ConsoleMessage;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import com.google.android.gms.common.ConnectionResult;
import com.ironsource.sdk.constants.Constants;
import com.mopub.common.AdType;
import com.tapjoy.TJAdUnitConstants;
import com.yandex.mobile.ads.video.tracking.Tracker;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import org.nexage.sourcekit.Settings;
import org.nexage.sourcekit.mraid.internal.MRAIDHtmlProcessor;
import org.nexage.sourcekit.mraid.internal.MRAIDLog;
import org.nexage.sourcekit.mraid.internal.MRAIDNativeFeatureManager;
import org.nexage.sourcekit.mraid.internal.MRAIDParser;
import org.nexage.sourcekit.mraid.properties.MRAIDOrientationProperties;
import org.nexage.sourcekit.mraid.properties.MRAIDResizeProperties;
import org.nexage.sourcekit.vast.view.CircleCountdownView;
@SuppressLint({"ViewConstructor"})
public class MRAIDView extends RelativeLayout {
private static final int CLOSE_REGION_SIZE = 50;
private static final int PROGRESS_TIMER_INTERVAL = 40;
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 static final String TAG = "MRAIDView";
public static final String VERSION = "1.1.1";
private String baseUrl;
private CircleCountdownView closeRegion;
private int closeTime;
private int closeTimerPosition;
private int contentViewTop;
private Context context;
private Rect currentPosition;
private WebView currentWebView;
private Rect defaultPosition;
private DisplayMetrics displayMetrics;
private RelativeLayout expandedView;
private GestureDetector gestureDetector;
private Handler handler;
private Activity interstitialActivity;
private boolean isActionBarShowing;
private boolean isCloseClickable;
private boolean isClosing;
private boolean isExpandingFromDefault;
private boolean isExpandingPart2;
private boolean isForceNotFullScreen;
private boolean isForcingFullScreen;
private boolean isFullScreen;
private final boolean isInterstitial;
private boolean isLaidOut;
private boolean isPageFinished;
private boolean isShown;
private final boolean isTag;
private boolean isTouched;
private boolean isViewable;
private MRAIDViewListener listener;
private String mData;
private Size maxSize;
private String mraidJs;
private boolean mraidViewOnLayoutCalledOnce;
private MRAIDWebChromeClient mraidWebChromeClient;
private MRAIDWebViewClient mraidWebViewClient;
private MRAIDNativeFeatureListener nativeFeatureListener;
private MRAIDNativeFeatureManager nativeFeatureManager;
private MRAIDOrientationProperties orientationProperties;
private int origTitleBarVisibility;
private final int originalRequestedOrientation;
private String placementId;
private boolean preload;
private MRAIDResizeProperties resizeProperties;
private RelativeLayout resizedView;
private Size screenSize;
private String segmentId;
private int state;
private View titleBar;
private boolean useCustomClose;
private WebView webView;
private WebView webViewPart2;
public class MRAIDWebChromeClient extends WebChromeClient {
private MRAIDWebChromeClient() {
}
private boolean handlePopups(JsResult jsResult) {
jsResult.cancel();
return true;
}
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
String str;
if (consoleMessage == null || consoleMessage.message() == null) {
return false;
}
if (!consoleMessage.message().contains("Uncaught ReferenceError")) {
StringBuilder sb = new StringBuilder();
sb.append(consoleMessage.message());
if (consoleMessage.sourceId() == null) {
str = "";
} else {
str = " at " + consoleMessage.sourceId();
}
sb.append(str);
sb.append(":");
sb.append(consoleMessage.lineNumber());
MRAIDLog.i("JS console", sb.toString());
}
if (consoleMessage.message().contains("AppodealAlert")) {
Log.e("Appodeal", consoleMessage.message().replace("AppodealAlert:", ""));
return true;
}
return true;
}
@Override
public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
MRAIDLog.d("JS alert", str2);
return handlePopups(jsResult);
}
@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);
}
}
public class MRAIDWebViewClient extends WebViewClient {
private MRAIDWebViewClient() {
}
@Override
public void onPageFinished(WebView webView, String str) {
MRAIDLog.d(MRAIDView.TAG, "onPageFinished: " + str);
super.onPageFinished(webView, str);
if (MRAIDView.this.state == 0) {
MRAIDView.this.isPageFinished = true;
MRAIDView mRAIDView = MRAIDView.this;
StringBuilder sb = new StringBuilder();
sb.append("mraid.setPlacementType('");
sb.append(MRAIDView.this.isInterstitial ? AdType.INTERSTITIAL : TJAdUnitConstants.String.INLINE);
sb.append("');");
mRAIDView.injectJavaScript(sb.toString());
MRAIDView.this.setSupportedServices();
if (MRAIDView.this.isLaidOut) {
MRAIDView.this.setScreenSize();
MRAIDView.this.setMaxSize();
MRAIDView.this.setCurrentPosition();
MRAIDView.this.setDefaultPosition();
if (MRAIDView.this.isInterstitial) {
MRAIDView.this.showAsInterstitial(null);
} else {
MRAIDView.this.state = 1;
MRAIDView.this.fireStateChangeEvent();
MRAIDView.this.fireReadyEvent();
if (MRAIDView.this.isViewable) {
MRAIDView.this.fireViewableChangeEvent();
}
}
}
if (MRAIDView.this.listener != null && !str.equals("data:text/html,<html></html>") && MRAIDView.this.preload && !MRAIDView.this.isTag) {
MRAIDView.this.listener.mraidViewLoaded(MRAIDView.this);
}
}
if (MRAIDView.this.isExpandingPart2) {
MRAIDView.this.isExpandingPart2 = false;
MRAIDView.this.handler.post(new Runnable() {
@Override
public void run() {
MRAIDView mRAIDView2 = MRAIDView.this;
StringBuilder sb2 = new StringBuilder();
sb2.append("mraid.setPlacementType('");
sb2.append(MRAIDView.this.isInterstitial ? AdType.INTERSTITIAL : TJAdUnitConstants.String.INLINE);
sb2.append("');");
mRAIDView2.injectJavaScript(sb2.toString());
MRAIDView.this.setSupportedServices();
MRAIDView.this.setScreenSize();
MRAIDView.this.setDefaultPosition();
MRAIDLog.d(MRAIDView.TAG, "calling fireStateChangeEvent 2");
MRAIDView.this.fireStateChangeEvent();
MRAIDView.this.fireReadyEvent();
if (MRAIDView.this.isViewable) {
MRAIDView.this.fireViewableChangeEvent();
}
}
});
}
}
@Override
public void onReceivedError(WebView webView, int i, String str, String str2) {
MRAIDLog.d(MRAIDView.TAG, "onReceivedError: " + str);
super.onReceivedError(webView, i, str, str2);
}
@Override
@TargetApi(26)
public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail renderProcessGoneDetail) {
MRAIDLog.d(MRAIDView.TAG, String.format("onRenderProcessGone didCrash: %s", Boolean.valueOf(renderProcessGoneDetail.didCrash())));
MRAIDView.this.removeView(MRAIDView.this.webView);
MRAIDView.this.webView.destroy();
MRAIDView.this.addWebView();
MRAIDView.this.load();
return true;
}
@Override
@TargetApi(24)
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
if (webResourceRequest.hasGesture()) {
MRAIDView.this.isTouched = true;
}
return shouldOverrideUrlLoading(webView, webResourceRequest.getUrl().toString());
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
MRAIDLog.d(MRAIDView.TAG, "shouldOverrideUrlLoading: " + str);
if (str.startsWith("mraid://")) {
MRAIDView.this.parseCommandUrl(str);
return true;
}
MRAIDView.this.open(str, webView);
return true;
}
}
public final class Size {
public int height;
public int width;
private Size() {
}
}
public static class builder {
String baseUrl;
Context context;
String data;
int height;
boolean isTag;
@VisibleForTesting
public MRAIDViewListener listener;
@VisibleForTesting
public MRAIDNativeFeatureListener nativeFeatureListener;
boolean preload;
boolean useLayout;
int width;
String[] supportedNativeFeatures = null;
boolean isInterstitial = false;
int closeTime = -1;
public builder(Context context, String str, int i, int i2) {
this.context = context;
this.data = str;
this.width = i;
this.height = i2;
}
public MRAIDView build() {
return new MRAIDView(this);
}
public builder setBaseUrl(String str) {
this.baseUrl = str;
return this;
}
public builder setCloseTime(int i) {
this.closeTime = i;
return this;
}
public builder setIsInterstitial(boolean z) {
this.isInterstitial = z;
return this;
}
public builder setIsTag(boolean z) {
this.isTag = z;
return this;
}
public builder setListener(MRAIDViewListener mRAIDViewListener) {
this.listener = mRAIDViewListener;
return this;
}
public builder setNativeFeatureListener(MRAIDNativeFeatureListener mRAIDNativeFeatureListener) {
this.nativeFeatureListener = mRAIDNativeFeatureListener;
return this;
}
public builder setPreload(boolean z) {
this.preload = z;
return this;
}
public builder setSupportedNativeFeatures(String[] strArr) {
this.supportedNativeFeatures = strArr;
return this;
}
public builder setUseLayout(boolean z) {
this.useLayout = z;
return this;
}
}
private MRAIDView(builder builderVar) {
super(builderVar.context);
this.isShown = false;
this.isCloseClickable = true;
this.isTouched = false;
this.closeTimerPosition = 0;
if (builderVar.supportedNativeFeatures == null) {
builderVar.supportedNativeFeatures = new String[0];
}
this.context = builderVar.context;
this.baseUrl = builderVar.baseUrl;
this.isInterstitial = builderVar.isInterstitial;
this.preload = builderVar.preload;
this.closeTime = builderVar.closeTime;
this.isTag = builderVar.isTag;
this.mraidViewOnLayoutCalledOnce = Settings.mraidViewOnLayoutCalledOnce;
this.state = 0;
this.isViewable = false;
this.useCustomClose = false;
this.orientationProperties = new MRAIDOrientationProperties();
this.resizeProperties = new MRAIDResizeProperties();
this.nativeFeatureManager = new MRAIDNativeFeatureManager(this.context, new ArrayList(Arrays.asList(builderVar.supportedNativeFeatures)));
this.listener = builderVar.listener;
this.nativeFeatureListener = builderVar.nativeFeatureListener;
this.displayMetrics = new DisplayMetrics();
((Activity) this.context).getWindowManager().getDefaultDisplay().getMetrics(this.displayMetrics);
this.currentPosition = new Rect();
this.defaultPosition = new Rect();
this.maxSize = new Size();
this.screenSize = new Size();
this.originalRequestedOrientation = this.context instanceof Activity ? ((Activity) this.context).getRequestedOrientation() : -1;
MRAIDLog.d(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.mraidWebChromeClient = new MRAIDWebChromeClient();
this.mraidWebViewClient = new MRAIDWebViewClient();
String replace = getMraidJs().replace("%%VERSION%%", Settings.mediatorVersion);
builderVar.data = MRAIDHtmlProcessor.processRawHtml(builderVar.data);
Display defaultDisplay = ((WindowManager) this.context.getSystemService("window")).getDefaultDisplay();
Point point = new Point();
defaultDisplay.getSize(point);
DisplayMetrics displayMetrics = new DisplayMetrics();
defaultDisplay.getMetrics(displayMetrics);
float f = displayMetrics.density;
int i = point.x;
int round = this.isInterstitial ? point.y : Math.round(builderVar.height * f);
float f2 = i;
float f3 = round;
float f4 = f2 / f3;
float f5 = builderVar.width / builderVar.height;
if (!Float.isNaN(f5)) {
if (f5 <= f4) {
i = Math.round(f3 * f5);
} else {
round = Math.round(f2 / f5);
}
}
int round2 = Math.round(i / f);
int round3 = Math.round(round / f);
if (round2 > builderVar.width && round3 > builderVar.height && builderVar.width != 0 && builderVar.height != 0) {
round2 = builderVar.width;
round3 = builderVar.height;
}
MRAIDLog.d(String.format("use layout: %s", Boolean.valueOf(builderVar.useLayout)));
this.mData = builderVar.useLayout ? String.format("<style type='text/css'>%s</style><script type='application/javascript'>%s</script><div class='appodeal-outer'><div class='appodeal-middle'><div class='appodeal-inner'>%s</div></div></div>", String.format("body, p {margin:0; padding:0} img {max-width:%dpx; max-height:%dpx} #appnext-interstitial {min-width:%dpx; min-height:%dpx;}img[width='%d'][height='%d'] {width: %dpx; height: %dpx} .appodeal-outer {display: table; position: absolute; height: 100%%; width: 100%%;}.appodeal-middle {display: table-cell; vertical-align: middle;}.appodeal-inner {margin-left: auto; margin-right: auto; width: %dpx; height: %dpx;}.ad_slug_table {margin-left: auto !important; margin-right: auto !important;} #ad[align='center'] {height: %dpx;} #voxelPlayer {position: relative !important;} #lsm_mobile_ad #wrapper, #lsm_overlay {position: relative !important;}", Integer.valueOf(round2), Integer.valueOf(round3), Integer.valueOf(round2), Integer.valueOf(round3), Integer.valueOf(builderVar.width), Integer.valueOf(builderVar.height), Integer.valueOf(round2), Integer.valueOf(round3), Integer.valueOf(round2), Integer.valueOf(round3), Integer.valueOf(round3)), replace, builderVar.data) : String.format("<script type='application/javascript'>%s</script>%s", replace, builderVar.data);
addWebView();
}
private void addCloseRegion(View view) {
this.closeRegion = new CircleCountdownView(this.context);
this.closeRegion.setBackgroundColor(0);
this.closeRegion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
MRAIDView.this.close();
}
});
if (view == this.expandedView && !this.useCustomClose) {
showDefaultCloseButton();
}
((ViewGroup) view).addView(this.closeRegion);
}
public void addWebView() {
WebView createWebView = createWebView();
this.currentWebView = createWebView;
this.webView = createWebView;
addView(this.webView);
}
private void applyOrientationProperties() {
MRAIDLog.d(TAG, "applyOrientationProperties " + this.orientationProperties.allowOrientationChange + " " + this.orientationProperties.forceOrientationString());
if (this.interstitialActivity != null) {
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(TAG, sb.toString());
if (this.orientationProperties.forceOrientation == 0) {
i = 1;
} else if (this.orientationProperties.forceOrientation != 1) {
i = this.orientationProperties.allowOrientationChange ? -1 : i2;
}
this.interstitialActivity.setRequestedOrientation(i);
}
}
private void calculateMaxSize() {
Rect rect = new Rect();
Window window = ((Activity) this.context).getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rect);
MRAIDLog.d(TAG, "calculateMaxSize frame [" + rect.left + "," + rect.top + "][" + rect.right + "," + rect.bottom + "] (" + rect.width() + "x" + rect.height() + ")");
int i = rect.top;
View findViewById = window.findViewById(16908290);
this.contentViewTop = 0;
if (findViewById != null) {
this.contentViewTop = findViewById.getTop();
int i2 = this.contentViewTop - i;
MRAIDLog.d(TAG, "calculateMaxSize statusHeight " + i);
MRAIDLog.d(TAG, "calculateMaxSize titleHeight " + i2);
MRAIDLog.d(TAG, "calculateMaxSize contentViewTop " + this.contentViewTop);
}
int width = rect.width();
int i3 = this.screenSize.height - this.contentViewTop;
MRAIDLog.d(TAG, "calculateMaxSize max size " + width + "x" + i3);
if (width == this.maxSize.width && i3 == this.maxSize.height) {
return;
}
this.maxSize.width = width;
this.maxSize.height = i3;
if (this.isPageFinished) {
setMaxSize();
}
}
private void calculatePosition(boolean z) {
int[] iArr = new int[2];
View view = z ? this.currentWebView : this;
String str = z ? "current" : "default";
view.getLocationOnScreen(iArr);
int i = iArr[0];
int i2 = iArr[1];
MRAIDLog.d(TAG, "calculatePosition " + str + " locationOnScreen [" + i + "," + i2 + Constants.RequestParameters.RIGHT_BRACKETS);
StringBuilder sb = new StringBuilder();
sb.append("calculatePosition ");
sb.append(str);
sb.append(" contentViewTop ");
sb.append(this.contentViewTop);
MRAIDLog.d(TAG, sb.toString());
int i3 = i2 - this.contentViewTop;
int width = view.getWidth();
int height = view.getHeight();
MRAIDLog.d(TAG, "calculatePosition " + str + " position [" + i + "," + 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;
StringBuilder sb = new StringBuilder();
sb.append("calculateScreenSize orientation ");
sb.append(z ? "portrait" : "landscape");
MRAIDLog.d(TAG, sb.toString());
int i = this.displayMetrics.widthPixels;
int i2 = this.displayMetrics.heightPixels;
MRAIDLog.d(TAG, "calculateScreenSize screen size " + i + "x" + i2);
if (i == this.screenSize.width && i2 == this.screenSize.height) {
return;
}
this.screenSize.width = i;
this.screenSize.height = i2;
if (this.isPageFinished) {
setScreenSize();
}
}
public void close() {
MRAIDLog.d("MRAIDView-JS callback", "close");
if (this.isCloseClickable || this.useCustomClose) {
this.handler.post(new Runnable() {
@Override
public void run() {
if (MRAIDView.this.state != 0) {
if ((MRAIDView.this.state != 1 || MRAIDView.this.isInterstitial) && MRAIDView.this.state != 4) {
if (MRAIDView.this.state == 1 || MRAIDView.this.state == 2) {
MRAIDView.this.closeFromExpanded();
} else if (MRAIDView.this.state == 3) {
MRAIDView.this.closeFromResized();
}
}
}
}
});
}
}
public void closeFromExpanded() {
if (this.state == 1 && this.isInterstitial) {
this.state = 4;
this.handler.post(new Runnable() {
@Override
public void run() {
MRAIDView.this.fireStateChangeEvent();
if (MRAIDView.this.listener != null) {
MRAIDView.this.listener.mraidViewClose(MRAIDView.this);
}
MRAIDView.this.clearView();
}
});
} else if (this.state == 2 || this.state == 3) {
this.state = 1;
}
this.isClosing = true;
this.expandedView.removeAllViews();
FrameLayout frameLayout = (FrameLayout) ((Activity) this.context).findViewById(16908290);
if (frameLayout != null) {
frameLayout.removeView(this.expandedView);
}
this.expandedView = null;
this.closeRegion = null;
this.handler.post(new Runnable() {
@Override
public void run() {
MRAIDView.this.restoreOriginalOrientation();
MRAIDView.this.restoreOriginalScreenState();
}
});
if (this.webViewPart2 == null) {
addView(this.webView);
} else {
this.webViewPart2.setWebChromeClient(null);
this.webViewPart2.setWebViewClient(null);
WebView webView = this.webViewPart2;
this.webViewPart2 = null;
webView.destroy();
this.webView.setWebChromeClient(this.mraidWebChromeClient);
this.webView.setWebViewClient(this.mraidWebViewClient);
this.currentWebView = this.webView;
}
this.handler.post(new Runnable() {
@Override
public void run() {
MRAIDView.this.fireStateChangeEvent();
if (MRAIDView.this.listener != null) {
MRAIDView.this.listener.mraidViewClose(MRAIDView.this);
}
}
});
}
public void closeFromResized() {
this.state = 1;
this.isClosing = true;
removeResizeView();
addView(this.webView);
this.handler.post(new Runnable() {
@Override
public void run() {
MRAIDView.this.fireStateChangeEvent();
if (MRAIDView.this.listener != null) {
MRAIDView.this.listener.mraidViewClose(MRAIDView.this);
}
}
});
}
private void createCalendarEvent(String str) {
MRAIDLog.d("MRAIDView-JS callback", "createCalendarEvent " + str);
if (this.nativeFeatureListener != null) {
this.nativeFeatureListener.mraidNativeFeatureCreateCalendarEvent(str);
}
}
@SuppressLint({"SetJavaScriptEnabled"})
public WebView createWebView() {
WebView webView = new WebView(this.context.getApplicationContext()) {
private static final String TAG = "MRAIDView-WebView";
@Override
public void computeScroll() {
}
@Override
public void onConfigurationChanged(Configuration configuration) {
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) {
((Activity) MRAIDView.this.context).getWindowManager().getDefaultDisplay().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);
}
if (i != 0) {
MRAIDView.this.pauseWebView(this);
} else {
MRAIDView.this.resumeWebView(this);
}
}
@Override
protected boolean overScrollBy(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, boolean z) {
return false;
}
};
webView.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
webView.setScrollContainer(false);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.setScrollBarStyle(33554432);
webView.setFocusableInTouchMode(false);
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
@SuppressLint({"ClickableViewAccessibility"})
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case 0:
case 1:
MRAIDView.this.isTouched = true;
if (view.hasFocus()) {
return false;
}
view.requestFocus();
return false;
default:
return false;
}
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= 17 && this.isInterstitial) {
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
}
webView.setWebChromeClient(this.mraidWebChromeClient);
webView.setWebViewClient(this.mraidWebViewClient);
webView.setBackgroundColor(0);
return webView;
}
@TargetApi(11)
private void expand(String str, final Activity activity) {
StringBuilder sb = new StringBuilder();
sb.append("expand ");
sb.append(str != null ? str : "(1-part)");
MRAIDLog.d("MRAIDView-JS callback", sb.toString());
if (!this.isInterstitial || this.state == 0) {
if (this.isInterstitial || this.state == 1 || this.state == 3) {
if (TextUtils.isEmpty(str)) {
if (this.isInterstitial || this.state == 1) {
if (this.webView.getParent() != null) {
((ViewGroup) this.webView.getParent()).removeView(this.webView);
} else {
removeView(this.webView);
}
} else if (this.state == 3) {
removeResizeView();
}
expandHelper(this.webView, activity);
return;
}
try {
final String decode = URLDecoder.decode(str, "UTF-8");
if (!decode.startsWith("http://") && !decode.startsWith("https://")) {
decode = this.baseUrl + decode;
}
new Thread(new Runnable() {
@Override
public void run() {
final String stringFromUrl = MRAIDView.this.getStringFromUrl(decode);
if (!TextUtils.isEmpty(stringFromUrl)) {
((Activity) MRAIDView.this.context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (MRAIDView.this.state == 3) {
MRAIDView.this.removeResizeView();
MRAIDView.this.addView(MRAIDView.this.webView);
}
MRAIDView.this.webView.setWebChromeClient(null);
MRAIDView.this.webView.setWebViewClient(null);
MRAIDView.this.webViewPart2 = MRAIDView.this.createWebView();
MRAIDView.this.webViewPart2.loadDataWithBaseURL(MRAIDView.this.baseUrl, stringFromUrl, "text/html", "UTF-8", null);
MRAIDView.this.currentWebView = MRAIDView.this.webViewPart2;
MRAIDView.this.isExpandingPart2 = true;
MRAIDView.this.expandHelper(MRAIDView.this.currentWebView, activity);
}
});
return;
}
MRAIDLog.e("Could not load part 2 expanded content for URL: " + decode);
}
}, "2-part-content").start();
} catch (UnsupportedEncodingException unused) {
}
}
}
}
public void expandHelper(WebView webView, Activity activity) {
RelativeLayout relativeLayout;
RelativeLayout.LayoutParams layoutParams;
if (!this.isInterstitial) {
this.state = 2;
}
applyOrientationProperties();
forceFullScreen();
this.expandedView = new RelativeLayout(this.context);
this.expandedView.addView(webView);
addCloseRegion(this.expandedView);
setCloseRegionPosition(this.expandedView);
if (!this.preload) {
webView.loadDataWithBaseURL(this.baseUrl, this.mData, "text/html", "UTF-8", null);
}
if (activity != null) {
relativeLayout = this.expandedView;
layoutParams = new RelativeLayout.LayoutParams(-1, -1);
} else {
activity = (Activity) this.context;
relativeLayout = this.expandedView;
layoutParams = new RelativeLayout.LayoutParams(-1, -1);
}
activity.addContentView(relativeLayout, layoutParams);
this.isExpandingFromDefault = true;
if (this.isInterstitial) {
this.isLaidOut = true;
this.state = 1;
fireStateChangeEvent();
}
}
public void fireReadyEvent() {
MRAIDLog.d(TAG, "fireReadyEvent");
injectJavaScript("mraid.fireReadyEvent();");
}
@SuppressLint({"DefaultLocale"})
public void fireStateChangeEvent() {
MRAIDLog.d(TAG, "fireStateChangeEvent");
injectJavaScript("mraid.fireStateChangeEvent('" + new String[]{"loading", "default", "expanded", "resized", "hidden"}[this.state] + "');");
}
public void fireViewableChangeEvent() {
MRAIDLog.d(TAG, "fireViewableChangeEvent");
if (this.isViewable) {
injectJavaScript(String.format("appodealXSetSegmentAndPlacement('%s', '%s');", this.segmentId, this.placementId));
}
injectJavaScript("mraid.fireViewableChangeEvent(" + this.isViewable + ");");
}
private void forceFullScreen() {
MRAIDLog.d(TAG, "forceFullScreen");
Activity activity = (Activity) this.context;
int i = activity.getWindow().getAttributes().flags;
boolean z = false;
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();
z = true;
}
if (!z) {
this.titleBar = null;
try {
this.titleBar = (View) activity.findViewById(16908310).getParent();
} catch (NullPointerException unused) {
}
if (this.titleBar != null) {
this.origTitleBarVisibility = this.titleBar.getVisibility();
this.titleBar.setVisibility(8);
}
}
MRAIDLog.d(TAG, "isFullScreen " + this.isFullScreen);
MRAIDLog.d(TAG, "isForceNotFullScreen " + this.isForceNotFullScreen);
MRAIDLog.d(TAG, "isActionBarShowing " + this.isActionBarShowing);
MRAIDLog.d(TAG, "origTitleBarVisibility " + getVisibilityString(this.origTitleBarVisibility));
this.isForcingFullScreen = this.isFullScreen ^ true;
}
private String getMraidJs() {
return TextUtils.isEmpty(this.mraidJs) ? new String(Base64.decode(Assets.mraidJS, 0)) : this.mraidJs;
}
private static String getOrientationString(int i) {
switch (i) {
case -1:
return "UNSPECIFIED";
case 0:
return "LANDSCAPE";
case 1:
return "PORTRAIT";
default:
return "UNKNOWN";
}
}
private String getStringFromFileUrl(String str) {
StringBuilder sb = new StringBuilder("");
String[] split = str.split("/");
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();
while (true) {
sb.append(readLine);
if (readLine != null) {
readLine = bufferedReader.readLine();
} else {
try {
break;
} catch (Exception unused) {
}
}
}
bufferedReader.close();
} catch (IOException e) {
MRAIDLog.e("Error fetching file: " + e.getMessage());
}
return sb.toString();
}
public String getStringFromUrl(String str) {
String str2;
HttpURLConnection httpURLConnection;
if (str.startsWith("file:///")) {
return getStringFromFileUrl(str);
}
InputStream inputStream = null;
try {
try {
httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
int responseCode = httpURLConnection.getResponseCode();
MRAIDLog.d(TAG, "response code " + responseCode);
if (responseCode == 200) {
MRAIDLog.d(TAG, "getContentLength " + httpURLConnection.getContentLength());
InputStream inputStream2 = httpURLConnection.getInputStream();
try {
try {
byte[] bArr = new byte[ConnectionResult.DRIVE_EXTERNAL_STORAGE_REQUIRED];
StringBuilder sb = new StringBuilder();
while (true) {
int read = inputStream2.read(bArr);
if (read == -1) {
break;
}
sb.append(new String(bArr, 0, read));
}
str2 = sb.toString();
} catch (Throwable th) {
th = th;
inputStream = inputStream2;
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException unused) {
}
}
throw th;
}
} catch (IOException e) {
e = e;
str2 = null;
}
try {
MRAIDLog.d(TAG, "getStringFromUrl ok, length=" + str2.length());
inputStream = inputStream2;
} catch (IOException e2) {
e = e2;
inputStream = inputStream2;
MRAIDLog.e(TAG, "getStringFromUrl failed " + e.getLocalizedMessage());
}
} else {
str2 = null;
}
} catch (Throwable th2) {
th = th2;
}
} catch (IOException e3) {
e = e3;
str2 = null;
}
try {
httpURLConnection.disconnect();
} catch (IOException e4) {
e = e4;
MRAIDLog.e(TAG, "getStringFromUrl failed " + e.getLocalizedMessage());
}
}
public static String getVisibilityString(int i) {
return i != 0 ? i != 4 ? i != 8 ? "UNKNOWN" : "GONE" : "INVISIBLE" : "VISIBLE";
}
@SuppressLint({"NewApi"})
private void injectJavaScript(WebView webView, String str) {
StringBuilder sb;
if (TextUtils.isEmpty(str) || webView == null) {
return;
}
if (Build.VERSION.SDK_INT >= 19) {
try {
MRAIDLog.d(TAG, "evaluating js: " + str);
webView.evaluateJavascript(str, new ValueCallback<String>() {
@Override
public void onReceiveValue(String str2) {
}
});
return;
} catch (Exception e) {
MRAIDLog.e(e.getMessage());
MRAIDLog.d(TAG, "loading url: " + str);
sb = new StringBuilder();
}
} else {
MRAIDLog.d(TAG, "loading url: " + str);
sb = new StringBuilder();
}
sb.append("javascript:");
sb.append(str);
webView.loadUrl(sb.toString());
}
@SuppressLint({"NewApi"})
public void injectJavaScript(String str) {
injectJavaScript(this.currentWebView, str);
}
private void loaded() {
MRAIDLog.d("MRAIDView-JS callback", Constants.ParametersKeys.LOADED);
if (this.listener != null) {
this.listener.mraidViewLoaded(this);
}
}
private void noFill() {
MRAIDLog.d("MRAIDView-JS callback", "noFill");
if (this.listener != null) {
this.listener.mraidViewNoFill(this);
}
}
public void onLayoutWebView(WebView webView, boolean z, int i, int i2, int i3, int i4) {
boolean z2 = webView == this.currentWebView;
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(" ");
sb.append(i);
sb.append(" ");
sb.append(i2);
sb.append(" ");
sb.append(i3);
sb.append(" ");
sb.append(i4);
MRAIDLog.w(TAG, sb.toString());
if (!z2) {
MRAIDLog.d(TAG, "onLayoutWebView ignored, not current");
} else if (this.isForcingFullScreen && !this.mraidViewOnLayoutCalledOnce) {
MRAIDLog.d(TAG, "onLayoutWebView ignored, isForcingFullScreen");
this.isForcingFullScreen = false;
} else {
if (this.state == 0 || this.state == 1) {
calculateScreenSize();
calculateMaxSize();
}
if (!this.isClosing) {
calculatePosition(true);
if (this.isInterstitial && !this.defaultPosition.equals(this.currentPosition)) {
this.defaultPosition = new Rect(this.currentPosition);
setDefaultPosition();
setCurrentPosition();
}
}
if (this.isExpandingFromDefault) {
this.isExpandingFromDefault = false;
if (this.isInterstitial) {
this.state = 1;
this.isLaidOut = true;
}
if (!this.isExpandingPart2) {
MRAIDLog.d(TAG, "calling fireStateChangeEvent 1");
fireStateChangeEvent();
}
if (this.isInterstitial) {
fireReadyEvent();
if (this.isViewable) {
fireViewableChangeEvent();
}
}
if (this.listener != null) {
this.listener.mraidViewExpand(this);
}
}
}
}
private void open(String str) {
open(str, null);
}
public void open(String str, WebView webView) {
if (!this.isTouched) {
MRAIDLog.d(TAG, "mraid view not touched");
return;
}
MRAIDLog.d("MRAIDView-JS callback", "open " + str);
if (this.nativeFeatureListener != null) {
if (str.startsWith("sms")) {
this.nativeFeatureListener.mraidNativeFeatureSendSms(str);
} else if (str.startsWith("tel")) {
this.nativeFeatureListener.mraidNativeFeatureCallTel(str);
} else {
this.nativeFeatureListener.mraidNativeFeatureOpenBrowser(str, webView);
}
trackAppodealXClick();
}
}
public void parseCommandUrl(String str) {
MRAIDLog.d(TAG, "parseCommandUrl " + str);
Map<String, String> parseCommandUrl = new MRAIDParser().parseCommandUrl(str);
String str2 = parseCommandUrl.get(TJAdUnitConstants.String.COMMAND);
String[] strArr = {"close", "resize", "noFill", Constants.ParametersKeys.LOADED};
String[] strArr2 = {"createCalendarEvent", Tracker.Events.CREATIVE_EXPAND, "open", "playVideo", MRAIDNativeFeature.STORE_PICTURE, "useCustomClose"};
String[] strArr3 = {"setOrientationProperties", "setResizeProperties"};
try {
if (Arrays.asList(strArr).contains(str2)) {
getClass().getDeclaredMethod(str2, new Class[0]).invoke(this, new Object[0]);
} else if (Arrays.asList(strArr2).contains(str2)) {
getClass().getDeclaredMethod(str2, String.class).invoke(this, parseCommandUrl.get(str2.equals("createCalendarEvent") ? "eventJSON" : str2.equals("useCustomClose") ? "useCustomClose" : "url"));
} else if (Arrays.asList(strArr3).contains(str2)) {
getClass().getDeclaredMethod(str2, Map.class).invoke(this, parseCommandUrl);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void pauseWebView(WebView webView) {
MRAIDLog.d(TAG, "pauseWebView " + webView.toString());
try {
webView.onPause();
} catch (Exception e) {
MRAIDLog.e(e.getMessage());
}
}
private void playVideo(String str) {
try {
String decode = URLDecoder.decode(str, "UTF-8");
MRAIDLog.d("MRAIDView-JS callback", "playVideo " + decode);
if (this.nativeFeatureListener != null) {
this.nativeFeatureListener.mraidNativeFeaturePlayVideo(decode);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
private int px2dip(int i) {
return (i * 160) / this.displayMetrics.densityDpi;
}
private void removeDefaultCloseButton() {
if (this.closeRegion != null) {
this.closeRegion.setVisibility(4);
this.closeTimerPosition = 100000;
this.closeRegion.setClickable(false);
}
}
public void removeResizeView() {
this.resizedView.removeAllViews();
FrameLayout frameLayout = (FrameLayout) ((Activity) this.context).findViewById(16908290);
if (frameLayout != null) {
frameLayout.removeView(this.resizedView);
}
this.resizedView = null;
this.closeRegion = null;
}
private void resize() {
MRAIDLog.d("MRAIDView-JS callback", "resize");
if (this.listener != null && this.listener.mraidViewResize(this, this.resizeProperties.width, this.resizeProperties.height, this.resizeProperties.offsetX, this.resizeProperties.offsetY)) {
this.state = 3;
if (this.resizedView == null) {
this.resizedView = new RelativeLayout(this.context);
removeAllViews();
this.resizedView.addView(this.webView);
addCloseRegion(this.resizedView);
FrameLayout frameLayout = (FrameLayout) getRootView().findViewById(16908290);
if (frameLayout != null) {
frameLayout.addView(this.resizedView);
}
}
setCloseRegionPosition(this.resizedView);
setResizedViewSize();
setResizedViewPosition();
this.handler.post(new Runnable() {
@Override
public void run() {
MRAIDView.this.fireStateChangeEvent();
}
});
}
}
public void restoreOriginalOrientation() {
MRAIDLog.d(TAG, "restoreOriginalOrientation");
if (this.interstitialActivity == null || this.interstitialActivity.getRequestedOrientation() == this.originalRequestedOrientation) {
return;
}
this.interstitialActivity.setRequestedOrientation(this.originalRequestedOrientation);
}
public void restoreOriginalScreenState() {
if (this.context == null || !(this.context instanceof Activity)) {
return;
}
Activity activity = (Activity) this.context;
if (!this.isFullScreen) {
activity.getWindow().clearFlags(1024);
}
if (this.isForceNotFullScreen) {
activity.getWindow().addFlags(2048);
}
if (!this.isActionBarShowing) {
if (this.titleBar != null) {
this.titleBar.setVisibility(this.origTitleBarVisibility);
return;
}
return;
}
ActionBar actionBar = activity.getActionBar();
if (actionBar != null) {
actionBar.show();
}
}
public void resumeWebView(WebView webView) {
MRAIDLog.d(TAG, "resumeWebView " + webView.toString());
try {
webView.onResume();
} catch (Exception e) {
MRAIDLog.e(e.getMessage());
}
}
private void setCloseRegionPosition(View view) {
int i;
int i2;
int applyDimension = (int) TypedValue.applyDimension(1, 50.0f, this.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:
i2 = 9;
layoutParams.addRule(i2);
break;
case 1:
case 3:
case 5:
i2 = 14;
layoutParams.addRule(i2);
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:
i = 15;
layoutParams.addRule(i);
break;
case 4:
case 5:
case 6:
i = 12;
layoutParams.addRule(i);
break;
}
}
} else {
layoutParams.addRule(10);
layoutParams.addRule(11);
}
this.closeRegion.setLayoutParams(layoutParams);
}
public void setCurrentPosition() {
int i = this.currentPosition.left;
int i2 = this.currentPosition.top;
int width = this.currentPosition.width();
int height = this.currentPosition.height();
MRAIDLog.d(TAG, "setCurrentPosition [" + i + "," + i2 + "] (" + width + "x" + height + ")");
injectJavaScript("mraid.setCurrentPosition(" + px2dip(i) + "," + px2dip(i2) + "," + px2dip(width) + "," + px2dip(height) + ");");
}
public void setDefaultPosition() {
int i = this.defaultPosition.left;
int i2 = this.defaultPosition.top;
int width = this.defaultPosition.width();
int height = this.defaultPosition.height();
MRAIDLog.d(TAG, "setDefaultPosition [" + i + "," + i2 + "] (" + width + "x" + height + ")");
injectJavaScript("mraid.setDefaultPosition(" + px2dip(i) + "," + px2dip(i2) + "," + px2dip(width) + "," + px2dip(height) + ");");
}
public void setMaxSize() {
MRAIDLog.d(TAG, "setMaxSize");
int i = this.maxSize.width;
int i2 = this.maxSize.height;
MRAIDLog.d(TAG, "setMaxSize " + i + "x" + i2);
injectJavaScript("mraid.setMaxSize(" + px2dip(i) + "," + px2dip(i2) + ");");
}
private void setOrientationProperties(Map<String, String> map) {
boolean parseBoolean = Boolean.parseBoolean(map.get("allowOrientationChange"));
String str = map.get("forceOrientation");
MRAIDLog.d("MRAIDView-JS callback", "setOrientationProperties " + parseBoolean + " " + str);
if (this.orientationProperties.allowOrientationChange == parseBoolean && this.orientationProperties.forceOrientation == MRAIDOrientationProperties.forceOrientationFromString(str)) {
return;
}
this.orientationProperties.allowOrientationChange = parseBoolean;
this.orientationProperties.forceOrientation = MRAIDOrientationProperties.forceOrientationFromString(str);
if (this.isInterstitial || this.state == 2) {
applyOrientationProperties();
}
}
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("MRAIDView-JS callback", "setResizeProperties " + parseInt + " " + parseInt2 + " " + parseInt3 + " " + parseInt4 + " " + str + " " + parseBoolean);
this.resizeProperties.width = parseInt;
this.resizeProperties.height = parseInt2;
this.resizeProperties.offsetX = parseInt3;
this.resizeProperties.offsetY = parseInt4;
this.resizeProperties.customClosePosition = MRAIDResizeProperties.customClosePositionFromString(str);
this.resizeProperties.allowOffscreen = parseBoolean;
}
public void setResizedViewPosition() {
MRAIDLog.d(TAG, "setResizedViewPosition");
if (this.resizedView == null) {
return;
}
int i = this.resizeProperties.width;
int i2 = this.resizeProperties.height;
int i3 = this.resizeProperties.offsetX;
int i4 = this.resizeProperties.offsetY;
int applyDimension = (int) TypedValue.applyDimension(1, i, this.displayMetrics);
int applyDimension2 = (int) TypedValue.applyDimension(1, i2, this.displayMetrics);
int applyDimension3 = this.defaultPosition.left + ((int) TypedValue.applyDimension(1, i3, this.displayMetrics));
int applyDimension4 = this.defaultPosition.top + ((int) TypedValue.applyDimension(1, i4, this.displayMetrics));
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this.resizedView.getLayoutParams();
layoutParams.leftMargin = applyDimension3;
layoutParams.topMargin = applyDimension4;
this.resizedView.setLayoutParams(layoutParams);
if (applyDimension3 == this.currentPosition.left && applyDimension4 == this.currentPosition.top && applyDimension == this.currentPosition.width() && applyDimension2 == this.currentPosition.height()) {
return;
}
this.currentPosition.left = applyDimension3;
this.currentPosition.top = applyDimension4;
this.currentPosition.right = applyDimension3 + applyDimension;
this.currentPosition.bottom = applyDimension4 + applyDimension2;
setCurrentPosition();
}
private void setResizedViewSize() {
MRAIDLog.d(TAG, "setResizedViewSize");
int i = this.resizeProperties.width;
int i2 = this.resizeProperties.height;
Log.d(TAG, "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() {
MRAIDLog.d(TAG, "setScreenSize");
int i = this.screenSize.width;
int i2 = this.screenSize.height;
MRAIDLog.d(TAG, "setScreenSize " + i + "x" + i2);
injectJavaScript("mraid.setScreenSize(" + px2dip(i) + "," + px2dip(i2) + ");");
}
public void setSupportedServices() {
MRAIDLog.d(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() + ");");
}
public void setViewable(int i) {
boolean z = i == 0;
if (z != this.isViewable) {
this.isViewable = z;
if (this.isPageFinished && this.isLaidOut) {
fireViewableChangeEvent();
}
}
}
private void showDefaultCloseButton() {
if (this.closeRegion != null) {
if (this.closeTime == 0) {
this.closeRegion.setClickable(true);
this.closeRegion.changePercentage(100, 0);
this.closeRegion.setImage(org.nexage.sourcekit.util.Assets.getBitmapFromBase64(org.nexage.sourcekit.util.Assets.close));
return;
}
this.closeRegion.setVisibility(0);
this.isCloseClickable = false;
final int i = (this.closeTime == -1 ? 3 : this.closeTime) * 1000;
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (MRAIDView.this.closeRegion != null) {
MRAIDView.this.closeTimerPosition += 40;
MRAIDView.this.closeRegion.changePercentage((100 * MRAIDView.this.closeTimerPosition) / i, (int) Math.ceil((i - MRAIDView.this.closeTimerPosition) / 1000.0d));
if (MRAIDView.this.closeTimerPosition < i) {
handler.postDelayed(this, 40L);
return;
}
MRAIDView.this.closeRegion.setClickable(true);
MRAIDView.this.closeRegion.setImage(org.nexage.sourcekit.util.Assets.getBitmapFromBase64(org.nexage.sourcekit.util.Assets.close));
MRAIDView.this.isCloseClickable = true;
}
}
}, 40L);
}
}
private void storePicture(String str) {
try {
String decode = URLDecoder.decode(str, "UTF-8");
MRAIDLog.d("MRAIDView-JS callback", "storePicture " + decode);
if (this.nativeFeatureListener != null) {
this.nativeFeatureListener.mraidNativeFeatureStorePicture(decode);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
private void useCustomClose(String str) {
MRAIDLog.d("MRAIDView-JS callback", "useCustomClose " + str);
boolean parseBoolean = Boolean.parseBoolean(str);
if (this.useCustomClose != parseBoolean) {
this.useCustomClose = parseBoolean;
if (parseBoolean) {
removeDefaultCloseButton();
} else {
showDefaultCloseButton();
}
}
}
public void clearView() {
if (this.webView != null) {
this.webView.setWebChromeClient(null);
this.webView.setWebViewClient(new WebViewClient() {
@Override
@TargetApi(24)
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
MRAIDLog.d(MRAIDView.TAG, "shouldOverrideUrlLoading: " + webResourceRequest.getUrl().toString());
return true;
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
MRAIDLog.d(MRAIDView.TAG, "shouldOverrideUrlLoading: " + str);
return true;
}
});
this.webView.loadUrl("about:blank");
}
}
public void destroy() {
this.context = null;
this.nativeFeatureManager = null;
this.listener = null;
this.interstitialActivity = null;
if (this.webView != null) {
try {
this.webView.removeAllViews();
this.webView.setWebChromeClient(null);
this.webView.setWebViewClient(null);
this.webView.destroy();
this.webView = null;
this.currentWebView = null;
} catch (Exception e) {
MRAIDLog.e(e.getMessage());
}
}
}
public int getState() {
return this.state;
}
public void load() {
WebView webView;
String str;
if (this.preload) {
this.webView.loadDataWithBaseURL(this.baseUrl, this.mData, "text/html", "UTF-8", null);
} else {
this.listener.mraidViewLoaded(this);
}
MRAIDLog.d("log level = " + MRAIDLog.getLoggingLevel());
if (MRAIDLog.getLoggingLevel() == MRAIDLog.LOG_LEVEL.verbose || MRAIDLog.getLoggingLevel() == MRAIDLog.LOG_LEVEL.debug) {
webView = this.webView;
str = "mraid.logLevel = mraid.LogLevelEnum.DEBUG;";
} else if (MRAIDLog.getLoggingLevel() == MRAIDLog.LOG_LEVEL.info) {
webView = this.webView;
str = "mraid.logLevel = mraid.LogLevelEnum.INFO;";
} else if (MRAIDLog.getLoggingLevel() == MRAIDLog.LOG_LEVEL.warning) {
webView = this.webView;
str = "mraid.logLevel = mraid.LogLevelEnum.WARNING;";
} else if (MRAIDLog.getLoggingLevel() == MRAIDLog.LOG_LEVEL.error) {
webView = this.webView;
str = "mraid.logLevel = mraid.LogLevelEnum.ERROR;";
} else if (MRAIDLog.getLoggingLevel() != MRAIDLog.LOG_LEVEL.none) {
return;
} else {
webView = this.webView;
str = "mraid.logLevel = mraid.LogLevelEnum.NONE;";
}
injectJavaScript(webView, str);
}
@Override
protected void onAttachedToWindow() {
MRAIDLog.d(TAG, "onAttachedToWindow");
super.onAttachedToWindow();
}
@Override
public void onConfigurationChanged(Configuration configuration) {
super.onConfigurationChanged(configuration);
StringBuilder sb = new StringBuilder();
sb.append("onConfigurationChanged ");
sb.append(configuration.orientation == 1 ? "portrait" : "landscape");
MRAIDLog.d(TAG, sb.toString());
if (this.context != null) {
((Activity) this.context).getWindowManager().getDefaultDisplay().getMetrics(this.displayMetrics);
}
}
@Override
protected void onDetachedFromWindow() {
MRAIDLog.d(TAG, "onDetachedFromWindow");
super.onDetachedFromWindow();
}
@Override
@SuppressLint({"DrawAllocation"})
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
super.onLayout(z, i, i2, i3, i4);
MRAIDLog.w(TAG, "onLayout (" + this.state + ") " + z + " " + i + " " + i2 + " " + i3 + " " + i4);
if (this.isForcingFullScreen) {
MRAIDLog.d(TAG, "onLayout ignored");
return;
}
if (this.state == 2 || this.state == 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 void run() {
MRAIDView.this.setResizedViewPosition();
}
});
}
this.isLaidOut = true;
if (this.state == 0 && this.isPageFinished && !this.isInterstitial) {
this.state = 1;
fireStateChangeEvent();
fireReadyEvent();
if (this.isViewable) {
fireViewableChangeEvent();
}
}
}
@Override
@SuppressLint({"ClickableViewAccessibility"})
public boolean onTouchEvent(MotionEvent motionEvent) {
if (this.gestureDetector.onTouchEvent(motionEvent)) {
motionEvent.setAction(3);
}
return super.onTouchEvent(motionEvent);
}
@Override
protected void onVisibilityChanged(@NonNull View view, int i) {
super.onVisibilityChanged(view, i);
MRAIDLog.d(TAG, "onVisibilityChanged " + getVisibilityString(i));
setViewable(i);
}
@Override
protected void onWindowVisibilityChanged(int i) {
super.onWindowVisibilityChanged(i);
int visibility = getVisibility();
MRAIDLog.d(TAG, "onWindowVisibilityChanged " + getVisibilityString(i) + " (actual " + getVisibilityString(visibility) + ")");
setViewable(visibility);
}
public void setSegmentAndPlacement(String str, String str2) {
this.placementId = str2;
this.segmentId = str;
}
public void show() {
if (this.preload || this.isShown || this.webView == null) {
return;
}
this.isShown = true;
this.webView.loadDataWithBaseURL(this.baseUrl, this.mData, "text/html", "UTF-8", null);
}
public void showAsInterstitial(Activity activity) {
this.interstitialActivity = activity;
expand(null, activity);
}
public void trackAppodealXClick() {
injectJavaScript("if (typeof appodealXSendClicks === 'function') appodealXSendClicks();");
}
public void trackAppodealXFinish() {
injectJavaScript("if (typeof appodealXTrackFinishEvent === 'function') appodealXTrackFinishEvent();");
}
}