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 | onClick()
super.onClick();
final boolean newValue = !isChecked();
if (callChangeListener(newValue)) {
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}.
// Always persist/notify the first time; don't assume the field's default of false.
final boolean changed = mChecked != checked;
if (changed || !mCheckedSet) {
mChecked = checked;
mCheckedSet = true;
persistBoolean(checked);
if (changed) {
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();
|
void | syncSummaryView(android.view.View view)Sync a summary view contained within view's subhierarchy with the correct summary text.
// Sync the summary view
TextView summaryView = (TextView) view.findViewById(com.android.internal.R.id.summary);
if (summaryView != null) {
boolean useDefaultSummary = true;
if (mChecked && !TextUtils.isEmpty(mSummaryOn)) {
summaryView.setText(mSummaryOn);
useDefaultSummary = false;
} else if (!mChecked && !TextUtils.isEmpty(mSummaryOff)) {
summaryView.setText(mSummaryOff);
useDefaultSummary = false;
}
if (useDefaultSummary) {
final CharSequence summary = getSummary();
if (!TextUtils.isEmpty(summary)) {
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);
}
}
|