Constructors Summary |
---|
public CheckBoxPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyle)
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.CheckBoxPreference, defStyle, 0);
mSummaryOn = a.getString(com.android.internal.R.styleable.CheckBoxPreference_summaryOn);
mSummaryOff = a.getString(com.android.internal.R.styleable.CheckBoxPreference_summaryOff);
mDisableDependentsState = a.getBoolean(
com.android.internal.R.styleable.CheckBoxPreference_disableDependentsState, false);
a.recycle();
|
public CheckBoxPreference(android.content.Context context, android.util.AttributeSet attrs)
this(context, attrs, com.android.internal.R.attr.checkBoxPreferenceStyle);
|
public CheckBoxPreference(android.content.Context context)
this(context, null);
|
Methods Summary |
---|
public boolean | getDisableDependentsState()Returns whether dependents are disabled when this preference is on ({@code true})
or when this preference is off ({@code false}).
return mDisableDependentsState;
|
public java.lang.CharSequence | getSummaryOff()Returns the summary to be shown when unchecked.
return mSummaryOff;
|
public java.lang.CharSequence | getSummaryOn()Returns the summary to be shown when checked.
return mSummaryOn;
|
public boolean | isChecked()Returns the checked state.
return mChecked;
|
protected void | onBindView(android.view.View view)
super.onBindView(view);
View checkboxView = view.findViewById(com.android.internal.R.id.checkbox);
if (checkboxView != null && checkboxView instanceof Checkable) {
((Checkable) checkboxView).setChecked(mChecked);
}
// Sync the summary view
TextView summaryView = (TextView) view.findViewById(com.android.internal.R.id.summary);
if (summaryView != null) {
boolean useDefaultSummary = true;
if (mChecked && mSummaryOn != null) {
summaryView.setText(mSummaryOn);
useDefaultSummary = false;
} else if (!mChecked && mSummaryOff != null) {
summaryView.setText(mSummaryOff);
useDefaultSummary = false;
}
if (useDefaultSummary) {
final CharSequence summary = getSummary();
if (summary != null) {
summaryView.setText(summary);
useDefaultSummary = false;
}
}
int newVisibility = View.GONE;
if (!useDefaultSummary) {
// Someone has written to it
newVisibility = View.VISIBLE;
}
if (newVisibility != summaryView.getVisibility()) {
summaryView.setVisibility(newVisibility);
}
}
|
protected void | onClick()
super.onClick();
boolean newValue = !isChecked();
if (!callChangeListener(newValue)) {
return;
}
setChecked(newValue);
|
protected java.lang.Object | onGetDefaultValue(android.content.res.TypedArray a, int index)
return a.getBoolean(index, false);
|
protected void | onRestoreInstanceState(android.os.Parcelable state)
if (state == null || !state.getClass().equals(SavedState.class)) {
// Didn't save state for us in onSaveInstanceState
super.onRestoreInstanceState(state);
return;
}
SavedState myState = (SavedState) state;
super.onRestoreInstanceState(myState.getSuperState());
setChecked(myState.checked);
|
protected android.os.Parcelable | onSaveInstanceState()
final Parcelable superState = super.onSaveInstanceState();
if (isPersistent()) {
// No need to save instance state since it's persistent
return superState;
}
final SavedState myState = new SavedState(superState);
myState.checked = isChecked();
return myState;
|
protected void | onSetInitialValue(boolean restoreValue, java.lang.Object defaultValue)
setChecked(restoreValue ? getPersistedBoolean(mChecked)
: (Boolean) defaultValue);
|
public void | setChecked(boolean checked)Sets the checked state and saves it to the {@link SharedPreferences}.
mChecked = checked;
persistBoolean(checked);
notifyDependencyChange(shouldDisableDependents());
notifyChanged();
|
public void | setDisableDependentsState(boolean disableDependentsState)Sets whether dependents are disabled when this preference is on ({@code true})
or when this preference is off ({@code false}).
mDisableDependentsState = disableDependentsState;
|
public void | setSummaryOff(java.lang.CharSequence summary)Sets the summary to be shown when unchecked.
mSummaryOff = summary;
if (!isChecked()) {
notifyChanged();
}
|
public void | setSummaryOff(int summaryResId)
setSummaryOff(getContext().getString(summaryResId));
|
public void | setSummaryOn(int summaryResId)
setSummaryOn(getContext().getString(summaryResId));
|
public void | setSummaryOn(java.lang.CharSequence summary)Sets the summary to be shown when checked.
mSummaryOn = summary;
if (isChecked()) {
notifyChanged();
}
|
public boolean | shouldDisableDependents()
boolean shouldDisable = mDisableDependentsState ? mChecked : !mChecked;
return shouldDisable || super.shouldDisableDependents();
|