package com.mbridge.msdk.advanced.view; import android.content.Context; import android.content.res.Configuration; import android.util.AttributeSet; import android.util.Base64; 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.advanced.signal.b; import com.mbridge.msdk.foundation.controller.c; 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.mbsignalcommon.windvane.g; import com.mbridge.msdk.newreward.player.view.hybrid.util.MRAIDCommunicatorUtil; import java.util.HashMap; import org.json.JSONObject; /* loaded from: classes4.dex */ public class MBNativeAdvancedView extends RelativeLayout { private static String a = "MBAdvancedNativeView"; private MBNativeAdvancedWebview b; private View c; private boolean d; private boolean e; private boolean f; private b g; private Context h; public void clearResState() { this.f = false; this.e = false; this.d = false; } public b getAdvancedNativeSignalCommunicationImpl() { return this.g; } public MBNativeAdvancedWebview getAdvancedNativeWebview() { return this.b; } public View getCloseView() { return this.c; } public boolean isEndCardReady() { return this.f; } public boolean isH5Ready() { return this.d; } public boolean isVideoReady() { return this.e; } public void resetLoadState() { this.f = false; this.e = false; this.d = false; } public void setEndCardReady(boolean z) { this.f = z; } public void setH5Ready(boolean z) { this.d = z; } public void setVideoReady(boolean z) { this.e = z; } public void setAdvancedNativeSignalCommunicationImpl(b bVar) { this.g = bVar; MBNativeAdvancedWebview mBNativeAdvancedWebview = this.b; if (mBNativeAdvancedWebview != null) { mBNativeAdvancedWebview.setObject(bVar); } } public MBNativeAdvancedView(Context context) { this(context, null); } public MBNativeAdvancedView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); } public MBNativeAdvancedView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); this.h = context; } @Override // android.view.View public void onConfigurationChanged(Configuration configuration) { super.onConfigurationChanged(configuration); } public void setAdvancedNativeWebview(MBNativeAdvancedWebview mBNativeAdvancedWebview) { this.b = mBNativeAdvancedWebview; b bVar = this.g; if (bVar != null) { mBNativeAdvancedWebview.setObject(bVar); } } public void changeCloseBtnState(int i) { View view = this.c; if (view != null) { if (i == 2) { view.setVisibility(8); } else { view.setVisibility(0); } } } public void setCloseView(View view) { this.c = view; if (view != null) { view.setContentDescription("closeButton"); } } public void clearResStateAndRemoveClose() { clearResState(); View view = this.c; if (view == null || view.getParent() == null) { return; } removeView(this.c); } public static void transInfoForMraid(WebView webView, int i, int i2, int i3, int i4) { af.b(a, "transInfoForMraid"); try { int i5 = 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(c.m().c()); float h = ab.h(c.m().c()); HashMap i6 = ab.i(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, "inline"); 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 destroy() { removeAllViews(); MBNativeAdvancedWebview mBNativeAdvancedWebview = this.b; if (mBNativeAdvancedWebview != null && !mBNativeAdvancedWebview.isDestoryed()) { this.b.release(); com.mbridge.msdk.advanced.signal.a.a(this.b, "onSystemDestory", ""); } if (this.h != null) { this.h = null; } } public void show() { MBNativeAdvancedWebview mBNativeAdvancedWebview = this.b; if (mBNativeAdvancedWebview != null && mBNativeAdvancedWebview.getParent() == null) { addView(this.b, new ViewGroup.LayoutParams(-1, -1)); } int[] iArr = new int[2]; this.b.getLocationInWindow(iArr); MBNativeAdvancedWebview mBNativeAdvancedWebview2 = this.b; transInfoForMraid(mBNativeAdvancedWebview2, iArr[0], iArr[1], mBNativeAdvancedWebview2.getWidth(), this.b.getHeight()); MBNativeAdvancedWebview mBNativeAdvancedWebview3 = this.b; if (mBNativeAdvancedWebview3 != null) { mBNativeAdvancedWebview3.setObject(this.g); this.b.post(new Runnable() { // from class: com.mbridge.msdk.advanced.view.MBNativeAdvancedView.1 @Override // java.lang.Runnable public final void run() { try { af.a(MBNativeAdvancedView.a, "webviewshow"); String str = ""; try { int[] iArr2 = new int[2]; MBNativeAdvancedView.this.b.getLocationOnScreen(iArr2); af.b(MBNativeAdvancedView.a, "coordinate:" + iArr2[0] + "--" + iArr2[1]); JSONObject jSONObject = new JSONObject(); jSONObject.put("startX", ak.b(c.m().c(), (float) iArr2[0])); jSONObject.put("startY", ak.b(c.m().c(), (float) iArr2[1])); str = jSONObject.toString(); } catch (Throwable th) { af.b(MBNativeAdvancedView.a, th.getMessage(), th); } g.a().a((WebView) MBNativeAdvancedView.this.b, "webviewshow", Base64.encodeToString(str.toString().getBytes(), 2)); } catch (Exception e) { e.printStackTrace(); } } }); } View view = this.c; if (view != null) { if (view.getParent() == null) { RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ak.a(getContext(), 28.0f), ak.a(getContext(), 16.0f)); layoutParams.addRule(10); layoutParams.addRule(11); layoutParams.rightMargin = ak.a(getContext(), 2.0f); layoutParams.topMargin = ak.a(getContext(), 2.0f); addView(this.c, layoutParams); } else { bringChildToFront(this.c); } } clearResState(); } }