discord-jadx/app/src/main/java/androidx/preference/CheckBoxPreference.java

85 lines
3.5 KiB
Java

package androidx.preference;
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.annotation.RestrictTo;
import androidx.core.content.res.TypedArrayUtils;
public class CheckBoxPreference extends TwoStatePreference {
private final Listener mListener;
public class Listener implements CompoundButton.OnCheckedChangeListener {
public Listener() {
}
@Override // android.widget.CompoundButton.OnCheckedChangeListener
public void onCheckedChanged(CompoundButton compoundButton, boolean z2) {
if (!CheckBoxPreference.this.callChangeListener(Boolean.valueOf(z2))) {
compoundButton.setChecked(!z2);
} else {
CheckBoxPreference.this.setChecked(z2);
}
}
}
public CheckBoxPreference(Context context) {
this(context, null);
}
public CheckBoxPreference(Context context, AttributeSet attributeSet) {
this(context, attributeSet, TypedArrayUtils.getAttr(context, R.attr.checkBoxPreferenceStyle, 16842895));
}
public CheckBoxPreference(Context context, AttributeSet attributeSet, int i) {
this(context, attributeSet, i, 0);
}
public CheckBoxPreference(Context context, AttributeSet attributeSet, int i, int i2) {
super(context, attributeSet, i, i2);
this.mListener = new Listener();
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.CheckBoxPreference, i, i2);
setSummaryOn(TypedArrayUtils.getString(obtainStyledAttributes, R.styleable.CheckBoxPreference_summaryOn, R.styleable.CheckBoxPreference_android_summaryOn));
setSummaryOff(TypedArrayUtils.getString(obtainStyledAttributes, R.styleable.CheckBoxPreference_summaryOff, R.styleable.CheckBoxPreference_android_summaryOff));
setDisableDependentsState(TypedArrayUtils.getBoolean(obtainStyledAttributes, R.styleable.CheckBoxPreference_disableDependentsState, R.styleable.CheckBoxPreference_android_disableDependentsState, false));
obtainStyledAttributes.recycle();
}
private void syncCheckboxView(View view) {
boolean z2 = view instanceof CompoundButton;
if (z2) {
((CompoundButton) view).setOnCheckedChangeListener(null);
}
if (view instanceof Checkable) {
((Checkable) view).setChecked(this.mChecked);
}
if (z2) {
((CompoundButton) view).setOnCheckedChangeListener(this.mListener);
}
}
private void syncViewIfAccessibilityEnabled(View view) {
if (((AccessibilityManager) getContext().getSystemService("accessibility")).isEnabled()) {
syncCheckboxView(view.findViewById(16908289));
syncSummaryView(view.findViewById(16908304));
}
}
@Override // androidx.preference.Preference
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder) {
super.onBindViewHolder(preferenceViewHolder);
syncCheckboxView(preferenceViewHolder.findViewById(16908289));
syncSummaryView(preferenceViewHolder);
}
@Override // androidx.preference.Preference
@RestrictTo({RestrictTo.Scope.LIBRARY})
public void performClick(View view) {
super.performClick(view);
syncViewIfAccessibilityEnabled(view);
}
}