package androidx.preference;

import android.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.Checkable;
import android.widget.CompoundButton;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.content.res.k;
import z4.c;
import z4.d;
import z4.g;

/* loaded from: classes.dex */
public class SwitchPreferenceCompat extends TwoStatePreference {
    private final a X;
    private CharSequence Y;
    private CharSequence Z;

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public class a implements CompoundButton.OnCheckedChangeListener {
        a() {
        }

        @Override // android.widget.CompoundButton.OnCheckedChangeListener
        public void onCheckedChanged(CompoundButton compoundButton, boolean z10) {
            if (SwitchPreferenceCompat.this.a(Boolean.valueOf(z10))) {
                SwitchPreferenceCompat.this.T(z10);
            } else {
                compoundButton.setChecked(!z10);
            }
        }
    }

    public SwitchPreferenceCompat(Context context, AttributeSet attributeSet, int i10, int i11) {
        super(context, attributeSet, i10, i11);
        this.X = new a();
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, g.U0, i10, i11);
        W(k.m(obtainStyledAttributes, g.f53175c1, g.V0));
        V(k.m(obtainStyledAttributes, g.f53172b1, g.W0));
        Z(k.m(obtainStyledAttributes, g.f53181e1, g.Y0));
        Y(k.m(obtainStyledAttributes, g.f53178d1, g.Z0));
        U(k.b(obtainStyledAttributes, g.f53169a1, g.X0, false));
        obtainStyledAttributes.recycle();
    }

    /* JADX WARN: Multi-variable type inference failed */
    private void a0(View view) {
        boolean z10 = view instanceof SwitchCompat;
        if (z10) {
            ((SwitchCompat) view).setOnCheckedChangeListener(null);
        }
        if (view instanceof Checkable) {
            ((Checkable) view).setChecked(this.S);
        }
        if (z10) {
            SwitchCompat switchCompat = (SwitchCompat) view;
            switchCompat.setTextOn(this.Y);
            switchCompat.setTextOff(this.Z);
            switchCompat.setOnCheckedChangeListener(this.X);
        }
    }

    private void b0(View view) {
        if (((AccessibilityManager) g().getSystemService("accessibility")).isEnabled()) {
            a0(view.findViewById(d.f53164a));
            X(view.findViewById(R.id.summary));
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.preference.Preference
    public void L(View view) {
        super.L(view);
        b0(view);
    }

    public void Y(CharSequence charSequence) {
        this.Z = charSequence;
        E();
    }

    public void Z(CharSequence charSequence) {
        this.Y = charSequence;
        E();
    }

    public SwitchPreferenceCompat(Context context, AttributeSet attributeSet, int i10) {
        this(context, attributeSet, i10, 0);
    }

    public SwitchPreferenceCompat(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, c.f53162i);
    }
}
