package com.mbridge.msdk.splash.view; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.util.AttributeSet; import android.util.Base64; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; import android.widget.RelativeLayout; import com.google.android.gms.ads.AdError; import com.mbridge.msdk.dycreator.listener.DyCountDownListener; import com.mbridge.msdk.foundation.tools.ab; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.foundation.tools.ak; import com.mbridge.msdk.foundation.tools.at; import com.mbridge.msdk.foundation.tools.s; import com.mbridge.msdk.mbsignalcommon.windvane.g; import com.mbridge.msdk.newreward.player.view.hybrid.util.MRAIDCommunicatorUtil; import com.mbridge.msdk.splash.signal.c; import com.mbridge.msdk.splash.signal.d; import java.util.HashMap; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes4.dex */ public class MBSplashView extends RelativeLayout { private static String a = "MBSplashView"; private int b; private MBSplashWebview c; private a d; private ViewGroup e; private View f; private View g; private int h; private boolean i; private boolean j; private boolean k; private ViewGroup l; private View m; private boolean n; private boolean o; private RelativeLayout.LayoutParams p; private c q; private DyCountDownListener r; public void clearResState() { this.k = false; this.j = false; this.i = false; } public View getCloseView() { return this.f; } public ViewGroup getDevContainer() { return this.l; } public View getIconVg() { return this.g; } public c getSplashSignalCommunicationImpl() { return this.q; } public MBSplashWebview getSplashWebview() { return this.c; } public boolean isAttach() { return this.o; } public boolean isDynamicView() { return this.n; } public boolean isH5Ready() { return this.i; } public boolean isImageReady() { return this.k; } public boolean isVideoReady() { return this.j; } public void resetLoadState() { this.j = false; this.i = false; } public void setDevContainer(ViewGroup viewGroup) { this.l = viewGroup; } public void setDyCountDownListener(DyCountDownListener dyCountDownListener) { this.r = dyCountDownListener; } public void setDynamicView(boolean z) { this.n = z; } public void setH5Ready(boolean z) { this.i = z; } public void setIconVg(View view, RelativeLayout.LayoutParams layoutParams) { this.g = view; this.p = layoutParams; } public void setImageReady(boolean z) { this.k = z; } public void setSplashNativeView(View view) { if (view != null) { this.m = view; } } public void setVideoReady(boolean z) { this.j = z; } public void setSplashSignalCommunicationImpl(c cVar) { this.q = cVar; MBSplashWebview mBSplashWebview = this.c; if (mBSplashWebview != null) { mBSplashWebview.setObject(cVar); } } public MBSplashView(Context context) { this(context, null); } public MBSplashView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); } public MBSplashView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); b(); } @Override // android.view.View public void onConfigurationChanged(Configuration configuration) { super.onConfigurationChanged(configuration); b(); } @Override // android.view.ViewGroup, android.view.View public void onAttachedToWindow() { super.onAttachedToWindow(); this.o = true; } private void b() { setBackgroundColor(0); this.b = getResources().getConfiguration().orientation; } public void setSplashWebView() { if (this.c == null) { try { MBSplashWebview mBSplashWebview = new MBSplashWebview(getContext()); this.c = mBSplashWebview; c cVar = this.q; if (cVar != null) { mBSplashWebview.setObject(cVar); } a aVar = this.d; if (aVar != null) { this.c.setWebViewClient(aVar); return; } a aVar2 = new a(); this.d = aVar2; this.c.setWebViewClient(aVar2); } catch (Throwable th) { af.b(a, th.getMessage()); } } } public void changeCloseBtnState(int i) { View view = this.f; if (view != null) { if (i == 2) { view.setVisibility(8); } else { view.setVisibility(0); } } } public void setCloseView(View view) { this.f = view; if (view != null) { view.setContentDescription("closeButton"); } } public void show() { View view; View view2; View view3; ViewGroup viewGroup; com.mbridge.msdk.splash.d.a a2; if (this.q != null && (viewGroup = this.l) != null && (viewGroup.getContext() instanceof Activity)) { this.q.a(this.l.getContext()); a aVar = this.d; if (aVar != null && (a2 = this.q.a()) != null) { aVar.a = a2; } } if (this.g != null) { if (this.e == null) { RelativeLayout relativeLayout = new RelativeLayout(getContext()); this.e = relativeLayout; relativeLayout.setId(2147482647); } if (this.b == 2) { this.h = ak.f(getContext()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -1); layoutParams.addRule(0, this.e.getId()); if (this.n && (view2 = this.m) != null) { if (view2.getParent() != null) { at.a(this.m); } addView(this.m, layoutParams); } else { MBSplashWebview mBSplashWebview = this.c; if (mBSplashWebview != null && mBSplashWebview.getParent() == null) { addView(this.c, layoutParams); } c(); } ViewGroup viewGroup2 = this.e; if (viewGroup2 != null && viewGroup2.getParent() == null) { int i = this.p.width; at.a(this.g); int i2 = this.h; if (i > i2 / 4) { i = i2 / 4; } this.e.addView(this.g, i, -1); RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(i, -1); layoutParams2.addRule(11); layoutParams2.addRule(13); addView(this.e, layoutParams2); } } else { this.h = ak.e(getContext()); RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(-1, -1); layoutParams3.addRule(2, this.e.getId()); if (this.n && (view = this.m) != null) { if (view.getParent() != null) { at.a(this.m); } addView(this.m, layoutParams3); } else { MBSplashWebview mBSplashWebview2 = this.c; if (mBSplashWebview2 != null && mBSplashWebview2.getParent() == null) { addView(this.c, layoutParams3); } c(); } ViewGroup viewGroup3 = this.e; if (viewGroup3 != null && viewGroup3.getParent() == null) { int i3 = this.p.height; int i4 = this.h; if (i3 > i4 / 4) { i3 = i4 / 4; } at.a(this.g); this.e.addView(this.g, -1, i3); RelativeLayout.LayoutParams layoutParams4 = new RelativeLayout.LayoutParams(-1, i3); layoutParams4.addRule(12); addView(this.e, layoutParams4); } } } else if (this.n && (view3 = this.m) != null) { if (view3.getParent() != null) { at.a(this.m); } addView(this.m, new ViewGroup.LayoutParams(-1, -1)); } else { MBSplashWebview mBSplashWebview3 = this.c; if (mBSplashWebview3 != null && mBSplashWebview3.getParent() == null) { addView(this.c, new ViewGroup.LayoutParams(-1, -1)); } c(); } View view4 = this.f; if (view4 != null) { if (view4.getParent() == null) { RelativeLayout.LayoutParams layoutParams5 = new RelativeLayout.LayoutParams(ak.a(getContext(), 100.0f), ak.a(getContext(), 30.0f)); layoutParams5.addRule(10); layoutParams5.addRule(11); layoutParams5.rightMargin = ak.a(getContext(), 10.0f); layoutParams5.topMargin = ak.a(getContext(), 10.0f); addView(this.f, layoutParams5); } else { bringChildToFront(this.f); } } clearResState(); } public void updateCountdown(int i) { DyCountDownListener dyCountDownListener; View view; if (this.c != null && !this.n) { try { JSONObject jSONObject = new JSONObject(); jSONObject.put("countdown", i); g.a().a((WebView) this.c, "updateCountdown", Base64.encodeToString(jSONObject.toString().getBytes(), 2)); } catch (JSONException e) { e.printStackTrace(); } } if (this.n && (view = this.m) != null && (view instanceof MBSplashNativeView)) { ((MBSplashNativeView) view).updateCountDown(i); } if (!this.n || (dyCountDownListener = this.r) == null) { return; } dyCountDownListener.getCountDownValue(i); } private void c() { MBSplashWebview mBSplashWebview = this.c; if (mBSplashWebview != null) { mBSplashWebview.setObject(this.q); this.c.post(new Runnable() { // from class: com.mbridge.msdk.splash.view.MBSplashView.1 @Override // java.lang.Runnable public final void run() { try { af.a(MBSplashView.a, "webviewshow"); String str = ""; try { int[] iArr = new int[2]; MBSplashView.this.c.getLocationOnScreen(iArr); af.b(MBSplashView.a, "coordinate:" + iArr[0] + "--" + iArr[1]); JSONObject jSONObject = new JSONObject(); jSONObject.put("startX", ak.b(com.mbridge.msdk.foundation.controller.c.m().c(), (float) iArr[0])); jSONObject.put("startY", ak.b(com.mbridge.msdk.foundation.controller.c.m().c(), (float) iArr[1])); str = jSONObject.toString(); } catch (Throwable th) { af.b(MBSplashView.a, th.getMessage(), th); } int[] iArr2 = new int[2]; MBSplashView.this.c.getLocationInWindow(iArr2); MBSplashView.transInfoForMraid(MBSplashView.this.c, iArr2[0], iArr2[1], MBSplashView.this.c.getWidth(), MBSplashView.this.c.getHeight()); g.a().a((WebView) MBSplashView.this.c, "webviewshow", Base64.encodeToString(str.toString().getBytes(), 2)); } catch (Exception e) { e.printStackTrace(); } } }); } } public static void transInfoForMraid(WebView webView, int i, int i2, int i3, int i4) { af.b(a, "transInfoForMraid"); try { int i5 = com.mbridge.msdk.foundation.controller.c.m().c().getResources().getConfiguration().orientation; JSONObject jSONObject = new JSONObject(); jSONObject.put("orientation", i5 == 2 ? "landscape" : i5 == 1 ? "portrait" : AdError.UNDEFINED_DOMAIN); jSONObject.put("locked", "true"); float j = ab.j(com.mbridge.msdk.foundation.controller.c.m().c()); float h = ab.h(com.mbridge.msdk.foundation.controller.c.m().c()); HashMap i6 = ab.i(com.mbridge.msdk.foundation.controller.c.m().c()); int intValue = ((Integer) i6.get("width")).intValue(); int intValue2 = ((Integer) i6.get("height")).intValue(); HashMap hashMap = new HashMap(); hashMap.put(MRAIDCommunicatorUtil.KEY_PLACEMENTTYPE, "Interstitial"); hashMap.put("state", MRAIDCommunicatorUtil.STATES_DEFAULT); hashMap.put(MRAIDCommunicatorUtil.KEY_VIEWABLE, "true"); hashMap.put(MRAIDCommunicatorUtil.KEY_CURRENTORIENTATION, jSONObject); float f = i; float f2 = i2; float f3 = i3; float f4 = i4; com.mbridge.msdk.mbsignalcommon.mraid.a.a().a(webView, f, f2, f3, f4); com.mbridge.msdk.mbsignalcommon.mraid.a.a().b(webView, f, f2, f3, f4); com.mbridge.msdk.mbsignalcommon.mraid.a.a().b(webView, j, h); com.mbridge.msdk.mbsignalcommon.mraid.a.a().c(webView, intValue, intValue2); com.mbridge.msdk.mbsignalcommon.mraid.a.a().a(webView, hashMap); com.mbridge.msdk.mbsignalcommon.mraid.a.a().a(webView); } catch (Throwable th) { af.b(a, "transInfoForMraid", th); } } public void onResume() { View view = this.m; if (view == null || !(view instanceof MBSplashNativeView)) { return; } ((MBSplashNativeView) view).setIsPause(false); } public void onPause() { View view = this.m; if (view == null || !(view instanceof MBSplashNativeView)) { return; } ((MBSplashNativeView) view).setIsPause(true); } public void setNotchPadding(int i, int i2, int i3, int i4) { View view = this.m; if (view != null && (view instanceof MBSplashNativeView)) { ((MBSplashNativeView) view).setNotchPadding(i, i2, i3, i4); } if (this.c != null) { g.a().a((WebView) this.c, "oncutoutfetched", Base64.encodeToString(s.a(-999, i, i2, i3, i4).getBytes(), 0)); } } @SuppressLint({"ClickableViewAccessibility"}) public void setAllowClickSplash(final boolean z) { MBSplashWebview mBSplashWebview = this.c; if (mBSplashWebview != null) { mBSplashWebview.setOnTouchListener(new View.OnTouchListener() { // from class: com.mbridge.msdk.splash.view.MBSplashView.2 @Override // android.view.View.OnTouchListener public final boolean onTouch(View view, MotionEvent motionEvent) { return !z; } }); } setOnTouchListener(new View.OnTouchListener() { // from class: com.mbridge.msdk.splash.view.MBSplashView.3 @Override // android.view.View.OnTouchListener public final boolean onTouch(View view, MotionEvent motionEvent) { return !z; } }); } public void destroy() { removeAllViews(); ViewGroup viewGroup = this.l; if (viewGroup != null) { viewGroup.removeAllViews(); } MBSplashWebview mBSplashWebview = this.c; if (mBSplashWebview == null || mBSplashWebview.isDestoryed()) { return; } this.c.finishAdSession(); d.a(this.c, "onSystemDestory", ""); this.c.release(); this.c = null; } }