package p022h;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.view.LayoutInflater;
import p007c.C0493i;

/* renamed from: h.d */
/* loaded from: classes.dex */
public class C0746d extends ContextWrapper {

    /* renamed from: f */
    public static Configuration f2332f;

    /* renamed from: a */
    public int f2333a;

    /* renamed from: b */
    public Resources.Theme f2334b;

    /* renamed from: c */
    public LayoutInflater f2335c;

    /* renamed from: d */
    public Configuration f2336d;

    /* renamed from: e */
    public Resources f2337e;

    /* renamed from: h.d$a */
    /* loaded from: classes.dex */
    public static class C0747a {
        /* renamed from: a */
        public static Context m3010a(C0746d c0746d, Configuration configuration) {
            return c0746d.createConfigurationContext(configuration);
        }
    }

    public C0746d() {
        super(null);
    }

    public C0746d(Context context, int i) {
        super(context);
        this.f2333a = i;
    }

    public C0746d(Context context, Resources.Theme theme) {
        super(context);
        this.f2334b = theme;
    }

    /* renamed from: e */
    public static boolean m3012e(Configuration configuration) {
        if (configuration == null) {
            return true;
        }
        if (f2332f == null) {
            Configuration configuration2 = new Configuration();
            configuration2.fontScale = 0.0f;
            f2332f = configuration2;
        }
        return configuration.equals(f2332f);
    }

    /* renamed from: a */
    public void m3016a(Configuration configuration) {
        if (this.f2337e != null) {
            throw new IllegalStateException("getResources() or getAssets() has already been called");
        }
        if (this.f2336d != null) {
            throw new IllegalStateException("Override configuration has already been set");
        }
        this.f2336d = new Configuration(configuration);
    }

    @Override // android.content.ContextWrapper
    public void attachBaseContext(Context context) {
        super.attachBaseContext(context);
    }

    /* renamed from: b */
    public final Resources m3015b() {
        Resources resources;
        int i;
        if (this.f2337e == null) {
            Configuration configuration = this.f2336d;
            if (configuration == null || ((i = Build.VERSION.SDK_INT) >= 26 && m3012e(configuration))) {
                resources = super.getResources();
            } else if (i >= 17) {
                resources = C0747a.m3010a(this, this.f2336d).getResources();
            } else {
                Resources resources2 = super.getResources();
                Configuration configuration2 = new Configuration(resources2.getConfiguration());
                configuration2.updateFrom(this.f2336d);
                this.f2337e = new Resources(resources2.getAssets(), resources2.getDisplayMetrics(), configuration2);
            }
            this.f2337e = resources;
        }
        return this.f2337e;
    }

    /* renamed from: c */
    public int m3014c() {
        return this.f2333a;
    }

    /* renamed from: d */
    public final void m3013d() {
        boolean z = this.f2334b == null;
        if (z) {
            this.f2334b = getResources().newTheme();
            Resources.Theme theme = getBaseContext().getTheme();
            if (theme != null) {
                this.f2334b.setTo(theme);
            }
        }
        m3011f(this.f2334b, this.f2333a, z);
    }

    /* renamed from: f */
    public void m3011f(Resources.Theme theme, int i, boolean z) {
        theme.applyStyle(i, true);
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public AssetManager getAssets() {
        return getResources().getAssets();
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public Resources getResources() {
        return m3015b();
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public Object getSystemService(String str) {
        if ("layout_inflater".equals(str)) {
            if (this.f2335c == null) {
                this.f2335c = LayoutInflater.from(getBaseContext()).cloneInContext(this);
            }
            return this.f2335c;
        }
        return getBaseContext().getSystemService(str);
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public Resources.Theme getTheme() {
        Resources.Theme theme = this.f2334b;
        if (theme != null) {
            return theme;
        }
        if (this.f2333a == 0) {
            this.f2333a = C0493i.Theme_AppCompat_Light;
        }
        m3013d();
        return this.f2334b;
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public void setTheme(int i) {
        if (this.f2333a != i) {
            this.f2333a = i;
            m3013d();
        }
    }
}