445 lines
18 KiB
Java
445 lines
18 KiB
Java
package com.unity3d.ads.adunit;
|
|
|
|
import android.app.Activity;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.RelativeLayout;
|
|
import com.baidu.cloud.media.player.misc.IMediaFormat;
|
|
import com.ubtrobot.jimu.robotapi.PeripheralType;
|
|
import com.unity3d.ads.api.AdUnit;
|
|
import com.unity3d.ads.api.VideoPlayer;
|
|
import com.unity3d.ads.log.DeviceLog;
|
|
import com.unity3d.ads.misc.ViewUtilities;
|
|
import com.unity3d.ads.video.VideoPlayerView;
|
|
import com.unity3d.ads.webplayer.WebPlayer;
|
|
import com.unity3d.ads.webview.WebViewApp;
|
|
import com.unity3d.ads.webview.WebViewEventCategory;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class AdUnitActivity extends Activity {
|
|
public static final String EXTRA_ACTIVITY_ID = "activityId";
|
|
public static final String EXTRA_KEEP_SCREEN_ON = "keepScreenOn";
|
|
public static final String EXTRA_KEY_EVENT_LIST = "keyEvents";
|
|
public static final String EXTRA_ORIENTATION = "orientation";
|
|
public static final String EXTRA_SYSTEM_UI_VISIBILITY = "systemUiVisibility";
|
|
public static final String EXTRA_VIEWS = "views";
|
|
private int _activityId;
|
|
boolean _keepScreenOn;
|
|
private ArrayList<Integer> _keyEventList;
|
|
protected AdUnitRelativeLayout _layout;
|
|
private int _orientation = -1;
|
|
private int _systemUiVisibility;
|
|
private RelativeLayout _videoContainer;
|
|
private String[] _views;
|
|
private WebPlayer _webPlayer;
|
|
|
|
private void createVideoPlayer() {
|
|
if (this._videoContainer == null) {
|
|
this._videoContainer = new RelativeLayout(this);
|
|
}
|
|
if (VideoPlayer.getVideoPlayerView() == null) {
|
|
VideoPlayer.setVideoPlayerView(new VideoPlayerView(this));
|
|
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -1);
|
|
layoutParams.addRule(13);
|
|
VideoPlayer.getVideoPlayerView().setLayoutParams(layoutParams);
|
|
this._videoContainer.addView(VideoPlayer.getVideoPlayerView());
|
|
}
|
|
}
|
|
|
|
private void createWebPlayer() {
|
|
if (this._webPlayer == null) {
|
|
this._webPlayer = new WebPlayer(this, com.unity3d.ads.api.WebPlayer.getWebSettings(), com.unity3d.ads.api.WebPlayer.getWebPlayerSettings());
|
|
this._webPlayer.setEventSettings(com.unity3d.ads.api.WebPlayer.getWebPlayerEventSettings());
|
|
}
|
|
}
|
|
|
|
private void destroyVideoPlayer() {
|
|
if (VideoPlayer.getVideoPlayerView() != null) {
|
|
VideoPlayer.getVideoPlayerView().stopVideoProgressTimer();
|
|
VideoPlayer.getVideoPlayerView().stopPlayback();
|
|
ViewUtilities.removeViewFromParent(VideoPlayer.getVideoPlayerView());
|
|
}
|
|
VideoPlayer.setVideoPlayerView(null);
|
|
RelativeLayout relativeLayout = this._videoContainer;
|
|
if (relativeLayout != null) {
|
|
ViewUtilities.removeViewFromParent(relativeLayout);
|
|
this._videoContainer = null;
|
|
}
|
|
}
|
|
|
|
private void destroyWebPlayer() {
|
|
WebPlayer webPlayer = this._webPlayer;
|
|
if (webPlayer != null) {
|
|
ViewUtilities.removeViewFromParent(webPlayer);
|
|
}
|
|
this._webPlayer = null;
|
|
}
|
|
|
|
private void handleViewPlacement(View view) {
|
|
if (view.getParent() != null && view.getParent().equals(this._layout)) {
|
|
this._layout.bringChildToFront(view);
|
|
return;
|
|
}
|
|
ViewUtilities.removeViewFromParent(view);
|
|
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -1);
|
|
layoutParams.addRule(13);
|
|
layoutParams.setMargins(0, 0, 0, 0);
|
|
view.setPadding(0, 0, 0, 0);
|
|
this._layout.addView(view, layoutParams);
|
|
}
|
|
|
|
protected void createLayout() {
|
|
if (this._layout != null) {
|
|
return;
|
|
}
|
|
this._layout = new AdUnitRelativeLayout(this);
|
|
this._layout.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
|
|
ViewUtilities.setBackground(this._layout, new ColorDrawable(-16777216));
|
|
}
|
|
|
|
public AdUnitRelativeLayout getLayout() {
|
|
return this._layout;
|
|
}
|
|
|
|
public Map<String, Integer> getViewFrame(String str) {
|
|
if (str.equals("adunit")) {
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this._layout.getLayoutParams();
|
|
HashMap hashMap = new HashMap();
|
|
hashMap.put("x", Integer.valueOf(layoutParams.leftMargin));
|
|
hashMap.put("y", Integer.valueOf(layoutParams.topMargin));
|
|
hashMap.put(IMediaFormat.KEY_WIDTH, Integer.valueOf(this._layout.getWidth()));
|
|
hashMap.put(IMediaFormat.KEY_HEIGHT, Integer.valueOf(this._layout.getHeight()));
|
|
return hashMap;
|
|
}
|
|
View webView = str.equals("videoplayer") ? this._videoContainer : str.equals("webview") ? WebViewApp.getCurrentApp().getWebView() : null;
|
|
if (webView == null) {
|
|
return null;
|
|
}
|
|
RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) webView.getLayoutParams();
|
|
HashMap hashMap2 = new HashMap();
|
|
hashMap2.put("x", Integer.valueOf(layoutParams2.leftMargin));
|
|
hashMap2.put("y", Integer.valueOf(layoutParams2.topMargin));
|
|
hashMap2.put(IMediaFormat.KEY_WIDTH, Integer.valueOf(webView.getWidth()));
|
|
hashMap2.put(IMediaFormat.KEY_HEIGHT, Integer.valueOf(webView.getHeight()));
|
|
return hashMap2;
|
|
}
|
|
|
|
public String[] getViews() {
|
|
return this._views;
|
|
}
|
|
|
|
public WebPlayer getWebPlayer() {
|
|
return this._webPlayer;
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onCreate(Bundle bundle) {
|
|
AdUnitEvent adUnitEvent;
|
|
super.onCreate(bundle);
|
|
if (WebViewApp.getCurrentApp() == null) {
|
|
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onCreate");
|
|
finish();
|
|
return;
|
|
}
|
|
AdUnit.setAdUnitActivity(this);
|
|
createLayout();
|
|
ViewUtilities.removeViewFromParent(this._layout);
|
|
AdUnitRelativeLayout adUnitRelativeLayout = this._layout;
|
|
addContentView(adUnitRelativeLayout, adUnitRelativeLayout.getLayoutParams());
|
|
if (bundle == null) {
|
|
this._views = getIntent().getStringArrayExtra(EXTRA_VIEWS);
|
|
this._keyEventList = getIntent().getIntegerArrayListExtra(EXTRA_KEY_EVENT_LIST);
|
|
if (getIntent().hasExtra(EXTRA_ORIENTATION)) {
|
|
this._orientation = getIntent().getIntExtra(EXTRA_ORIENTATION, -1);
|
|
}
|
|
if (getIntent().hasExtra(EXTRA_SYSTEM_UI_VISIBILITY)) {
|
|
this._systemUiVisibility = getIntent().getIntExtra(EXTRA_SYSTEM_UI_VISIBILITY, 0);
|
|
}
|
|
if (getIntent().hasExtra(EXTRA_ACTIVITY_ID)) {
|
|
this._activityId = getIntent().getIntExtra(EXTRA_ACTIVITY_ID, -1);
|
|
}
|
|
adUnitEvent = AdUnitEvent.ON_CREATE;
|
|
} else {
|
|
this._views = bundle.getStringArray(EXTRA_VIEWS);
|
|
this._orientation = bundle.getInt(EXTRA_ORIENTATION, -1);
|
|
this._systemUiVisibility = bundle.getInt(EXTRA_SYSTEM_UI_VISIBILITY, 0);
|
|
this._keyEventList = bundle.getIntegerArrayList(EXTRA_KEY_EVENT_LIST);
|
|
this._keepScreenOn = bundle.getBoolean(EXTRA_KEEP_SCREEN_ON);
|
|
this._activityId = bundle.getInt(EXTRA_ACTIVITY_ID, -1);
|
|
setKeepScreenOn(this._keepScreenOn);
|
|
adUnitEvent = AdUnitEvent.ON_RESTORE;
|
|
}
|
|
setOrientation(this._orientation);
|
|
setSystemUiVisibility(this._systemUiVisibility);
|
|
String[] strArr = this._views;
|
|
if (strArr != null) {
|
|
if (Arrays.asList(strArr).contains("videoplayer")) {
|
|
createVideoPlayer();
|
|
}
|
|
if (Arrays.asList(this._views).contains("webplayer")) {
|
|
createWebPlayer();
|
|
}
|
|
}
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, adUnitEvent, Integer.valueOf(this._activityId));
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
if (WebViewApp.getCurrentApp() == null) {
|
|
if (isFinishing()) {
|
|
return;
|
|
}
|
|
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onDestroy");
|
|
finish();
|
|
return;
|
|
}
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_DESTROY, Boolean.valueOf(isFinishing()), Integer.valueOf(this._activityId));
|
|
if (AdUnit.getCurrentAdUnitActivityId() == this._activityId) {
|
|
AdUnit.setAdUnitActivity(null);
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Activity, android.view.KeyEvent.Callback
|
|
public boolean onKeyDown(int i, KeyEvent keyEvent) {
|
|
ArrayList<Integer> arrayList = this._keyEventList;
|
|
if (arrayList == null || !arrayList.contains(Integer.valueOf(i))) {
|
|
return false;
|
|
}
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.KEY_DOWN, Integer.valueOf(i), Long.valueOf(keyEvent.getEventTime()), Long.valueOf(keyEvent.getDownTime()), Integer.valueOf(keyEvent.getRepeatCount()), Integer.valueOf(this._activityId));
|
|
return true;
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onPause() {
|
|
super.onPause();
|
|
if (WebViewApp.getCurrentApp() == null) {
|
|
if (isFinishing()) {
|
|
return;
|
|
}
|
|
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onPause");
|
|
finish();
|
|
return;
|
|
}
|
|
if (isFinishing()) {
|
|
ViewUtilities.removeViewFromParent(WebViewApp.getCurrentApp().getWebView());
|
|
}
|
|
destroyVideoPlayer();
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_PAUSE, Boolean.valueOf(isFinishing()), Integer.valueOf(this._activityId));
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onResume() {
|
|
super.onResume();
|
|
if (WebViewApp.getCurrentApp() != null) {
|
|
setViews(this._views);
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_RESUME, Integer.valueOf(this._activityId));
|
|
} else {
|
|
if (isFinishing()) {
|
|
return;
|
|
}
|
|
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onResume");
|
|
finish();
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onSaveInstanceState(Bundle bundle) {
|
|
super.onSaveInstanceState(bundle);
|
|
bundle.putInt(EXTRA_ORIENTATION, this._orientation);
|
|
bundle.putInt(EXTRA_SYSTEM_UI_VISIBILITY, this._systemUiVisibility);
|
|
bundle.putIntegerArrayList(EXTRA_KEY_EVENT_LIST, this._keyEventList);
|
|
bundle.putBoolean(EXTRA_KEEP_SCREEN_ON, this._keepScreenOn);
|
|
bundle.putStringArray(EXTRA_VIEWS, this._views);
|
|
bundle.putInt(EXTRA_ACTIVITY_ID, this._activityId);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onStart() {
|
|
super.onStart();
|
|
if (WebViewApp.getCurrentApp() != null) {
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_START, Integer.valueOf(this._activityId));
|
|
} else {
|
|
if (isFinishing()) {
|
|
return;
|
|
}
|
|
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onStart");
|
|
finish();
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onStop() {
|
|
super.onStop();
|
|
if (WebViewApp.getCurrentApp() != null) {
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_STOP, Integer.valueOf(this._activityId));
|
|
} else {
|
|
if (isFinishing()) {
|
|
return;
|
|
}
|
|
DeviceLog.error("Unity Ads web app is null, closing Unity Ads activity from onStop");
|
|
finish();
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Activity, android.view.Window.Callback
|
|
public void onWindowFocusChanged(boolean z) {
|
|
if (z) {
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_FOCUS_GAINED, Integer.valueOf(this._activityId));
|
|
} else {
|
|
WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.ADUNIT, AdUnitEvent.ON_FOCUS_LOST, Integer.valueOf(this._activityId));
|
|
}
|
|
super.onWindowFocusChanged(z);
|
|
}
|
|
|
|
public boolean setKeepScreenOn(boolean z) {
|
|
this._keepScreenOn = z;
|
|
if (getWindow() == null) {
|
|
return false;
|
|
}
|
|
if (z) {
|
|
getWindow().addFlags(PeripheralType.SERVO);
|
|
return true;
|
|
}
|
|
getWindow().clearFlags(PeripheralType.SERVO);
|
|
return true;
|
|
}
|
|
|
|
public void setKeyEventList(ArrayList<Integer> arrayList) {
|
|
this._keyEventList = arrayList;
|
|
}
|
|
|
|
public void setOrientation(int i) {
|
|
this._orientation = i;
|
|
setRequestedOrientation(i);
|
|
}
|
|
|
|
public boolean setSystemUiVisibility(int i) {
|
|
this._systemUiVisibility = i;
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
try {
|
|
getWindow().getDecorView().setSystemUiVisibility(i);
|
|
return true;
|
|
} catch (Exception e) {
|
|
DeviceLog.exception("Error while setting SystemUIVisibility", e);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:6:0x0041 */
|
|
/* JADX WARN: Removed duplicated region for block: B:9:? A[RETURN, SYNTHETIC] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
public void setViewFrame(java.lang.String r3, int r4, int r5, int r6, int r7) {
|
|
/*
|
|
r2 = this;
|
|
java.lang.String r0 = "adunit"
|
|
boolean r0 = r3.equals(r0)
|
|
r1 = 0
|
|
if (r0 == 0) goto L17
|
|
android.widget.FrameLayout$LayoutParams r3 = new android.widget.FrameLayout$LayoutParams
|
|
r3.<init>(r6, r7)
|
|
r3.setMargins(r4, r5, r1, r1)
|
|
com.unity3d.ads.adunit.AdUnitRelativeLayout r0 = r2._layout
|
|
r0.setLayoutParams(r3)
|
|
goto L3e
|
|
L17:
|
|
java.lang.String r0 = "videoplayer"
|
|
boolean r0 = r3.equals(r0)
|
|
if (r0 == 0) goto L22
|
|
android.widget.RelativeLayout r3 = r2._videoContainer
|
|
goto L3f
|
|
L22:
|
|
java.lang.String r0 = "webview"
|
|
boolean r0 = r3.equals(r0)
|
|
if (r0 == 0) goto L33
|
|
com.unity3d.ads.webview.WebViewApp r3 = com.unity3d.ads.webview.WebViewApp.getCurrentApp()
|
|
com.unity3d.ads.webview.WebView r3 = r3.getWebView()
|
|
goto L3f
|
|
L33:
|
|
java.lang.String r0 = "webplayer"
|
|
boolean r3 = r3.equals(r0)
|
|
if (r3 == 0) goto L3e
|
|
com.unity3d.ads.webplayer.WebPlayer r3 = r2._webPlayer
|
|
goto L3f
|
|
L3e:
|
|
r3 = 0
|
|
L3f:
|
|
if (r3 == 0) goto L4c
|
|
android.widget.RelativeLayout$LayoutParams r0 = new android.widget.RelativeLayout$LayoutParams
|
|
r0.<init>(r6, r7)
|
|
r0.setMargins(r4, r5, r1, r1)
|
|
r3.setLayoutParams(r0)
|
|
L4c:
|
|
return
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.unity3d.ads.adunit.AdUnitActivity.setViewFrame(java.lang.String, int, int, int, int):void");
|
|
}
|
|
|
|
public void setViews(String[] strArr) {
|
|
if (strArr == null) {
|
|
strArr = new String[0];
|
|
}
|
|
ArrayList arrayList = new ArrayList(Arrays.asList(strArr));
|
|
if (this._views == null) {
|
|
this._views = new String[0];
|
|
}
|
|
ArrayList arrayList2 = new ArrayList(Arrays.asList(this._views));
|
|
arrayList2.removeAll(arrayList);
|
|
Iterator it = arrayList2.iterator();
|
|
while (it.hasNext()) {
|
|
String str = (String) it.next();
|
|
char c = 65535;
|
|
int hashCode = str.hashCode();
|
|
if (hashCode != -318269643) {
|
|
if (hashCode != 1224424441) {
|
|
if (hashCode == 1865295644 && str.equals("videoplayer")) {
|
|
c = 0;
|
|
}
|
|
} else if (str.equals("webview")) {
|
|
c = 1;
|
|
}
|
|
} else if (str.equals("webplayer")) {
|
|
c = 2;
|
|
}
|
|
if (c == 0) {
|
|
destroyVideoPlayer();
|
|
} else if (c == 1) {
|
|
ViewUtilities.removeViewFromParent(WebViewApp.getCurrentApp().getWebView());
|
|
} else if (c == 2) {
|
|
destroyWebPlayer();
|
|
}
|
|
}
|
|
this._views = strArr;
|
|
for (String str2 : strArr) {
|
|
if (str2 != null) {
|
|
if (str2.equals("videoplayer")) {
|
|
createVideoPlayer();
|
|
handleViewPlacement(this._videoContainer);
|
|
} else if (str2.equals("webview")) {
|
|
if (WebViewApp.getCurrentApp() == null) {
|
|
DeviceLog.error("WebApp IS NULL!");
|
|
throw new NullPointerException();
|
|
}
|
|
handleViewPlacement(WebViewApp.getCurrentApp().getWebView());
|
|
} else if (str2.equals("webplayer")) {
|
|
createWebPlayer();
|
|
handleViewPlacement(this._webPlayer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|