176 lines
6.2 KiB
Java
176 lines
6.2 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 androidx.annotation.ArrayRes;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.core.content.res.TypedArrayUtils;
|
|
import androidx.preference.Preference;
|
|
import java.util.Collections;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
public class MultiSelectListPreference extends DialogPreference {
|
|
private CharSequence[] mEntries;
|
|
private CharSequence[] mEntryValues;
|
|
private Set<String> mValues;
|
|
|
|
public static class SavedState extends Preference.BaseSavedState {
|
|
public static final Parcelable.Creator<SavedState> CREATOR = new AnonymousClass1();
|
|
public Set<String> mValues;
|
|
|
|
/* renamed from: androidx.preference.MultiSelectListPreference$SavedState$1 reason: invalid class name */
|
|
public static class AnonymousClass1 implements Parcelable.Creator<SavedState> {
|
|
@Override // android.os.Parcelable.Creator
|
|
public SavedState createFromParcel(Parcel parcel) {
|
|
return new SavedState(parcel);
|
|
}
|
|
|
|
@Override // android.os.Parcelable.Creator
|
|
public SavedState[] newArray(int i) {
|
|
return new SavedState[i];
|
|
}
|
|
}
|
|
|
|
public SavedState(Parcel parcel) {
|
|
super(parcel);
|
|
int readInt = parcel.readInt();
|
|
this.mValues = new HashSet();
|
|
String[] strArr = new String[readInt];
|
|
parcel.readStringArray(strArr);
|
|
Collections.addAll(this.mValues, strArr);
|
|
}
|
|
|
|
public SavedState(Parcelable parcelable) {
|
|
super(parcelable);
|
|
}
|
|
|
|
@Override // android.view.AbsSavedState, android.os.Parcelable
|
|
public void writeToParcel(@NonNull Parcel parcel, int i) {
|
|
super.writeToParcel(parcel, i);
|
|
parcel.writeInt(this.mValues.size());
|
|
Set<String> set = this.mValues;
|
|
parcel.writeStringArray((String[]) set.toArray(new String[set.size()]));
|
|
}
|
|
}
|
|
|
|
public MultiSelectListPreference(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
public MultiSelectListPreference(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle, 16842897));
|
|
}
|
|
|
|
public MultiSelectListPreference(Context context, AttributeSet attributeSet, int i) {
|
|
this(context, attributeSet, i, 0);
|
|
}
|
|
|
|
public MultiSelectListPreference(Context context, AttributeSet attributeSet, int i, int i2) {
|
|
super(context, attributeSet, i, i2);
|
|
this.mValues = new HashSet();
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MultiSelectListPreference, i, i2);
|
|
this.mEntries = TypedArrayUtils.getTextArray(obtainStyledAttributes, R.styleable.MultiSelectListPreference_entries, R.styleable.MultiSelectListPreference_android_entries);
|
|
this.mEntryValues = TypedArrayUtils.getTextArray(obtainStyledAttributes, R.styleable.MultiSelectListPreference_entryValues, R.styleable.MultiSelectListPreference_android_entryValues);
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
public int findIndexOfValue(String str) {
|
|
CharSequence[] charSequenceArr;
|
|
if (str == null || (charSequenceArr = this.mEntryValues) == null) {
|
|
return -1;
|
|
}
|
|
for (int length = charSequenceArr.length - 1; length >= 0; length--) {
|
|
if (this.mEntryValues[length].equals(str)) {
|
|
return length;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public CharSequence[] getEntries() {
|
|
return this.mEntries;
|
|
}
|
|
|
|
public CharSequence[] getEntryValues() {
|
|
return this.mEntryValues;
|
|
}
|
|
|
|
public boolean[] getSelectedItems() {
|
|
CharSequence[] charSequenceArr = this.mEntryValues;
|
|
int length = charSequenceArr.length;
|
|
Set<String> set = this.mValues;
|
|
boolean[] zArr = new boolean[length];
|
|
for (int i = 0; i < length; i++) {
|
|
zArr[i] = set.contains(charSequenceArr[i].toString());
|
|
}
|
|
return zArr;
|
|
}
|
|
|
|
public Set<String> getValues() {
|
|
return this.mValues;
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public Object onGetDefaultValue(TypedArray typedArray, int i) {
|
|
CharSequence[] textArray = typedArray.getTextArray(i);
|
|
HashSet hashSet = new HashSet();
|
|
for (CharSequence charSequence : textArray) {
|
|
hashSet.add(charSequence.toString());
|
|
}
|
|
return hashSet;
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void onRestoreInstanceState(Parcelable parcelable) {
|
|
if (parcelable == null || !parcelable.getClass().equals(SavedState.class)) {
|
|
super.onRestoreInstanceState(parcelable);
|
|
return;
|
|
}
|
|
SavedState savedState = (SavedState) parcelable;
|
|
super.onRestoreInstanceState(savedState.getSuperState());
|
|
setValues(savedState.mValues);
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public Parcelable onSaveInstanceState() {
|
|
Parcelable onSaveInstanceState = super.onSaveInstanceState();
|
|
if (isPersistent()) {
|
|
return onSaveInstanceState;
|
|
}
|
|
SavedState savedState = new SavedState(onSaveInstanceState);
|
|
savedState.mValues = getValues();
|
|
return savedState;
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void onSetInitialValue(Object obj) {
|
|
setValues(getPersistedStringSet((Set) obj));
|
|
}
|
|
|
|
public void setEntries(@ArrayRes int i) {
|
|
setEntries(getContext().getResources().getTextArray(i));
|
|
}
|
|
|
|
public void setEntries(CharSequence[] charSequenceArr) {
|
|
this.mEntries = charSequenceArr;
|
|
}
|
|
|
|
public void setEntryValues(@ArrayRes int i) {
|
|
setEntryValues(getContext().getResources().getTextArray(i));
|
|
}
|
|
|
|
public void setEntryValues(CharSequence[] charSequenceArr) {
|
|
this.mEntryValues = charSequenceArr;
|
|
}
|
|
|
|
public void setValues(Set<String> set) {
|
|
this.mValues.clear();
|
|
this.mValues.addAll(set);
|
|
persistStringSet(set);
|
|
notifyChanged();
|
|
}
|
|
}
|