package androidx.preference;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import z4.c;
import z4.g;

/* loaded from: classes.dex */
public class SeekBarPreference extends Preference {
    int S;
    int T;
    private int U;
    private int V;
    boolean W;
    SeekBar X;
    private TextView Y;
    boolean Z;

    /* renamed from: a0, reason: collision with root package name */
    private boolean f5008a0;

    /* renamed from: b0, reason: collision with root package name */
    boolean f5009b0;

    /* renamed from: c0, reason: collision with root package name */
    private final SeekBar.OnSeekBarChangeListener f5010c0;

    /* renamed from: d0, reason: collision with root package name */
    private final View.OnKeyListener f5011d0;

    /* loaded from: classes.dex */
    class a implements SeekBar.OnSeekBarChangeListener {
        a() {
        }

        @Override // android.widget.SeekBar.OnSeekBarChangeListener
        public void onProgressChanged(SeekBar seekBar, int i10, boolean z10) {
            if (z10) {
                SeekBarPreference seekBarPreference = SeekBarPreference.this;
                if (seekBarPreference.f5009b0 || !seekBarPreference.W) {
                    seekBarPreference.V(seekBar);
                    return;
                }
            }
            SeekBarPreference seekBarPreference2 = SeekBarPreference.this;
            seekBarPreference2.W(i10 + seekBarPreference2.T);
        }

        @Override // android.widget.SeekBar.OnSeekBarChangeListener
        public void onStartTrackingTouch(SeekBar seekBar) {
            SeekBarPreference.this.W = true;
        }

        @Override // android.widget.SeekBar.OnSeekBarChangeListener
        public void onStopTrackingTouch(SeekBar seekBar) {
            SeekBarPreference.this.W = false;
            int progress = seekBar.getProgress();
            SeekBarPreference seekBarPreference = SeekBarPreference.this;
            if (progress + seekBarPreference.T != seekBarPreference.S) {
                seekBarPreference.V(seekBar);
            }
        }
    }

    /* loaded from: classes.dex */
    class b implements View.OnKeyListener {
        b() {
        }

        @Override // android.view.View.OnKeyListener
        public boolean onKey(View view, int i10, KeyEvent keyEvent) {
            if (keyEvent.getAction() != 0) {
                return false;
            }
            SeekBarPreference seekBarPreference = SeekBarPreference.this;
            if ((!seekBarPreference.Z && (i10 == 21 || i10 == 22)) || i10 == 23 || i10 == 66) {
                return false;
            }
            SeekBar seekBar = seekBarPreference.X;
            if (seekBar != null) {
                return seekBar.onKeyDown(i10, keyEvent);
            }
            Log.e("SeekBarPreference", "SeekBar view is null and hence cannot be adjusted.");
            return false;
        }
    }

    public SeekBarPreference(Context context, AttributeSet attributeSet, int i10, int i11) {
        super(context, attributeSet, i10, i11);
        this.f5010c0 = new a();
        this.f5011d0 = new b();
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, g.C0, i10, i11);
        this.T = obtainStyledAttributes.getInt(g.F0, 0);
        S(obtainStyledAttributes.getInt(g.D0, 100));
        T(obtainStyledAttributes.getInt(g.G0, 0));
        this.Z = obtainStyledAttributes.getBoolean(g.E0, true);
        this.f5008a0 = obtainStyledAttributes.getBoolean(g.H0, false);
        this.f5009b0 = obtainStyledAttributes.getBoolean(g.I0, false);
        obtainStyledAttributes.recycle();
    }

    private void U(int i10, boolean z10) {
        int i11 = this.T;
        if (i10 < i11) {
            i10 = i11;
        }
        int i12 = this.U;
        if (i10 > i12) {
            i10 = i12;
        }
        if (i10 != this.S) {
            this.S = i10;
            W(i10);
            N(i10);
            if (z10) {
                E();
            }
        }
    }

    @Override // androidx.preference.Preference
    protected Object I(TypedArray typedArray, int i10) {
        return Integer.valueOf(typedArray.getInt(i10, 0));
    }

    public final void S(int i10) {
        int i11 = this.T;
        if (i10 < i11) {
            i10 = i11;
        }
        if (i10 != this.U) {
            this.U = i10;
            E();
        }
    }

    public final void T(int i10) {
        if (i10 != this.V) {
            this.V = Math.min(this.U - this.T, Math.abs(i10));
            E();
        }
    }

    void V(SeekBar seekBar) {
        int progress = this.T + seekBar.getProgress();
        if (progress != this.S) {
            if (a(Integer.valueOf(progress))) {
                U(progress, false);
            } else {
                seekBar.setProgress(this.S - this.T);
                W(this.S);
            }
        }
    }

    void W(int i10) {
        TextView textView = this.Y;
        if (textView != null) {
            textView.setText(String.valueOf(i10));
        }
    }

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

    public SeekBarPreference(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, c.f53161h);
    }
}
