374 lines
13 KiB
Java
374 lines
13 KiB
Java
package androidx.preference;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Parcel;
|
|
import android.os.Parcelable;
|
|
import android.text.TextUtils;
|
|
import android.util.AttributeSet;
|
|
import android.util.Log;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.collection.SimpleArrayMap;
|
|
import androidx.core.content.res.TypedArrayUtils;
|
|
import androidx.preference.Preference;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
/* loaded from: classes.dex */
|
|
public abstract class PreferenceGroup extends Preference {
|
|
private static final String TAG = "PreferenceGroup";
|
|
private boolean mAttachedToHierarchy;
|
|
private final Runnable mClearRecycleCacheRunnable;
|
|
private int mCurrentPreferenceOrder;
|
|
private final Handler mHandler;
|
|
public final SimpleArrayMap<String, Long> mIdRecycleCache;
|
|
private int mInitialExpandedChildrenCount;
|
|
private OnExpandButtonClickListener mOnExpandButtonClickListener;
|
|
private boolean mOrderingAsAdded;
|
|
private List<Preference> mPreferences;
|
|
|
|
/* renamed from: androidx.preference.PreferenceGroup$1 reason: invalid class name */
|
|
/* loaded from: classes.dex */
|
|
public class AnonymousClass1 implements Runnable {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
synchronized (this) {
|
|
PreferenceGroup.this.mIdRecycleCache.clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
/* loaded from: classes.dex */
|
|
public interface OnExpandButtonClickListener {
|
|
void onExpandButtonClick();
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public interface PreferencePositionCallback {
|
|
int getPreferenceAdapterPosition(Preference preference);
|
|
|
|
int getPreferenceAdapterPosition(String str);
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static class SavedState extends Preference.BaseSavedState {
|
|
public static final Parcelable.Creator<SavedState> CREATOR = new AnonymousClass1();
|
|
public int mInitialExpandedChildrenCount;
|
|
|
|
/* renamed from: androidx.preference.PreferenceGroup$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.mInitialExpandedChildrenCount = parcel.readInt();
|
|
}
|
|
|
|
public SavedState(Parcelable parcelable, int i) {
|
|
super(parcelable);
|
|
this.mInitialExpandedChildrenCount = i;
|
|
}
|
|
|
|
@Override // android.view.AbsSavedState, android.os.Parcelable
|
|
public void writeToParcel(Parcel parcel, int i) {
|
|
super.writeToParcel(parcel, i);
|
|
parcel.writeInt(this.mInitialExpandedChildrenCount);
|
|
}
|
|
}
|
|
|
|
public PreferenceGroup(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public PreferenceGroup(Context context, AttributeSet attributeSet, int i) {
|
|
this(context, attributeSet, i, 0);
|
|
}
|
|
|
|
public PreferenceGroup(Context context, AttributeSet attributeSet, int i, int i2) {
|
|
super(context, attributeSet, i, i2);
|
|
this.mIdRecycleCache = new SimpleArrayMap<>();
|
|
this.mHandler = new Handler();
|
|
this.mOrderingAsAdded = true;
|
|
this.mCurrentPreferenceOrder = 0;
|
|
this.mAttachedToHierarchy = false;
|
|
this.mInitialExpandedChildrenCount = Integer.MAX_VALUE;
|
|
this.mOnExpandButtonClickListener = null;
|
|
this.mClearRecycleCacheRunnable = new AnonymousClass1();
|
|
this.mPreferences = new ArrayList();
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.PreferenceGroup, i, i2);
|
|
int i3 = R.styleable.PreferenceGroup_orderingFromXml;
|
|
this.mOrderingAsAdded = TypedArrayUtils.getBoolean(obtainStyledAttributes, i3, i3, true);
|
|
int i4 = R.styleable.PreferenceGroup_initialExpandedChildrenCount;
|
|
if (obtainStyledAttributes.hasValue(i4)) {
|
|
setInitialExpandedChildrenCount(TypedArrayUtils.getInt(obtainStyledAttributes, i4, i4, Integer.MAX_VALUE));
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
private boolean removePreferenceInt(Preference preference) {
|
|
boolean remove;
|
|
synchronized (this) {
|
|
preference.onPrepareForRemoval();
|
|
if (preference.getParent() == this) {
|
|
preference.assignParent(null);
|
|
}
|
|
remove = this.mPreferences.remove(preference);
|
|
if (remove) {
|
|
String key = preference.getKey();
|
|
if (key != null) {
|
|
this.mIdRecycleCache.put(key, Long.valueOf(preference.getId()));
|
|
this.mHandler.removeCallbacks(this.mClearRecycleCacheRunnable);
|
|
this.mHandler.post(this.mClearRecycleCacheRunnable);
|
|
}
|
|
if (this.mAttachedToHierarchy) {
|
|
preference.onDetached();
|
|
}
|
|
}
|
|
}
|
|
return remove;
|
|
}
|
|
|
|
public void addItemFromInflater(Preference preference) {
|
|
addPreference(preference);
|
|
}
|
|
|
|
public boolean addPreference(Preference preference) {
|
|
long j;
|
|
if (this.mPreferences.contains(preference)) {
|
|
return true;
|
|
}
|
|
if (preference.getKey() != null) {
|
|
PreferenceGroup preferenceGroup = this;
|
|
while (preferenceGroup.getParent() != null) {
|
|
preferenceGroup = preferenceGroup.getParent();
|
|
}
|
|
String key = preference.getKey();
|
|
if (preferenceGroup.findPreference(key) != null) {
|
|
Log.e(TAG, "Found duplicated key: \"" + key + "\". This can cause unintended behaviour, please use unique keys for every preference.");
|
|
}
|
|
}
|
|
if (preference.getOrder() == Integer.MAX_VALUE) {
|
|
if (this.mOrderingAsAdded) {
|
|
int i = this.mCurrentPreferenceOrder;
|
|
this.mCurrentPreferenceOrder = i + 1;
|
|
preference.setOrder(i);
|
|
}
|
|
if (preference instanceof PreferenceGroup) {
|
|
((PreferenceGroup) preference).setOrderingAsAdded(this.mOrderingAsAdded);
|
|
}
|
|
}
|
|
int binarySearch = Collections.binarySearch(this.mPreferences, preference);
|
|
if (binarySearch < 0) {
|
|
binarySearch = (binarySearch * (-1)) - 1;
|
|
}
|
|
if (!onPrepareAddPreference(preference)) {
|
|
return false;
|
|
}
|
|
synchronized (this) {
|
|
this.mPreferences.add(binarySearch, preference);
|
|
}
|
|
PreferenceManager preferenceManager = getPreferenceManager();
|
|
String key2 = preference.getKey();
|
|
if (key2 == null || !this.mIdRecycleCache.containsKey(key2)) {
|
|
j = preferenceManager.getNextId();
|
|
} else {
|
|
j = this.mIdRecycleCache.get(key2).longValue();
|
|
this.mIdRecycleCache.remove(key2);
|
|
}
|
|
preference.onAttachedToHierarchy(preferenceManager, j);
|
|
preference.assignParent(this);
|
|
if (this.mAttachedToHierarchy) {
|
|
preference.onAttached();
|
|
}
|
|
notifyHierarchyChanged();
|
|
return true;
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void dispatchRestoreInstanceState(Bundle bundle) {
|
|
super.dispatchRestoreInstanceState(bundle);
|
|
int preferenceCount = getPreferenceCount();
|
|
for (int i = 0; i < preferenceCount; i++) {
|
|
getPreference(i).dispatchRestoreInstanceState(bundle);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void dispatchSaveInstanceState(Bundle bundle) {
|
|
super.dispatchSaveInstanceState(bundle);
|
|
int preferenceCount = getPreferenceCount();
|
|
for (int i = 0; i < preferenceCount; i++) {
|
|
getPreference(i).dispatchSaveInstanceState(bundle);
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
public <T extends Preference> T findPreference(@NonNull CharSequence charSequence) {
|
|
T t;
|
|
if (charSequence == null) {
|
|
throw new IllegalArgumentException("Key cannot be null");
|
|
} else if (TextUtils.equals(getKey(), charSequence)) {
|
|
return this;
|
|
} else {
|
|
int preferenceCount = getPreferenceCount();
|
|
for (int i = 0; i < preferenceCount; i++) {
|
|
T t2 = (T) getPreference(i);
|
|
if (TextUtils.equals(t2.getKey(), charSequence)) {
|
|
return t2;
|
|
}
|
|
if ((t2 instanceof PreferenceGroup) && (t = (T) ((PreferenceGroup) t2).findPreference(charSequence)) != null) {
|
|
return t;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public int getInitialExpandedChildrenCount() {
|
|
return this.mInitialExpandedChildrenCount;
|
|
}
|
|
|
|
@Nullable
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public OnExpandButtonClickListener getOnExpandButtonClickListener() {
|
|
return this.mOnExpandButtonClickListener;
|
|
}
|
|
|
|
public Preference getPreference(int i) {
|
|
return this.mPreferences.get(i);
|
|
}
|
|
|
|
public int getPreferenceCount() {
|
|
return this.mPreferences.size();
|
|
}
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public boolean isAttached() {
|
|
return this.mAttachedToHierarchy;
|
|
}
|
|
|
|
public boolean isOnSameScreenAsChildren() {
|
|
return true;
|
|
}
|
|
|
|
public boolean isOrderingAsAdded() {
|
|
return this.mOrderingAsAdded;
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void notifyDependencyChange(boolean z2) {
|
|
super.notifyDependencyChange(z2);
|
|
int preferenceCount = getPreferenceCount();
|
|
for (int i = 0; i < preferenceCount; i++) {
|
|
getPreference(i).onParentChanged(this, z2);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void onAttached() {
|
|
super.onAttached();
|
|
this.mAttachedToHierarchy = true;
|
|
int preferenceCount = getPreferenceCount();
|
|
for (int i = 0; i < preferenceCount; i++) {
|
|
getPreference(i).onAttached();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public void onDetached() {
|
|
super.onDetached();
|
|
this.mAttachedToHierarchy = false;
|
|
int preferenceCount = getPreferenceCount();
|
|
for (int i = 0; i < preferenceCount; i++) {
|
|
getPreference(i).onDetached();
|
|
}
|
|
}
|
|
|
|
public boolean onPrepareAddPreference(Preference preference) {
|
|
preference.onParentChanged(this, shouldDisableDependents());
|
|
return true;
|
|
}
|
|
|
|
@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;
|
|
this.mInitialExpandedChildrenCount = savedState.mInitialExpandedChildrenCount;
|
|
super.onRestoreInstanceState(savedState.getSuperState());
|
|
}
|
|
|
|
@Override // androidx.preference.Preference
|
|
public Parcelable onSaveInstanceState() {
|
|
return new SavedState(super.onSaveInstanceState(), this.mInitialExpandedChildrenCount);
|
|
}
|
|
|
|
public void removeAll() {
|
|
synchronized (this) {
|
|
List<Preference> list = this.mPreferences;
|
|
for (int size = list.size() - 1; size >= 0; size--) {
|
|
removePreferenceInt(list.get(0));
|
|
}
|
|
}
|
|
notifyHierarchyChanged();
|
|
}
|
|
|
|
public boolean removePreference(Preference preference) {
|
|
boolean removePreferenceInt = removePreferenceInt(preference);
|
|
notifyHierarchyChanged();
|
|
return removePreferenceInt;
|
|
}
|
|
|
|
public boolean removePreferenceRecursively(@NonNull CharSequence charSequence) {
|
|
Preference findPreference = findPreference(charSequence);
|
|
if (findPreference == null) {
|
|
return false;
|
|
}
|
|
return findPreference.getParent().removePreference(findPreference);
|
|
}
|
|
|
|
public void setInitialExpandedChildrenCount(int i) {
|
|
if (i != Integer.MAX_VALUE && !hasKey()) {
|
|
Log.e(TAG, getClass().getSimpleName() + " should have a key defined if it contains an expandable preference");
|
|
}
|
|
this.mInitialExpandedChildrenCount = i;
|
|
}
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public void setOnExpandButtonClickListener(@Nullable OnExpandButtonClickListener onExpandButtonClickListener) {
|
|
this.mOnExpandButtonClickListener = onExpandButtonClickListener;
|
|
}
|
|
|
|
public void setOrderingAsAdded(boolean z2) {
|
|
this.mOrderingAsAdded = z2;
|
|
}
|
|
|
|
public void sortPreferences() {
|
|
synchronized (this) {
|
|
Collections.sort(this.mPreferences);
|
|
}
|
|
}
|
|
}
|