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
handleOnPreferenceDialogButtonClick(Dialog, int) where this method delegates the click
event to the associated dialog preference via SettingDialogPreference.handleOnDialogButtonClick(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(android.app.Activity activity)
Creates a new instance of SettingDialogPreferencesManager for the given activity
context.
|
SettingDialogPreferenceManager(android.app.Fragment fragment)
Creates a new instance of SettingDialogPreferencesManager for the given fragment
context.
|
SettingDialogPreferenceManager(android.app.FragmentManager fragmentManager)
Creates a new instance of SettingDialogPreferencesManager for the given fragmentManager
context.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attachToPreferenceScreen(android.preference.PreferenceScreen preferenceScreen)
Attaches this manager to the given preferenceScreen.
|
void |
detachFromPreferenceScreen(android.preference.PreferenceScreen preferenceScreen)
Detaches this manager from the given preferenceScreen 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 |
handleOnPreferenceDialogButtonClick(Dialog dialog,
int button)
Handles button click occurred in the given preference dialog.
|
protected void |
onAttachedToPreference(SettingDialogPreference dialogPreference)
Called when this manager has been successfully attached to the given dialogPreference.
|
protected void |
onDetachedFromPreference(SettingDialogPreference dialogPreference)
Called when this manager has been successfully detached from the given dialogPreference.
|
boolean |
onDialogPreferenceClick(SettingDialogPreference dialogPreference)
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 dialogPreference.
|
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 dialogFactory)
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(android.app.Activity activity)
This constructor creates this manager with default instance of DialogController and
default DialogXmlFactory with R.xml#ui_settings_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#DialogController(Activity),
getDialogController(),
getDialogFactory()public SettingDialogPreferenceManager(android.app.Fragment fragment)
This constructor creates this manager with default instance of DialogController and
default DialogXmlFactory with R.xml#ui_settings_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(Activity),
DialogController#DialogController(Fragment),
getDialogController(),
getDialogFactory()public SettingDialogPreferenceManager(android.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(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)public DialogController getDialogController()
setDialogController(DialogController).SettingDialogPreferenceManager(Activity),
SettingDialogPreferenceManager(Fragment),
SettingDialogPreferenceManager(FragmentManager)public void setDialogFactory(DialogFactory dialogFactory)
DialogController#setFactory(DialogFactory).dialogFactory - The desired dialog factory. May be null to clear the current one.getDialogFactory(),
setDialogController(DialogController)public DialogFactory getDialogFactory()
setDialogFactory(DialogFactory)setDialogFactory(DialogFactory),
SettingDialogPreferenceManager(Activity),
SettingDialogPreferenceManager(Fragment)public void attachToPreferenceScreen(android.preference.PreferenceScreen preferenceScreen)
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 handleOnPreferenceDialogButtonClick(Dialog, int).
When this manager is no more needed it should be detached from the attached preference screen
via detachFromPreferenceScreen(PreferenceScreen).
preferenceScreen - The preference screen to attach to.protected void onAttachedToPreference(SettingDialogPreference dialogPreference)
dialogPreference - The dialog preference to which has been this manager just attached.attachToPreferenceScreen(PreferenceScreen)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(android.preference.PreferenceScreen preferenceScreen)
attachToPreferenceScreen(PreferenceScreen).preferenceScreen - The preference screen from which to detach this manager.protected void onDetachedFromPreference(SettingDialogPreference dialogPreference)
dialogPreference - The dialog preference from which has been this manager just detached.detachFromPreferenceScreen(PreferenceScreen)public boolean onDialogPreferenceClick(SettingDialogPreference dialogPreference)
onShowPreferenceDialog(DialogController, SettingDialogPreference) is called
to show the preference dialog.onDialogPreferenceClick in interface SettingDialogPreference.OnClickListenerdialogPreference - The clicked dialog preference.True if the click event has been handled, false otherwise.protected boolean onShowPreferenceDialog(DialogController dialogController,
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 handleOnPreferenceDialogButtonClick(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.handleOnDialogButtonClick(Dialog, int)