342 lines
12 KiB
Java
342 lines
12 KiB
Java
package androidx.preference;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.os.Parcel;
|
|
import android.os.Parcelable;
|
|
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 androidx.preference.Preference;
|
|
/* loaded from: classes.dex */
|
|
public class SeekBarPreference extends Preference {
|
|
private static final String TAG = "SeekBarPreference";
|
|
public boolean mAdjustable;
|
|
private int mMax;
|
|
public int mMin;
|
|
public SeekBar mSeekBar;
|
|
private SeekBar.OnSeekBarChangeListener mSeekBarChangeListener;
|
|
private int mSeekBarIncrement;
|
|
private View.OnKeyListener mSeekBarKeyListener;
|
|
public int mSeekBarValue;
|
|
private TextView mSeekBarValueTextView;
|
|
private boolean mShowSeekBarValue;
|
|
public boolean mTrackingTouch;
|
|
public boolean mUpdatesContinuously;
|
|
|
|
/* renamed from: androidx.preference.SeekBarPreference$1 reason: invalid class name */
|
|
/* loaded from: classes.dex */
|
|
public class AnonymousClass1 implements SeekBar.OnSeekBarChangeListener {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
@Override // android.widget.SeekBar.OnSeekBarChangeListener
|
|
public void onProgressChanged(SeekBar seekBar, int i, boolean z2) {
|
|
if (z2) {
|
|
SeekBarPreference seekBarPreference = SeekBarPreference.this;
|
|
if (seekBarPreference.mUpdatesContinuously || !seekBarPreference.mTrackingTouch) {
|
|
seekBarPreference.syncValueInternal(seekBar);
|
|
return;
|
|
}
|
|
}
|
|
SeekBarPreference seekBarPreference2 = SeekBarPreference.this;
|
|
seekBarPreference2.updateLabelValue(i + seekBarPreference2.mMin);
|
|
}
|
|
|
|
@Override // android.widget.SeekBar.OnSeekBarChangeListener
|
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
SeekBarPreference.this.mTrackingTouch = true;
|
|
}
|
|
|
|
@Override // android.widget.SeekBar.OnSeekBarChangeListener
|
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
SeekBarPreference.this.mTrackingTouch = false;
|
|
int progress = seekBar.getProgress();
|
|
SeekBarPreference seekBarPreference = SeekBarPreference.this;
|
|
if (progress + seekBarPreference.mMin != seekBarPreference.mSeekBarValue) {
|
|
seekBarPreference.syncValueInternal(seekBar);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.preference.SeekBarPreference$2 reason: invalid class name */
|
|
/* loaded from: classes.dex */
|
|
public class AnonymousClass2 implements View.OnKeyListener {
|
|
public AnonymousClass2() {
|
|
}
|
|
|
|
@Override // android.view.View.OnKeyListener
|
|
public boolean onKey(View view, int i, KeyEvent keyEvent) {
|
|
if (keyEvent.getAction() != 0) {
|
|
return false;
|
|
}
|
|
SeekBarPreference seekBarPreference = SeekBarPreference.this;
|
|
if ((!seekBarPreference.mAdjustable && (i == 21 || i == 22)) || i == 23 || i == 66) {
|
|
return false;
|
|
}
|
|
SeekBar seekBar = seekBarPreference.mSeekBar;
|
|
if (seekBar != null) {
|
|
return seekBar.onKeyDown(i, keyEvent);
|
|
}
|
|
Log.e(SeekBarPreference.TAG, "SeekBar view is null and hence cannot be adjusted.");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static class SavedState extends Preference.BaseSavedState {
|
|
public static final Parcelable.Creator<SavedState> CREATOR = new AnonymousClass1();
|
|
public int mMax;
|
|
public int mMin;
|
|
public int mSeekBarValue;
|
|
|
|
/* renamed from: androidx.preference.SeekBarPreference$SavedState$1 reason: invalid class name */
|
|
/* loaded from: classes.dex */
|
|
public static class AnonymousClass1 implements Parcelable.Creator<SavedState> {
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // android.os.Parcelable.Creator
|
|
public SavedState createFromParcel(Parcel parcel) {
|
|
return new SavedState(parcel);
|
|
}
|
|
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // android.os.Parcelable.Creator
|
|
public SavedState[] newArray(int i) {
|
|
return new SavedState[i];
|
|
}
|
|
}
|
|
|
|
public SavedState(Parcel parcel) {
|
|
super(parcel);
|
|
this.mSeekBarValue = parcel.readInt();
|
|
this.mMin = parcel.readInt();
|
|
this.mMax = parcel.readInt();
|
|
}
|
|
|
|
public SavedState(Parcelable parcelable) {
|
|
super(parcelable);
|
|
}
|
|
|
|
@Override // android.view.AbsSavedState, android.os.Parcelable
|
|
public void writeToParcel(Parcel parcel, int i) {
|
|
super.writeToParcel(parcel, i);
|
|
parcel.writeInt(this.mSeekBarValue);
|
|
parcel.writeInt(this.mMin);
|
|
parcel.writeInt(this.mMax);
|
|
}
|
|
}
|
|
|
|
public SeekBarPreference(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
public SeekBarPreference(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, R.attr.seekBarPreferenceStyle);
|
|
}
|
|
|
|
public SeekBarPreference(Context context, AttributeSet attributeSet, int i) {
|
|
this(context, attributeSet, i, 0);
|
|
}
|
|
|
|
public SeekBarPreference(Context context, AttributeSet attributeSet, int i, int i2) {
|
|
super(context, attributeSet, i, i2);
|
|
this.mSeekBarChangeListener = new AnonymousClass1();
|
|
this.mSeekBarKeyListener = new AnonymousClass2();
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.SeekBarPreference, i, i2);
|
|
this.mMin = obtainStyledAttributes.getInt(R.styleable.SeekBarPreference_min, 0);
|
|
setMax(obtainStyledAttributes.getInt(R.styleable.SeekBarPreference_android_max, 100));
|
|
setSeekBarIncrement(obtainStyledAttributes.getInt(R.styleable.SeekBarPreference_seekBarIncrement, 0));
|
|
this.mAdjustable = obtainStyledAttributes.getBoolean(R.styleable.SeekBarPreference_adjustable, true);
|
|
this.mShowSeekBarValue = obtainStyledAttributes.getBoolean(R.styleable.SeekBarPreference_showSeekBarValue, false);
|
|
this.mUpdatesContinuously = obtainStyledAttributes.getBoolean(R.styleable.SeekBarPreference_updatesContinuously, false);
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
private void setValueInternal(int i, boolean z2) {
|
|
int i2 = this.mMin;
|
|
if (i < i2) {
|
|
i = i2;
|
|
}
|
|
int i3 = this.mMax;
|
|
if (i > i3) {
|
|
i = i3;
|
|
}
|
|
if (i != this.mSeekBarValue) {
|
|
this.mSeekBarValue = i;
|
|
updateLabelValue(i);
|
|
persistInt(i);
|
|
if (z2) {
|
|
notifyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public int getMax() {
|
|
return this.mMax;
|
|
}
|
|
|
|
public int getMin() {
|
|
return this.mMin;
|
|
}
|
|
|
|
public final int getSeekBarIncrement() {
|
|
return this.mSeekBarIncrement;
|
|
}
|
|
|
|
public boolean getShowSeekBarValue() {
|
|
return this.mShowSeekBarValue;
|
|
}
|
|
|
|
public boolean getUpdatesContinuously() {
|
|
return this.mUpdatesContinuously;
|
|
}
|
|
|
|
public int getValue() {
|
|
return this.mSeekBarValue;
|
|
}
|
|
|
|
public boolean isAdjustable() {
|
|
return this.mAdjustable;
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder) {
|
|
super.onBindViewHolder(preferenceViewHolder);
|
|
preferenceViewHolder.itemView.setOnKeyListener(this.mSeekBarKeyListener);
|
|
this.mSeekBar = (SeekBar) preferenceViewHolder.findViewById(R.id.seekbar);
|
|
TextView textView = (TextView) preferenceViewHolder.findViewById(R.id.seekbar_value);
|
|
this.mSeekBarValueTextView = textView;
|
|
if (this.mShowSeekBarValue) {
|
|
textView.setVisibility(0);
|
|
} else {
|
|
textView.setVisibility(8);
|
|
this.mSeekBarValueTextView = null;
|
|
}
|
|
SeekBar seekBar = this.mSeekBar;
|
|
if (seekBar == null) {
|
|
Log.e(TAG, "SeekBar view is null in onBindViewHolder.");
|
|
return;
|
|
}
|
|
seekBar.setOnSeekBarChangeListener(this.mSeekBarChangeListener);
|
|
this.mSeekBar.setMax(this.mMax - this.mMin);
|
|
int i = this.mSeekBarIncrement;
|
|
if (i != 0) {
|
|
this.mSeekBar.setKeyProgressIncrement(i);
|
|
} else {
|
|
this.mSeekBarIncrement = this.mSeekBar.getKeyProgressIncrement();
|
|
}
|
|
this.mSeekBar.setProgress(this.mSeekBarValue - this.mMin);
|
|
updateLabelValue(this.mSeekBarValue);
|
|
this.mSeekBar.setEnabled(isEnabled());
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public Object onGetDefaultValue(TypedArray typedArray, int i) {
|
|
return Integer.valueOf(typedArray.getInt(i, 0));
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void onRestoreInstanceState(Parcelable parcelable) {
|
|
if (!parcelable.getClass().equals(SavedState.class)) {
|
|
super.onRestoreInstanceState(parcelable);
|
|
return;
|
|
}
|
|
SavedState savedState = (SavedState) parcelable;
|
|
super.onRestoreInstanceState(savedState.getSuperState());
|
|
this.mSeekBarValue = savedState.mSeekBarValue;
|
|
this.mMin = savedState.mMin;
|
|
this.mMax = savedState.mMax;
|
|
notifyChanged();
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public Parcelable onSaveInstanceState() {
|
|
Parcelable onSaveInstanceState = super.onSaveInstanceState();
|
|
if (isPersistent()) {
|
|
return onSaveInstanceState;
|
|
}
|
|
SavedState savedState = new SavedState(onSaveInstanceState);
|
|
savedState.mSeekBarValue = this.mSeekBarValue;
|
|
savedState.mMin = this.mMin;
|
|
savedState.mMax = this.mMax;
|
|
return savedState;
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void onSetInitialValue(Object obj) {
|
|
if (obj == null) {
|
|
obj = 0;
|
|
}
|
|
setValue(getPersistedInt(((Integer) obj).intValue()));
|
|
}
|
|
|
|
public void setAdjustable(boolean z2) {
|
|
this.mAdjustable = z2;
|
|
}
|
|
|
|
public final void setMax(int i) {
|
|
int i2 = this.mMin;
|
|
if (i < i2) {
|
|
i = i2;
|
|
}
|
|
if (i != this.mMax) {
|
|
this.mMax = i;
|
|
notifyChanged();
|
|
}
|
|
}
|
|
|
|
public void setMin(int i) {
|
|
int i2 = this.mMax;
|
|
if (i > i2) {
|
|
i = i2;
|
|
}
|
|
if (i != this.mMin) {
|
|
this.mMin = i;
|
|
notifyChanged();
|
|
}
|
|
}
|
|
|
|
public final void setSeekBarIncrement(int i) {
|
|
if (i != this.mSeekBarIncrement) {
|
|
this.mSeekBarIncrement = Math.min(this.mMax - this.mMin, Math.abs(i));
|
|
notifyChanged();
|
|
}
|
|
}
|
|
|
|
public void setShowSeekBarValue(boolean z2) {
|
|
this.mShowSeekBarValue = z2;
|
|
notifyChanged();
|
|
}
|
|
|
|
public void setUpdatesContinuously(boolean z2) {
|
|
this.mUpdatesContinuously = z2;
|
|
}
|
|
|
|
public void setValue(int i) {
|
|
setValueInternal(i, true);
|
|
}
|
|
|
|
public void syncValueInternal(SeekBar seekBar) {
|
|
int progress = seekBar.getProgress() + this.mMin;
|
|
if (progress == this.mSeekBarValue) {
|
|
return;
|
|
}
|
|
if (callChangeListener(Integer.valueOf(progress))) {
|
|
setValueInternal(progress, false);
|
|
return;
|
|
}
|
|
seekBar.setProgress(this.mSeekBarValue - this.mMin);
|
|
updateLabelValue(this.mSeekBarValue);
|
|
}
|
|
|
|
public void updateLabelValue(int i) {
|
|
TextView textView = this.mSeekBarValueTextView;
|
|
if (textView != null) {
|
|
textView.setText(String.valueOf(i));
|
|
}
|
|
}
|
|
}
|