package com.mbridge.msdk.foundation.d; import android.R; import android.app.Activity; import android.content.Context; import android.text.TextUtils; import android.view.ViewGroup; import android.widget.RelativeLayout; import com.mbridge.msdk.c.g; import com.mbridge.msdk.c.h; import com.mbridge.msdk.c.i; import com.mbridge.msdk.foundation.controller.c; import com.mbridge.msdk.foundation.d.a.a; import com.mbridge.msdk.foundation.entity.CampaignEx; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.foundation.tools.ak; import com.mbridge.msdk.widget.FeedBackButton; import com.mbridge.msdk.widget.dialog.MBFeedBackDialog; import java.lang.ref.WeakReference; import java.util.concurrent.ConcurrentHashMap; import org.json.JSONArray; /* loaded from: classes4.dex */ public final class b { public static int a = -2; public static int b = -2; public static volatile boolean c = false; private final RelativeLayout.LayoutParams d; private final ConcurrentHashMap e; private g f; public static class a { private static final b a = new b(); } private b() { this.d = new RelativeLayout.LayoutParams(b, a); this.e = new ConcurrentHashMap<>(); } public static b a() { return a.a; } public final void a(String str, Context context, ViewGroup viewGroup, ViewGroup.LayoutParams layoutParams, com.mbridge.msdk.foundation.d.a aVar) { if (b()) { com.mbridge.msdk.foundation.d.a.a a2 = a(str); if (aVar != null) { a2.a(new a.C0197a(str, aVar)); } FeedBackButton d = a2.d(); if (d != null) { if (layoutParams == null) { int a3 = ak.a(c.m().c(), 10.0f); this.d.setMargins(a3, a3, a3, a3); layoutParams = this.d; } ViewGroup viewGroup2 = (ViewGroup) d.getParent(); if (viewGroup2 != null) { viewGroup2.removeView(d); } Activity a4 = a(context); if (a4 != null && viewGroup == null) { viewGroup = (ViewGroup) a4.findViewById(R.id.content); } if (viewGroup != null) { viewGroup.removeView(d); viewGroup.addView(d, layoutParams); } } } } public final boolean b() { g b2 = h.a().b(c.m().k()); this.f = b2; if (b2 != null) { return false; } h.a(); this.f = i.a(); return false; } public final com.mbridge.msdk.foundation.d.a.a a(String str) { com.mbridge.msdk.foundation.d.a.a aVar; if (TextUtils.isEmpty(str)) { str = c.m().k(); } if (!this.e.containsKey(str)) { aVar = new com.mbridge.msdk.foundation.d.a.a(str); this.e.put(str, aVar); } else { aVar = this.e.get(str); } if (aVar != null) { return aVar; } com.mbridge.msdk.foundation.d.a.a aVar2 = new com.mbridge.msdk.foundation.d.a.a(str); this.e.put(str, aVar2); return aVar2; } public final Activity a(Context context) { Activity activity; Activity activity2; Context e = c.m().e(); Activity activity3 = null; try { activity = e instanceof Activity ? (Activity) e : null; } catch (Exception e2) { e = e2; } try { if ((context instanceof Activity) && !((Activity) context).isDestroyed()) { activity = (Activity) context; } WeakReference a2 = c.m().a(); if (a2 != null && (activity2 = a2.get()) != null && !activity2.isFinishing() && !activity2.isDestroyed()) { activity = activity2; } if (activity == null || activity.isFinishing()) { return null; } if (activity.isDestroyed()) { return null; } return activity; } catch (Exception e3) { e = e3; activity3 = activity; e.printStackTrace(); return activity3; } } public final void a(String str, int i, ViewGroup viewGroup) { com.mbridge.msdk.foundation.d.a.a a2 = a(str); if (a2.d() != null) { a2.c(i); if (i == 0) { a(str, c.m().c(), viewGroup, (ViewGroup.LayoutParams) null, (com.mbridge.msdk.foundation.d.a) null); } } } public final void a(String str, int i, int i2, int i3, float f, float f2, float f3, String str2, String str3, float f4, JSONArray jSONArray) { com.mbridge.msdk.foundation.d.a.a a2 = a(str); Context c2 = c.m().c(); a2.a(ak.a(c2, f), ak.a(c2, f2), ak.a(c2, i), ak.a(c2, i2), ak.a(c2, i3), f3, str2, str3, f4, jSONArray); } public final void a(String str, int i, com.mbridge.msdk.foundation.d.a aVar) { com.mbridge.msdk.foundation.d.a.a a2 = a(str); a2.a(new a.C0197a(str, aVar)); if (i == 1) { a2.b(); } else { a2.e(); } } public final FeedBackButton b(String str) { return a(str).d(); } public final void c(String str) { try { com.mbridge.msdk.foundation.d.a.a d = d(str); if (d != null) { d.a(); } this.e.remove(str); c = false; } catch (Exception e) { e.printStackTrace(); } } private com.mbridge.msdk.foundation.d.a.a d(String str) { if (TextUtils.isEmpty(str)) { str = c.m().k(); } if (this.e.containsKey(str)) { return this.e.get(str); } return null; } public final void a(String str, int i, int i2, String str2, String str3) { com.mbridge.msdk.foundation.d.a.a d = d(str + "_1"); if (d == null) { d = d(str + "_2"); if (d == null) { d = d(str + "_3"); if (d == null) { d = d(str + "_4"); if (d == null) { d = a(str); } } } d.b(0); } if (d != null) { CampaignEx c2 = d.c(); com.mbridge.msdk.foundation.same.report.i.a(c2, c2 != null ? c2.getCampaignUnitId() : "", d.g(), d.f(), !TextUtils.isEmpty(str2) ? str2 : "", i, c2 != null ? c2.getAdType() : 0, i2, str3); } } public final void a(String str, CampaignEx campaignEx) { a(str).a(campaignEx); } public final void a(String str, String str2) { a(str).a(str2); } public final void a(String str, FeedBackButton feedBackButton) { a(str).a(feedBackButton); } public final void a(String str, com.mbridge.msdk.foundation.d.a aVar) { com.mbridge.msdk.foundation.d.a.a a2 = a(str); if (aVar != null) { a2.a(new a.C0197a(str, aVar)); } } public final void a(String str, int i) { a(str).a(i); } public final void b(String str, int i) { a(str).b(i); } public final boolean a(String str, Context context, MBFeedBackDialog mBFeedBackDialog) { if (mBFeedBackDialog == null) { af.c("", "mbAlertDialog is null"); return false; } return a(context, mBFeedBackDialog); } private boolean a(Context context, MBFeedBackDialog mBFeedBackDialog) { Activity a2 = a(context); if (a2 == null || mBFeedBackDialog == null || a2.isDestroyed()) { return false; } try { if (mBFeedBackDialog.isShowing() || a2.isFinishing()) { return false; } mBFeedBackDialog.show(); return true; } catch (Exception e) { e.printStackTrace(); return false; } } }