public class SettingDialogPreferenceManager extends Object implements SettingDialogPreference.OnClickListener
dialog prefernces presented on
a single preference screen. This manager handles attaching of SettingDialogPreference.OnClickListener
to all dialog preferences of PreferenceScreen passed to attachToPreferenceScreen(PreferenceScreen)
and showing of preference dialogs for the associated dialog preferences whenever
SettingDialogPreference.OnClickListener.onDialogPreferenceClick(SettingDialogPreference)
is fired for a particular dialog preference. Dialog preferences manager also provides default
handling of button click events occurred in those shown preference dialogs via
handlePreferenceDialogButtonClick(Dialog, int) where this method delegates the click
event to the associated dialog preference via SettingDialogPreference.handleDialogButtonClick(Dialog, int).
Subclasses may inherit this manager and override any default behavior as needed.
| Constructor and Description |
|---|
SettingDialogPreferenceManager()
Creates a new instance of SettingDialogPreferencesManager without either
DialogController
nor default DialogFactory. |
SettingDialogPreferenceManager(androidx.fragment.app.Fragment fragment)
Creates a new instance of SettingDialogPreferencesManager for the given fragment
context.
|
SettingDialogPreferenceManager(androidx.fragment.app.FragmentActivity activity)
Creates a new instance of SettingDialogPreferencesManager for the given activity
context.
|
SettingDialogPreferenceManager(androidx.fragment.app.FragmentManager fragmentManager)
Creates a new instance of SettingDialogPreferencesManager for the given fragmentManager
context.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attachToPreferenceScreen(androidx.preference.PreferenceScreen screen)
Attaches this manager to the given screen.
|
void |
detachFromPreferenceScreen(androidx.preference.PreferenceScreen screen)
Detaches this manager from the given screen if previously attached via
attachToPreferenceScreen(PreferenceScreen). |
SettingDialogPreference |
findDialogPreference(int dialogId)
Searches for the dialog preference associated with the specified dialogId.
|
DialogController |
getDialogController()
Returns the dialog controller used by this manager.
|
DialogFactory |
getDialogFactory()
Returns the current dialog factory set to this manager.
|
boolean |
handlePreferenceDialogButtonClick(Dialog dialog,
int button)
Handles button click occurred in the given preference dialog.
|
protected void |
onAttachedToPreference(SettingDialogPreference preference)
Called when this manager has been successfully attached to the given preference.
|
protected void |
onDetachedFromPreference(SettingDialogPreference preference)
Called when this manager has been successfully detached from the given preference.
|
boolean |
onDialogPreferenceClick(SettingDialogPreference preference)
This implementation check whether this manager has dialog factory attached and also if that
factory provides dialog instance with dialog id associated with the clicked preference.
|
protected boolean |
onShowPreferenceDialog(DialogController dialogController,
SettingDialogPreference preference)
Called from
onDialogPreferenceClick(SettingDialogPreference) to show a dialog for
the clicked preference. |
void |
setDialogController(DialogController dialogController)
Sets a dialog controller that should be used by this manager to show dialogs for the clicked
dialog preferences.
|
void |
setDialogFactory(DialogFactory factory)
Sets a factory that provides dialog instances associated with the clicked dialog preferences.
|
public SettingDialogPreferenceManager()
DialogController
nor default DialogFactory.
These should be specified via setDialogController(DialogController) and
setDialogFactory(DialogFactory) otherwise the new manager will throw an exception if
functionality related to dialogs is requested.
public SettingDialogPreferenceManager(@NonNull
androidx.fragment.app.FragmentActivity activity)
This constructor creates this manager with default instance of DialogController and
default DialogXmlFactory with R.xml.setting_dialogs file containing dialogs
for all dialog preferences provided by the Settings library.
activity - The activity used to instantiate the default dialog controller along with
default dialog factory.SettingDialogPreferenceManager(Fragment),
DialogController.create(FragmentActivity),
getDialogController(),
getDialogFactory()public SettingDialogPreferenceManager(@NonNull
androidx.fragment.app.Fragment fragment)
This constructor creates this manager with default instance of DialogController and
default DialogXmlFactory with R.xml.setting_dialogs file containing dialogs
for all dialog preferences provided by the Settings library.
fragment - The fragment used to instantiate the default dialog controller along with
default dialog factory.SettingDialogPreferenceManager(FragmentActivity),
DialogController.create(Fragment),
getDialogController(),
getDialogFactory()public SettingDialogPreferenceManager(@NonNull
androidx.fragment.app.FragmentManager fragmentManager)
This constructor creates this manager with default instance of DialogController. The
dialog factory need to be specified via setDialogFactory(DialogFactory)
fragmentManager - The fragment manager used to instantiate the default dialog controller.DialogController.DialogController(FragmentManager),
getDialogController()public void setDialogController(@NonNull
DialogController dialogController)
Note, that if the specified dialog controller does not have specified any dialog factory,
the one specified for this manager will be set to it via DialogController.setFactory(DialogFactory).
dialogController - The desired dialog controller.getDialogController(),
setDialogFactory(DialogFactory)@Nullable public DialogController getDialogController()
setDialogController(DialogController).SettingDialogPreferenceManager(FragmentActivity),
SettingDialogPreferenceManager(Fragment),
SettingDialogPreferenceManager(FragmentManager)public void setDialogFactory(@Nullable
DialogFactory factory)
DialogController.setFactory(DialogFactory).factory - The desired dialog factory. May be null to clear the current one.getDialogFactory(),
setDialogController(DialogController)@Nullable public DialogFactory getDialogFactory()
setDialogFactory(DialogFactory).setDialogFactory(DialogFactory),
SettingDialogPreferenceManager(FragmentActivity),
SettingDialogPreferenceManager(Fragment)public void attachToPreferenceScreen(@NonNull
androidx.preference.PreferenceScreen screen)
Dialog preferences manager will use the preference screen to look up for all instances of
dialog preferences that are added to that preference screen.
To all those dialog preferences is than this manager attached as SettingDialogPreference.OnClickListener
so it may receive the preference click callback and show dialog for that particular preference.
The context that is using this manager should dispatch Dialog.OnDialogListener#onDialogButtonClick(Dialog, int)
callback to this manager via handlePreferenceDialogButtonClick(Dialog, int).
When this manager is no more needed it should be detached from the attached preference screen
via detachFromPreferenceScreen(PreferenceScreen).
screen - The preference screen to attach to.protected void onAttachedToPreference(@NonNull
SettingDialogPreference preference)
preference - The dialog preference to which has been this manager just attached.attachToPreferenceScreen(PreferenceScreen)@Nullable public SettingDialogPreference findDialogPreference(int dialogId)
Note, that the manager should be attached to preference screen via
attachToPreferenceScreen(PreferenceScreen) otherwise this method will always return
null.
dialogId - Id of the dialog associated with the desired preference to find.null if this manager is not attached to preference
screen at this time or there is no dialog preference with such dialog id associated.public void detachFromPreferenceScreen(@NonNull
androidx.preference.PreferenceScreen screen)
attachToPreferenceScreen(PreferenceScreen).screen - The preference screen from which to detach this manager.protected void onDetachedFromPreference(@NonNull
SettingDialogPreference preference)
preference - The dialog preference from which has been this manager just detached.detachFromPreferenceScreen(PreferenceScreen)public boolean onDialogPreferenceClick(@NonNull
SettingDialogPreference preference)
onShowPreferenceDialog(DialogController, SettingDialogPreference) is called
to show the preference dialog.onDialogPreferenceClick in interface SettingDialogPreference.OnClickListenerpreference - The clicked dialog preference.True if the click event has been handled, false otherwise.protected boolean onShowPreferenceDialog(@NonNull
DialogController dialogController,
@NonNull
SettingDialogPreference preference)
onDialogPreferenceClick(SettingDialogPreference) to show a dialog for
the clicked preference.dialogController - Current dialog controller of this manager that may be used to show
the dialog associated with the clicked preference..preference - The preference that has been clicked.True if the preference dialog has been successfully shown, false otherwise.public boolean handlePreferenceDialogButtonClick(@NonNull
Dialog dialog,
int button)
dialog - The preference dialog where the button has been clicked.button - The clicked dialog button.True if this manager is attached to preference screen and the button click
has been successfully handled by the associated dialog preference, false otherwise.SettingDialogPreference.handleDialogButtonClick(Dialog, int)