public class SettingSelectionDialogPreference extends SettingDialogPreference<SelectionDialog.SelectionOptions>
SettingDialogPreference implementation that may be used to allow to a user to select
its preferred values, either in single or multiple choice mode, for a specific
setting preference. Entries that should be available for selection may be specified via
setEntries(CharSequence[]) along with theirs corresponding entry values that should be
specified via setEntryValues(CharSequence[]).
This preference implementation by default displays the preferred entry values as its summary text,
using SettingSelectionDialogPreference.SummaryTextBuilder, that may be specified via setSummaryTextBuilder(SummaryTextBuilder),
to build the summary text from the selected entry values. If there are no preferred entry values
selected yet, the standard summary text is displayed. The selected entry values are persisted as
String in Json Array format. The preferred entry values may be specified via setSelection(long[])
where the passed array should contain indexes of entry values specified via setEntryValues(CharSequence[])
to be persisted. The current selection array may be obtained via getSelection(). Array
of persisted entry values may be obtained via getSelecedEntryValues(). Outside of context
of the selection preference it may be obtained via selectedEntryValuesFromPersistedValues(String)
method which accepts String containing persisted entry values in Json Array format.
When SettingDialogPreference.handleOnDialogButtonClick(Dialog, int) is called, this preference implementation
handles only SelectionDialog type of dialog. If its Dialog#BUTTON_POSITIVE button
has been clicked, the selection array provided via SelectionDialog#getSelection() is set
as selection for this preference via setSelection(long[]).
String which should contain entry values
that should be by default selected, in Json Array format like "["entry_value_1", "entry_value_2"]".
See TypedArray.getString(int).
SettingDialogPreference,
SettingSelectionDialogPreference Attributes
uiSettingSelectionDialogPreferenceStyle| Modifier and Type | Class and Description |
|---|---|
static interface |
SettingSelectionDialogPreference.SummaryTextBuilder
Interface for builder that is used by
SettingSelectionDialogPreference to build its
summary text from the current selection of entry items. |
SettingDialogPreference.OnClickListenerNO_DIALOG_ID| Constructor and Description |
|---|
SettingSelectionDialogPreference(android.content.Context context)
Same as
SettingSelectionDialogPreference(Context, AttributeSet) without attributes. |
SettingSelectionDialogPreference(android.content.Context context,
android.util.AttributeSet attrs)
Same as
SettingSelectionDialogPreference(Context, AttributeSet, int) with
R.attr#uiSettingSelectionDialogPreferenceStyle as attribute for default style. |
SettingSelectionDialogPreference(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr)
Same as
SettingSelectionDialogPreference(Context, AttributeSet, int, int) with 0
as default style. |
SettingSelectionDialogPreference(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Creates a new instance of SettingSelectionDialogPreference for the given context.
|
| Modifier and Type | Method and Description |
|---|---|
SelectionDialog.SelectionOptions |
getDialogOptions()
Returns the dialog options specific for the dialog associated with this dialog preference.
|
CharSequence[] |
getEntries()
Returns the array of entries specified for this preference.
|
CharSequence[] |
getEntryValues()
Returns the array of entry values associated with the entries specified for this preference.
|
CharSequence[] |
getSelecedEntryValues()
Returns the array of preferred entry values of this preference.
|
long[] |
getSelection()
Returns the array of indexes of the preferred entry values of this preference.
|
void |
onBindView(android.view.View view) |
protected void |
onConfigureDialogOptions(SelectionDialog.SelectionOptions options,
android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Called from one of constructors to configure dialog options specific for this dialog preference.
|
protected SelectionDialog.SelectionOptions |
onCreateDialogOptions(android.content.res.Resources resources)
Called to create instance of dialog options specific for this dialog preference.
|
protected Object |
onGetDefaultValue(android.content.res.TypedArray typedArray,
int index) |
protected CharSequence |
onGetSummaryText()
Called from
SettingDialogPreference.synchronizeSummaryView(View) to retrieve the current summary text for
this dialog preference. |
protected boolean |
onHandleDialogButtonClick(Dialog dialog,
int button)
Called from
SettingDialogPreference.handleOnDialogButtonClick(Dialog, int) if the given dialog has
id associated with this dialog preference. |
protected void |
onSetInitialValue(boolean restorePersistedValue,
Object defaultValue) |
static String[] |
selectedEntryValuesFromPersistedValues(String persistedValues)
Creates an array of selected entry values from the given persistedValues String.
|
void |
setEntries(CharSequence[] entries)
Specifies an array of entries that should be displayed in the associated selection dialog.
|
void |
setEntries(int resId)
Same as
setEntries(CharSequence[]) for resource id. |
void |
setEntryValues(CharSequence[] entryValues)
Specifies an array of entry values where each value should be associated with corresponding
entry from the entries array specified via
setEntries(CharSequence[]). |
void |
setEntryValues(int resId)
Same as
setEntryValues(CharSequence[]) for resource id. |
void |
setSelection(long[] selection)
Sets a selection array containing indexes of preferred entry values that have been specified
via
setEntryValues(CharSequence[]) for this preference. |
void |
setSummaryTextBuilder(SettingSelectionDialogPreference.SummaryTextBuilder textBuilder)
Sets a builder that should be used by this preference to build its summary text for the current
selected entry items.
|
getDialogId, handleOnDialogButtonClick, setOnClickListener, synchronizeSummaryViewsetKeycallChangeListener, 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, onClick, onCreateView, onDependencyChanged, onParentChanged, onPrepareForRemoval, onRestoreInstanceState, onSaveInstanceState, peekExtras, persistBoolean, persistFloat, persistInt, persistLong, persistString, persistStringSet, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldDisableDependents, shouldPersist, toStringpublic SettingSelectionDialogPreference(android.content.Context context)
SettingSelectionDialogPreference(Context, AttributeSet) without attributes.public SettingSelectionDialogPreference(android.content.Context context,
android.util.AttributeSet attrs)
SettingSelectionDialogPreference(Context, AttributeSet, int) with
R.attr#uiSettingSelectionDialogPreferenceStyle as attribute for default style.public SettingSelectionDialogPreference(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr)
SettingSelectionDialogPreference(Context, AttributeSet, int, int) with 0
as default style.public SettingSelectionDialogPreference(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
context - Context in which will be the new setting preference presented.attrs - Set of Xml attributes used to configure the new instance of this preference.defStyleAttr - An attribute which contains a reference to a default style resource for
this preference within a theme of the given context.defStyleRes - Resource id of the default style for the new preference.protected SelectionDialog.SelectionOptions onCreateDialogOptions(android.content.res.Resources resources)
SettingDialogPreference
Default implementation creates instance of DialogOptions.
onCreateDialogOptions in class SettingDialogPreference<SelectionDialog.SelectionOptions>resources - Application resources that may be used supply default values from resources
for the options.protected void onConfigureDialogOptions(SelectionDialog.SelectionOptions options,
android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
SettingDialogPreferenceonConfigureDialogOptions in class SettingDialogPreference<SelectionDialog.SelectionOptions>options - The options created via SettingDialogPreference.onCreateDialogOptions(Resources).public void setEntries(int resId)
setEntries(CharSequence[]) for resource id.resId - Resource id of the desired text array with entries.public void setEntries(CharSequence[] entries)
entries - The desired array of entries. May be null to clear the current ones.R.attr.entries,
setEntryValues(CharSequence[])public CharSequence[] getEntries()
null if no entries have been specified.setEntries(CharSequence[]),
getEntryValues()public void setEntryValues(int resId)
setEntryValues(CharSequence[]) for resource id.resId - Resource id of the desired text array with values for entries.public void setEntryValues(CharSequence[] entryValues)
setEntries(CharSequence[]).
Note, that this method does not check if the entries and entry values arrays are consistent, that is that they are equal in length.
entryValues - The desired array of values associated with entries. May be null
to clear the current ones.R.attr.entryValuespublic CharSequence[] getEntryValues()
null if no entry values have been specified.setEntryValues(CharSequence[]),
getEntries()public void setSummaryTextBuilder(SettingSelectionDialogPreference.SummaryTextBuilder textBuilder)
By default, this preference uses internal implementation of the summary builder which separates the entry items in the summary text by ', '.
textBuilder - The desired builder for the summary text. May be null to use the
default one.protected Object onGetDefaultValue(android.content.res.TypedArray typedArray, int index)
onGetDefaultValue in class android.preference.Preferenceprotected void onSetInitialValue(boolean restorePersistedValue,
Object defaultValue)
onSetInitialValue in class android.preference.Preferencepublic static String[] selectedEntryValuesFromPersistedValues(String persistedValues)
persistedValues - The string with entry values in Json Array format persisted for a
particular SettingSelectionDialogPreference.null if no preferred values
have been selected/persisted yet.public void setSelection(long[] selection)
setEntryValues(CharSequence[]) for this preference.selection - The desired selection array with indexes of the preferred entry values to
be persisted as String in Json Array format.getSelection()public long[] getSelection()
setSelection(long[]),
getSelecedEntryValues(),
getDialogOptions()public CharSequence[] getSelecedEntryValues()
getSelection()public void onBindView(android.view.View view)
onBindView in class SettingPreferenceprotected CharSequence onGetSummaryText()
SettingDialogPreferenceSettingDialogPreference.synchronizeSummaryView(View) to retrieve the current summary text for
this dialog preference.
Default implementation returns the text provided by Preference.getSummary() method.
onGetSummaryText in class SettingDialogPreference<SelectionDialog.SelectionOptions>public SelectionDialog.SelectionOptions getDialogOptions()
SettingDialogPreferenceSubclasses may override this method and provide the dialog options with the current preferred value so it may be properly displayed in the associated dialog.
getDialogOptions in class SettingDialogPreference<SelectionDialog.SelectionOptions>protected boolean onHandleDialogButtonClick(Dialog dialog,
int button)
SettingDialogPreferenceSettingDialogPreference.handleOnDialogButtonClick(Dialog, int) if the given dialog has
id associated with this dialog preference.onHandleDialogButtonClick in class SettingDialogPreference<SelectionDialog.SelectionOptions>dialog - The dialog where the button has been clicked.button - The clicked dialog button.True if the button click event has been successfully handled, false
otherwise.