package n;

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.view.LayoutInflater;

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

    /* renamed from: a, reason: collision with root package name */
    private int f29658a;

    /* renamed from: b, reason: collision with root package name */
    private Resources.Theme f29659b;

    /* renamed from: c, reason: collision with root package name */
    private LayoutInflater f29660c;

    /* renamed from: d, reason: collision with root package name */
    private Configuration f29661d;

    /* renamed from: e, reason: collision with root package name */
    private Resources f29662e;

    public d(Context context, int i10) {
        super(context);
        this.f29658a = i10;
    }

    private Resources b() {
        if (this.f29662e == null) {
            Configuration configuration = this.f29661d;
            if (configuration == null) {
                this.f29662e = super.getResources();
            } else {
                this.f29662e = createConfigurationContext(configuration).getResources();
            }
        }
        return this.f29662e;
    }

    private void d() {
        boolean z10 = this.f29659b == null;
        if (z10) {
            this.f29659b = getResources().newTheme();
            Resources.Theme theme = getBaseContext().getTheme();
            if (theme != null) {
                this.f29659b.setTo(theme);
            }
        }
        e(this.f29659b, this.f29658a, z10);
    }

    public void a(Configuration configuration) {
        if (this.f29662e != null) {
            throw new IllegalStateException("getResources() or getAssets() has already been called");
        }
        if (this.f29661d != null) {
            throw new IllegalStateException("Override configuration has already been set");
        }
        this.f29661d = new Configuration(configuration);
    }

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

    public int c() {
        return this.f29658a;
    }

    protected void e(Resources.Theme theme, int i10, boolean z10) {
        theme.applyStyle(i10, 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 b();
    }

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

    @Override // android.content.ContextWrapper, android.content.Context
    public Resources.Theme getTheme() {
        Resources.Theme theme = this.f29659b;
        if (theme != null) {
            return theme;
        }
        if (this.f29658a == 0) {
            this.f29658a = h.i.f20280e;
        }
        d();
        return this.f29659b;
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public void setTheme(int i10) {
        if (this.f29658a != i10) {
            this.f29658a = i10;
            d();
        }
    }

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