O - Type of the dialog options specific for type of the dialog associated with this preference.public class SettingDialogPreference<O extends DialogOptions<O>> extends SettingPreference
SettingPreference implementation that may be used to show a preference dialog. Each
dialog preference has specified id of the associated dialog, via dialog:dialogId
attribute, that may be obtained via getDialogId(). Dialog preference also provides an
options for its associated dialog that may be obtained via getDialogOptions(). Default
values for the dialog options are parsed from the Xml for the attributes specified in the section
below.
Subclasses should override onCreateDialogOptions(Resources) to create type of options
that are specific for theirs associated type of dialog along with
onConfigureDialogOptions(DialogOptions, Context, AttributeSet, int, int) where these
options should be configured from the provided AttributeSet. Also
onHandleDialogButtonClick(Dialog, int) should be override to provide default handling of
dialog button click event.
SettingPreference,
SettingDialogPreference Attributes
android:dialogPreferenceStyle| Modifier and Type | Class and Description |
|---|---|
static interface |
SettingDialogPreference.OnClickListener
Listener that may be used to receive a callback that a specific dialog preference has been clicked.
|
androidx.preference.Preference.BaseSavedState, androidx.preference.Preference.OnPreferenceChangeListener, androidx.preference.Preference.OnPreferenceClickListener, androidx.preference.Preference.SummaryProvider<T extends androidx.preference.Preference>| Modifier and Type | Field and Description |
|---|---|
static int |
NO_DIALOG_ID
Constant identifying no dialog id.
|
| Constructor and Description |
|---|
SettingDialogPreference(android.content.Context context)
Same as
SettingDialogPreference(Context, AttributeSet) without attributes. |
SettingDialogPreference(android.content.Context context,
android.util.AttributeSet attrs)
Same as
SettingDialogPreference(Context, AttributeSet, int) with
R.attr.dialogPreferenceStyle as attribute for default style. |
SettingDialogPreference(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr)
Same as
SettingDialogPreference(Context, AttributeSet, int, int) with 0 as
default style. |
SettingDialogPreference(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Creates a new instance of SettingDialogPreference for the given context.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getDialogId()
Returns id of the dialog associated with this dialog preference.
|
O |
getDialogOptions()
Returns the dialog options specific for the dialog associated with this dialog preference.
|
boolean |
handleDialogButtonClick(Dialog dialog,
int button)
Handles click event for the specified button occurred in the given dialog.
|
protected void |
onConfigureDialogOptions(O 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 O |
onCreateDialogOptions(android.content.res.Resources resources)
Called to create instance of dialog options specific for this dialog preference.
|
protected CharSequence |
onGetSummaryText()
Called from
synchronizeSummaryView(PreferenceViewHolder) to retrieve the current
summary text for this dialog preference. |
protected boolean |
onHandleDialogButtonClick(Dialog dialog,
int button)
Called from
handleDialogButtonClick(Dialog, int) if the given dialog has
id associated with this dialog preference. |
void |
setDialogId(int dialogId)
Specifies id of a dialog that is associated with this preference.
|
void |
setOnClickListener(SettingDialogPreference.OnClickListener listener)
Registers a callback to be invoked whenever this dialog preference is clicked.
|
protected void |
synchronizeSummaryView(androidx.preference.PreferenceViewHolder holder)
Performs synchronization of the summary view of this dialog preference.
|
onBindViewHolder, setKeycallChangeListener, 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, onGetDefaultValue, onInitializeAccessibilityNodeInfo, onParentChanged, onPrepareForRemoval, onRestoreInstanceState, onSaveInstanceState, onSetInitialValue, 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 static final int NO_DIALOG_ID
getDialogId(),
Constant Field Valuespublic SettingDialogPreference(@NonNull
android.content.Context context)
SettingDialogPreference(Context, AttributeSet) without attributes.public SettingDialogPreference(@NonNull
android.content.Context context,
@Nullable
android.util.AttributeSet attrs)
SettingDialogPreference(Context, AttributeSet, int) with
R.attr.dialogPreferenceStyle as attribute for default style.public SettingDialogPreference(@NonNull
android.content.Context context,
@Nullable
android.util.AttributeSet attrs,
@AttrRes
int defStyleAttr)
SettingDialogPreference(Context, AttributeSet, int, int) with 0 as
default style.public SettingDialogPreference(@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.protected void onConfigureDialogOptions(@NonNull
O options,
@NonNull
android.content.Context context,
@Nullable
android.util.AttributeSet attrs,
@AttrRes
int defStyleAttr,
@StyleRes
int defStyleRes)
options - The options created via onCreateDialogOptions(Resources).@NonNull protected O onCreateDialogOptions(@NonNull android.content.res.Resources resources)
Default implementation creates instance of DialogOptions.
resources - Application resources that may be used supply default values from resources
for the options.public void setOnClickListener(@Nullable
SettingDialogPreference.OnClickListener listener)
Note, that this method uses Preference.setOnPreferenceClickListener(OnPreferenceClickListener)
to register the requested callback. Any previously registered OnPreferenceClickListener
will be replaced.
listener - The desired callback. May be null to clear the current one.protected void synchronizeSummaryView(@NonNull
androidx.preference.PreferenceViewHolder holder)
Default implementation takes the summary text provided by onGetSummaryText() method
and sets is text for the summary view, changing its visibility so the summary view is visible
if there is some summary text available or gone if there is no summary text available.
This method may be called from {@link #onBindViewHolder(PreferenceViewHolder).
holder - The view holder of this preference.@Nullable protected CharSequence onGetSummaryText()
synchronizeSummaryView(PreferenceViewHolder) to retrieve the current
summary text for this dialog preference.
Default implementation returns the text provided by Preference.getSummary() method.
public void setDialogId(int dialogId)
dialogId - Id of the desired dialog.getDialogId()public int getDialogId()
Default value: NO_DIALOG_ID
setDialogId(int),
dialog:dialogId@NonNull public O getDialogOptions()
Subclasses may override this method and provide the dialog options with the current preferred value so it may be properly displayed in the associated dialog.
public boolean handleDialogButtonClick(@NonNull
Dialog dialog,
int button)
dialog - The dialog where the button has been clicked.button - The clicked dialog button.True if the dialog has id associated with this preference and the button click
event has been successfully handled by this preference, false otherwise so it should
be handled by the caller.protected boolean onHandleDialogButtonClick(@NonNull
Dialog dialog,
int button)
handleDialogButtonClick(Dialog, int) if the given dialog has
id associated with this dialog preference.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.