package androidx.appcompat.view;

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;

/* JADX INFO: compiled from: ContextThemeWrapper.java */
/* JADX INFO: loaded from: classes.dex */
public class d extends ContextWrapper {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static Configuration f320f;

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

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

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

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

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

    /* JADX INFO: compiled from: ContextThemeWrapper.java */
    static class a {
        static Context a(d dVar, Configuration configuration) {
            return dVar.createConfigurationContext(configuration);
        }
    }

    public d() {
        super(null);
    }

    private Resources b() {
        int i3;
        if (this.f325e == null) {
            Configuration configuration = this.f324d;
            if (configuration == null || ((i3 = Build.VERSION.SDK_INT) >= 26 && d(configuration))) {
                this.f325e = super.getResources();
            } else if (i3 >= 17) {
                this.f325e = a.a(this, this.f324d).getResources();
            } else {
                Resources resources = super.getResources();
                Configuration configuration2 = new Configuration(resources.getConfiguration());
                configuration2.updateFrom(this.f324d);
                this.f325e = new Resources(resources.getAssets(), resources.getDisplayMetrics(), configuration2);
            }
        }
        return this.f325e;
    }

    private void c() {
        boolean z2 = this.f322b == null;
        if (z2) {
            this.f322b = getResources().newTheme();
            Resources.Theme theme = getBaseContext().getTheme();
            if (theme != null) {
                this.f322b.setTo(theme);
            }
        }
        e(this.f322b, this.f321a, z2);
    }

    private static boolean d(Configuration configuration) {
        if (configuration == null) {
            return true;
        }
        if (f320f == null) {
            Configuration configuration2 = new Configuration();
            configuration2.fontScale = 0.0f;
            f320f = configuration2;
        }
        return configuration.equals(f320f);
    }

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

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

    protected void e(Resources.Theme theme, int i3, boolean z2) {
        theme.applyStyle(i3, 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.f323c == null) {
            this.f323c = LayoutInflater.from(getBaseContext()).cloneInContext(this);
        }
        return this.f323c;
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public Resources.Theme getTheme() {
        Resources.Theme theme = this.f322b;
        if (theme != null) {
            return theme;
        }
        if (this.f321a == 0) {
            this.f321a = c.i.f3287d;
        }
        c();
        return this.f322b;
    }

    public int getThemeResId() {
        return this.f321a;
    }

    @Override // android.content.ContextWrapper, android.content.Context
    public void setTheme(int i3) {
        if (this.f321a != i3) {
            this.f321a = i3;
            c();
        }
    }

    public d(Context context, int i3) {
        super(context);
        this.f321a = i3;
    }

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