package p028j; import android.content.Context; import android.content.ContextWrapper; import android.content.res.AssetManager; import android.content.res.Resources; import android.os.Build; import java.lang.ref.WeakReference; import java.util.ArrayList; /* renamed from: j.d3 */ /* loaded from: classes.dex */ public class C1091d3 extends ContextWrapper { /* renamed from: c */ public static final Object f2677c = new Object(); /* renamed from: d */ public static ArrayList> f2678d; /* renamed from: a */ public final Resources f2679a; /* renamed from: b */ public final Resources.Theme f2680b; public C1091d3(Context context) { super(context); if (!C1182p3.m1908c()) { this.f2679a = new C1101f3(this, context.getResources()); this.f2680b = null; return; } C1182p3 c1182p3 = new C1182p3(this, context.getResources()); this.f2679a = c1182p3; Resources.Theme newTheme = c1182p3.newTheme(); this.f2680b = newTheme; newTheme.setTo(context.getTheme()); } /* renamed from: a */ public static boolean m2199a(Context context) { if ((context instanceof C1091d3) || (context.getResources() instanceof C1101f3) || (context.getResources() instanceof C1182p3)) { return false; } return Build.VERSION.SDK_INT < 21 || C1182p3.m1908c(); } /* renamed from: b */ public static Context m2198b(Context context) { if (m2199a(context)) { synchronized (f2677c) { ArrayList> arrayList = f2678d; if (arrayList == null) { f2678d = new ArrayList<>(); } else { for (int size = arrayList.size() - 1; size >= 0; size--) { WeakReference weakReference = f2678d.get(size); if (weakReference == null || weakReference.get() == null) { f2678d.remove(size); } } for (int size2 = f2678d.size() - 1; size2 >= 0; size2--) { WeakReference weakReference2 = f2678d.get(size2); C1091d3 c1091d3 = weakReference2 != null ? weakReference2.get() : null; if (c1091d3 != null && c1091d3.getBaseContext() == context) { return c1091d3; } } } C1091d3 c1091d32 = new C1091d3(context); f2678d.add(new WeakReference<>(c1091d32)); return c1091d32; } } return context; } @Override // android.content.ContextWrapper, android.content.Context public AssetManager getAssets() { return this.f2679a.getAssets(); } @Override // android.content.ContextWrapper, android.content.Context public Resources getResources() { return this.f2679a; } @Override // android.content.ContextWrapper, android.content.Context public Resources.Theme getTheme() { Resources.Theme theme = this.f2680b; return theme == null ? super.getTheme() : theme; } @Override // android.content.ContextWrapper, android.content.Context public void setTheme(int i) { Resources.Theme theme = this.f2680b; if (theme == null) { super.setTheme(i); } else { theme.applyStyle(i, true); } } }