package com.tapjoy; import android.content.Context; import android.view.View; import android.view.ViewGroup; import androidx.annotation.VisibleForTesting; /* loaded from: classes4.dex */ public class TJAdUnit { public TJAdUnitWebViewListener a; public TJAdUnitActivity b; public TJAdUnitJSBridge c; public View d; public TJWebView e; public boolean f; public boolean g; public boolean h; public volatile boolean i; public boolean j; public com.tapjoy.internal.z0 k; public final d l = new d(this); public final e m = new e(this); public interface TJAdUnitWebViewListener { void onClick(); void onClosed(); void onContentReady(); } public void closeRequested(boolean z) { this.c.closeRequested(Boolean.valueOf(z)); } public View getBackgroundView() { return this.d; } public boolean getCloseRequested() { return this.c.closeRequested; } public com.tapjoy.internal.z0 getSdkBeacon() { return this.k; } public TJWebView getWebView() { return this.e; } public boolean hasCalledLoad() { return this.g; } public boolean isPrerendered() { return this.h; } public boolean preload(TJPlacementData tJPlacementData, Context context) { if (this.g || !tJPlacementData.isPrerenderingRequested() || !TJPlacementManager.canPreRenderPlacement() || TapjoyConnectCore.getInstance().isViewOpen()) { fireContentReady(); return false; } TapjoyLog.i("TJAdUnit", "Pre-rendering ad unit for placement: " + tJPlacementData.getPlacementName()); TJPlacementManager.incrementPlacementPreRenderCount(); load(tJPlacementData, true, context); return true; } public void resetContentLoadState() { this.g = false; this.j = false; this.h = false; } public void setAdUnitActivity(TJAdUnitActivity tJAdUnitActivity) { this.b = tJAdUnitActivity; } public void setWebViewListener(TJAdUnitWebViewListener tJAdUnitWebViewListener) { this.a = tJAdUnitWebViewListener; } @VisibleForTesting public void destroy() { TJAdUnitJSBridge tJAdUnitJSBridge = this.c; if (tJAdUnitJSBridge != null) { tJAdUnitJSBridge.destroy(); } View view = this.d; if (view != null) { ViewGroup viewGroup = (ViewGroup) view.getParent(); if (viewGroup != null) { viewGroup.removeView(this.d); } this.d = null; } TJWebView tJWebView = this.e; if (tJWebView != null) { tJWebView.destroy(); this.e = null; } this.i = false; this.f = false; setAdUnitActivity(null); TJAdUnitWebViewListener tJAdUnitWebViewListener = this.a; if (tJAdUnitWebViewListener != null) { tJAdUnitWebViewListener.onClosed(); } resetContentLoadState(); } public void fireContentReady() { TJAdUnitWebViewListener tJAdUnitWebViewListener = this.a; if (tJAdUnitWebViewListener != null) { tJAdUnitWebViewListener.onContentReady(); } } public void invokeBridgeCallback(String str, Object... objArr) { TJAdUnitJSBridge tJAdUnitJSBridge = this.c; if (tJAdUnitJSBridge == null || str == null) { return; } tJAdUnitJSBridge.invokeJSCallback(str, objArr); } public void notifyOrientationChanged() { TJAdUnitActivity tJAdUnitActivity; if (this.c == null || (tJAdUnitActivity = this.b) == null) { return; } TJDeviceUtils tJDeviceUtils = TJDeviceUtils.INSTANCE; int screenWidth = tJDeviceUtils.getScreenWidth(tJAdUnitActivity); int screenHeight = tJDeviceUtils.getScreenHeight(this.b); this.c.notifyOrientationChanged(tJDeviceUtils.getOrientationString(screenWidth, screenHeight), screenWidth, screenHeight); } public void pause() { TJAdUnitJSBridge tJAdUnitJSBridge = this.c; if (tJAdUnitJSBridge != null) { tJAdUnitJSBridge.setEnabled(false); this.c.pause(); } } public void setVisible(boolean z) { TJAdUnitJSBridge tJAdUnitJSBridge; TJAdUnitActivity tJAdUnitActivity; if (this.c != null && (tJAdUnitActivity = this.b) != null) { TJDeviceUtils tJDeviceUtils = TJDeviceUtils.INSTANCE; int screenWidth = tJDeviceUtils.getScreenWidth(tJAdUnitActivity); int screenHeight = tJDeviceUtils.getScreenHeight(this.b); this.c.notifyOrientationChanged(tJDeviceUtils.getOrientationString(screenWidth, screenHeight), screenWidth, screenHeight); } this.f = z; if (z && this.j && (tJAdUnitJSBridge = this.c) != null) { tJAdUnitJSBridge.display(); } } public void load(TJPlacementData tJPlacementData, boolean z, Context context) { this.g = false; TapjoyUtil.runOnMainThread(new c(this, context, tJPlacementData, z)); } public void resume() { TJAdUnitJSBridge tJAdUnitJSBridge = this.c; if (tJAdUnitJSBridge == null) { TJAdUnitActivity tJAdUnitActivity = this.b; if (tJAdUnitActivity != null) { tJAdUnitActivity.finish(); TapjoyLog.w("TJAdUnit", "Failed to resume TJAdUnit. TJAdUnitBridge is null."); return; } return; } if (tJAdUnitJSBridge.didLaunchOtherActivity) { TapjoyLog.d("TJAdUnit", "onResume bridge.didLaunchOtherActivity callbackID: " + this.c.otherActivityCallbackID); TJAdUnitJSBridge tJAdUnitJSBridge2 = this.c; tJAdUnitJSBridge2.invokeJSCallback(tJAdUnitJSBridge2.otherActivityCallbackID, Boolean.TRUE); this.c.didLaunchOtherActivity = false; } this.c.setEnabled(true); this.c.resume(); } }