public abstract class TwoStatePreference extends Preference
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
TwoStatePreference(Context context) |
TwoStatePreference(Context context,
AttributeSet attrs) |
TwoStatePreference(Context context,
AttributeSet attrs,
int defStyle) |
Modifier and Type | Method and Description |
---|---|
boolean |
getDisableDependentsState()
Returns whether dependents are disabled when this preference is on (
true )
or when this preference is off (false ). |
CharSequence |
getSummaryOff()
Returns the summary to be shown when unchecked.
|
CharSequence |
getSummaryOn()
Returns the summary to be shown when checked.
|
boolean |
isChecked()
Returns the checked state.
|
protected void |
onClick()
Processes a click on the preference.
|
protected Object |
onGetDefaultValue(TypedArray a,
int index)
Called when a Preference is being inflated and the default value
attribute needs to be read.
|
protected void |
onRestoreInstanceState(Parcelable state)
Hook allowing a Preference to re-apply a representation of its internal
state that had previously been generated by
Preference.onSaveInstanceState() . |
protected Parcelable |
onSaveInstanceState()
Hook allowing a Preference to generate a representation of its internal
state that can later be used to create a new instance with that same
state.
|
protected void |
onSetInitialValue(boolean restoreValue,
Object defaultValue)
Implement this to set the initial value of the Preference.
|
void |
setChecked(boolean checked)
Sets the checked state and saves it to the
SharedPreferences . |
void |
setDisableDependentsState(boolean disableDependentsState)
Sets whether dependents are disabled when this preference is on (
true )
or when this preference is off (false ). |
void |
setSummaryOff(CharSequence summary)
Sets the summary to be shown when unchecked.
|
void |
setSummaryOff(int summaryResId) |
void |
setSummaryOn(CharSequence summary)
Sets the summary to be shown when checked.
|
void |
setSummaryOn(int summaryResId) |
boolean |
shouldDisableDependents()
Checks whether this preference's dependents should currently be
disabled.
|
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getEditor, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPersistedStringSet, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getTitleRes, getView, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToActivity, onAttachedToHierarchy, onBindView, onCreateView, onDependencyChanged, onKey, onPrepareForRemoval, peekExtras, persistBoolean, persistFloat, persistInt, persistLong, persistString, persistStringSet, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldPersist, toString
public TwoStatePreference(Context context, AttributeSet attrs, int defStyle)
public TwoStatePreference(Context context, AttributeSet attrs)
public TwoStatePreference(Context context)
protected void onClick()
Preference
SharedPreferences
. However, the overridden method should
call Preference.callChangeListener(Object)
to make sure the client wants to
update the preference's state with the new value.onClick
in class Preference
public void setChecked(boolean checked)
SharedPreferences
.checked
- The checked state.public boolean isChecked()
public boolean shouldDisableDependents()
Preference
shouldDisableDependents
in class Preference
public void setSummaryOn(CharSequence summary)
summary
- The summary to be shown when checked.public void setSummaryOn(int summaryResId)
summaryResId
- The summary as a resource.setSummaryOn(CharSequence)
public CharSequence getSummaryOn()
public void setSummaryOff(CharSequence summary)
summary
- The summary to be shown when unchecked.public void setSummaryOff(int summaryResId)
summaryResId
- The summary as a resource.setSummaryOff(CharSequence)
public CharSequence getSummaryOff()
public boolean getDisableDependentsState()
true
)
or when this preference is off (false
).true
)
or when this preference is off (false
).public void setDisableDependentsState(boolean disableDependentsState)
true
)
or when this preference is off (false
).disableDependentsState
- The preference state that should disable dependents.protected Object onGetDefaultValue(TypedArray a, int index)
Preference
For example, if the value type is String, the body of the method would
proxy to TypedArray.getString(int)
.
onGetDefaultValue
in class Preference
a
- The set of attributes.index
- The index of the default value attribute.protected void onSetInitialValue(boolean restoreValue, Object defaultValue)
Preference
If restorePersistedValue is true, you should restore the
Preference value from the SharedPreferences
. If
restorePersistedValue is false, you should set the Preference
value to defaultValue that is given (and possibly store to SharedPreferences
if Preference.shouldPersist()
is true).
This may not always be called. One example is if it should not persist but there is no default value given.
onSetInitialValue
in class Preference
restoreValue
- True to restore the persisted value;
false to use the given defaultValue.defaultValue
- The default value for this Preference. Only use this
if restorePersistedValue is false.protected Parcelable onSaveInstanceState()
Preference
onSaveInstanceState
in class Preference
Preference.onRestoreInstanceState(android.os.Parcelable)
,
Preference.saveHierarchyState(android.os.Bundle)
protected void onRestoreInstanceState(Parcelable state)
Preference
Preference.onSaveInstanceState()
.
This function will never be called with a null state.onRestoreInstanceState
in class Preference
state
- The saved state that had previously been returned by
Preference.onSaveInstanceState()
.Preference.onSaveInstanceState()
,
Preference.restoreHierarchyState(android.os.Bundle)