Methods Summary |
---|
public android.app.Dialog | getDialog()Gets the dialog that is shown by this preference.
return mDialog;
|
public android.graphics.drawable.Drawable | getDialogIcon()Returns the icon to be shown on subsequent dialogs.
return mDialogIcon;
|
public int | getDialogLayoutResource()Returns the layout resource that is used as the content View for
subsequent dialogs.
return mDialogLayoutResId;
|
public java.lang.CharSequence | getDialogMessage()Returns the message to be shown on subsequent dialogs.
return mDialogMessage;
|
public java.lang.CharSequence | getDialogTitle()Returns the title to be shown on subsequent dialogs.
return mDialogTitle;
|
public java.lang.CharSequence | getNegativeButtonText()Returns the text of the negative button to be shown on subsequent
dialogs.
return mNegativeButtonText;
|
public java.lang.CharSequence | getPositiveButtonText()Returns the text of the positive button to be shown on subsequent
dialogs.
return mPositiveButtonText;
|
protected boolean | needInputMethod()Returns whether the preference needs to display a soft input method when the dialog
is displayed. Default is false. Subclasses should override this method if they need
the soft input method brought up automatically.
return false;
|
public void | onActivityDestroy(){@inheritDoc}
if (mDialog == null || !mDialog.isShowing()) {
return;
}
mDialog.dismiss();
|
protected void | onBindDialogView(android.view.View view)Binds views in the content View of the dialog to data.
Make sure to call through to the superclass implementation.
View dialogMessageView = view.findViewById(com.android.internal.R.id.message);
if (dialogMessageView != null) {
final CharSequence message = getDialogMessage();
int newVisibility = View.GONE;
if (!TextUtils.isEmpty(message)) {
if (dialogMessageView instanceof TextView) {
((TextView) dialogMessageView).setText(message);
}
newVisibility = View.VISIBLE;
}
if (dialogMessageView.getVisibility() != newVisibility) {
dialogMessageView.setVisibility(newVisibility);
}
}
|
protected void | onClick()
if (mDialog != null && mDialog.isShowing()) return;
showDialog(null);
|
public void | onClick(android.content.DialogInterface dialog, int which)
mWhichButtonClicked = which;
|
protected android.view.View | onCreateDialogView()Creates the content view for the dialog (if a custom content view is
required). By default, it inflates the dialog layout resource if it is
set.
if (mDialogLayoutResId == 0) {
return null;
}
LayoutInflater inflater = LayoutInflater.from(mBuilder.getContext());
return inflater.inflate(mDialogLayoutResId, null);
|
protected void | onDialogClosed(boolean positiveResult)Called when the dialog is dismissed and should be used to save data to
the {@link SharedPreferences}.
|
public void | onDismiss(android.content.DialogInterface dialog)
getPreferenceManager().unregisterOnActivityDestroyListener(this);
mDialog = null;
onDialogClosed(mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE);
|
protected void | onPrepareDialogBuilder(AlertDialog.Builder builder)Prepares the dialog builder to be shown when the preference is clicked.
Use this to set custom properties on the dialog.
Do not {@link AlertDialog.Builder#create()} or
{@link AlertDialog.Builder#show()}.
|
protected void | onRestoreInstanceState(android.os.Parcelable state)
if (state == null || !state.getClass().equals(SavedState.class)) {
// Didn't save state for us in onSaveInstanceState
super.onRestoreInstanceState(state);
return;
}
SavedState myState = (SavedState) state;
super.onRestoreInstanceState(myState.getSuperState());
if (myState.isDialogShowing) {
showDialog(myState.dialogBundle);
}
|
protected android.os.Parcelable | onSaveInstanceState()
final Parcelable superState = super.onSaveInstanceState();
if (mDialog == null || !mDialog.isShowing()) {
return superState;
}
final SavedState myState = new SavedState(superState);
myState.isDialogShowing = true;
myState.dialogBundle = mDialog.onSaveInstanceState();
return myState;
|
private void | requestInputMethod(android.app.Dialog dialog)Sets the required flags on the dialog window to enable input method window to show up.
Window window = dialog.getWindow();
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
public void | setDialogIcon(android.graphics.drawable.Drawable dialogIcon)Sets the icon of the dialog. This will be shown on subsequent dialogs.
mDialogIcon = dialogIcon;
|
public void | setDialogIcon(int dialogIconRes)Sets the icon (resource ID) of the dialog. This will be shown on
subsequent dialogs.
mDialogIcon = getContext().getDrawable(dialogIconRes);
|
public void | setDialogLayoutResource(int dialogLayoutResId)Sets the layout resource that is inflated as the {@link View} to be shown
as the content View of subsequent dialogs.
mDialogLayoutResId = dialogLayoutResId;
|
public void | setDialogMessage(java.lang.CharSequence dialogMessage)Sets the message of the dialog. This will be shown on subsequent dialogs.
This message forms the content View of the dialog and conflicts with
list-based dialogs, for example. If setting a custom View on a dialog via
{@link #setDialogLayoutResource(int)}, include a text View with ID
{@link android.R.id#message} and it will be populated with this message.
mDialogMessage = dialogMessage;
|
public void | setDialogMessage(int dialogMessageResId)
setDialogMessage(getContext().getString(dialogMessageResId));
|
public void | setDialogTitle(java.lang.CharSequence dialogTitle)Sets the title of the dialog. This will be shown on subsequent dialogs.
mDialogTitle = dialogTitle;
|
public void | setDialogTitle(int dialogTitleResId)
setDialogTitle(getContext().getString(dialogTitleResId));
|
public void | setNegativeButtonText(java.lang.CharSequence negativeButtonText)Sets the text of the negative button of the dialog. This will be shown on
subsequent dialogs.
mNegativeButtonText = negativeButtonText;
|
public void | setNegativeButtonText(int negativeButtonTextResId)
setNegativeButtonText(getContext().getString(negativeButtonTextResId));
|
public void | setPositiveButtonText(java.lang.CharSequence positiveButtonText)Sets the text of the positive button of the dialog. This will be shown on
subsequent dialogs.
mPositiveButtonText = positiveButtonText;
|
public void | setPositiveButtonText(int positiveButtonTextResId)
setPositiveButtonText(getContext().getString(positiveButtonTextResId));
|
protected void | showDialog(android.os.Bundle state)Shows the dialog associated with this Preference. This is normally initiated
automatically on clicking on the preference. Call this method if you need to
show the dialog on some other event.
Context context = getContext();
mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;
mBuilder = new AlertDialog.Builder(context)
.setTitle(mDialogTitle)
.setIcon(mDialogIcon)
.setPositiveButton(mPositiveButtonText, this)
.setNegativeButton(mNegativeButtonText, this);
View contentView = onCreateDialogView();
if (contentView != null) {
onBindDialogView(contentView);
mBuilder.setView(contentView);
} else {
mBuilder.setMessage(mDialogMessage);
}
onPrepareDialogBuilder(mBuilder);
getPreferenceManager().registerOnActivityDestroyListener(this);
// Create the dialog
final Dialog dialog = mDialog = mBuilder.create();
if (state != null) {
dialog.onRestoreInstanceState(state);
}
if (needInputMethod()) {
requestInputMethod(dialog);
}
dialog.setOnDismissListener(this);
dialog.show();
|