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(String[]).
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(String[])
to be persisted. The current selection array may be obtained via getSelection(). Array
of persisted entry values may be obtained via getSelectedEntryValues(). Outside of context
of the selection preference it may be obtained via createEntryValuesFromPersistedValues(String)
method which accepts String containing persisted entry values in Json Array format.
When SettingDialogPreference.handleDialogButtonClick(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
settingSelectionDialogPreferenceStyle| 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.OnClickListenerandroidx.preference.Preference.BaseSavedState, androidx.preference.Preference.OnPreferenceChangeListener, androidx.preference.Preference.OnPreferenceClickListener, androidx.preference.Preference.SummaryProvider<T extends androidx.preference.Preference>NO_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.settingSelectionDialogPreferenceStyle 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 |
|---|---|
static String[] |
createEntryValuesFromPersistedValues(String persistedValues)
Creates an array of selected entry values from the given persistedValues String.
|
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.
|
String[] |
getEntryValues()
Returns the array of entry values associated with the entries specified for this preference.
|
String[] |
getSelectedEntryValues()
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 |
onBindViewHolder(androidx.preference.PreferenceViewHolder holder) |
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(PreferenceViewHolder) to retrieve the current
summary text for this dialog preference. |
protected boolean |
onHandleDialogButtonClick(Dialog dialog,
int button)
Called from
SettingDialogPreference.handleDialogButtonClick(Dialog, int) if the given dialog has
id associated with this dialog preference. |
protected void |
onSetInitialValue(Object defaultValue) |
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(int resId)
Same as
setEntryValues(String[]) for resource id. |
void |
setEntryValues(String[] 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 |
setSelection(long[] selection)
Sets a selection array containing indexes of preferred entry values that have been specified
via
setEntryValues(String[]) 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, handleDialogButtonClick, setDialogId, setOnClickListener, synchronizeSummaryViewsetKeycallChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getParent, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPersistedStringSet, getPreferenceDataStore, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getSummaryProvider, getTitle, getWidgetLayoutResource, hasKey, isCopyingEnabled, isEnabled, isIconSpaceReserved, isPersistent, isSelectable, isShown, isSingleLineTitle, isVisible, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttached, onAttachedToHierarchy, onAttachedToHierarchy, onClick, onDependencyChanged, onDetached, onInitializeAccessibilityNodeInfo, onParentChanged, onPrepareForRemoval, onRestoreInstanceState, onSaveInstanceState, onSetInitialValue, peekExtras, performClick, performClick, persistBoolean, persistFloat, persistInt, persistLong, persistString, persistStringSet, restoreHierarchyState, saveHierarchyState, setCopyingEnabled, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIconSpaceReserved, setIntent, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setPreferenceDataStore, setSelectable, setShouldDisableView, setSingleLineTitle, setSummary, setSummary, setSummaryProvider, setTitle, setTitle, setViewId, setVisible, setWidgetLayoutResource, shouldDisableDependents, shouldPersist, toStringpublic SettingSelectionDialogPreference(@NonNull
android.content.Context context)
SettingSelectionDialogPreference(Context, AttributeSet) without attributes.public SettingSelectionDialogPreference(@NonNull
android.content.Context context,
@Nullable
android.util.AttributeSet attrs)
SettingSelectionDialogPreference(Context, AttributeSet, int) with
R.attr.settingSelectionDialogPreferenceStyle as attribute for default style.public SettingSelectionDialogPreference(@NonNull
android.content.Context context,
@Nullable
android.util.AttributeSet attrs,
@AttrRes
int defStyleAttr)
SettingSelectionDialogPreference(Context, AttributeSet, int, int) with 0
as default style.public SettingSelectionDialogPreference(@NonNull
android.content.Context context,
@Nullable
android.util.AttributeSet attrs,
@AttrRes
int defStyleAttr,
@StyleRes
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.@Nullable public static String[] createEntryValuesFromPersistedValues(@NonNull 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.protected Object onGetDefaultValue(@NonNull android.content.res.TypedArray typedArray, int index)
onGetDefaultValue in class androidx.preference.Preferenceprotected void onSetInitialValue(@Nullable
Object defaultValue)
onSetInitialValue in class androidx.preference.Preference@NonNull protected SelectionDialog.SelectionOptions onCreateDialogOptions(@NonNull 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(@NonNull
SelectionDialog.SelectionOptions options,
@NonNull
android.content.Context context,
@Nullable
android.util.AttributeSet attrs,
@AttrRes
int defStyleAttr,
@StyleRes
int defStyleRes)
SettingDialogPreferenceonConfigureDialogOptions in class SettingDialogPreference<SelectionDialog.SelectionOptions>options - The options created via SettingDialogPreference.onCreateDialogOptions(Resources).public void setSummaryTextBuilder(@Nullable
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.public void setEntries(@ArrayRes
int resId)
setEntries(CharSequence[]) for resource id.resId - Resource id of the desired text array with entries.public void setEntries(@Nullable
CharSequence[] entries)
entries - The desired array of entries. May be null to clear the current ones.R.attr.entries,
setEntryValues(String[])@Nullable public CharSequence[] getEntries()
null if no entries have been specified.setEntries(CharSequence[]),
getEntryValues()public void setEntryValues(@ArrayRes
int resId)
setEntryValues(String[]) for resource id.resId - Resource id of the desired text array with values for entries.public void setEntryValues(@Nullable
String[] 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.entryValues@Nullable public String[] getEntryValues()
null if no entry values have been specified.setEntryValues(String[]),
getEntries()public void setSelection(@Nullable
long[] selection)
setEntryValues(String[]) 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()@Nullable public long[] getSelection()
setSelection(long[]),
getSelectedEntryValues(),
getDialogOptions()@Nullable public String[] getSelectedEntryValues()
getSelection()public void onBindViewHolder(@NonNull
androidx.preference.PreferenceViewHolder holder)
onBindViewHolder in class SettingPreference@Nullable protected CharSequence onGetSummaryText()
SettingDialogPreferenceSettingDialogPreference.synchronizeSummaryView(PreferenceViewHolder) 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>@NonNull 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(@NonNull
Dialog dialog,
int button)
SettingDialogPreferenceSettingDialogPreference.handleDialogButtonClick(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.