Clean up AlertDialog javadocs, add overlay theme for dialogs

Also cleans up CheckedTextView javadocs.

Bug: 19482450
Change-Id: I47559533784b19267e9381af10c456ce0d20d329
This commit is contained in:
Alan Viverette
2015-02-23 17:15:27 -08:00
parent b3f3762ee0
commit 49f118ef08
7 changed files with 349 additions and 222 deletions

View File

@@ -2018,6 +2018,7 @@ package android {
field public static final int ThemeOverlay_Material_ActionBar = 16974409; // 0x1030249
field public static final int ThemeOverlay_Material_Dark = 16974411; // 0x103024b
field public static final int ThemeOverlay_Material_Dark_ActionBar = 16974412; // 0x103024c
field public static final int ThemeOverlay_Material_Dialog = 16974564; // 0x10302e4
field public static final int ThemeOverlay_Material_Light = 16974410; // 0x103024a
field public static final int Theme_Black = 16973832; // 0x1030008
field public static final int Theme_Black_NoTitleBar = 16973833; // 0x1030009
@@ -3745,8 +3746,8 @@ package android.app {
public class AlertDialog extends android.app.Dialog implements android.content.DialogInterface {
ctor protected AlertDialog(android.content.Context);
ctor protected AlertDialog(android.content.Context, int);
ctor protected AlertDialog(android.content.Context, boolean, android.content.DialogInterface.OnCancelListener);
ctor protected AlertDialog(android.content.Context, int);
method public android.widget.Button getButton(int);
method public android.widget.ListView getListView();
method public void setButton(int, java.lang.CharSequence, android.os.Message);
@@ -3765,11 +3766,11 @@ package android.app {
method public void setMessage(java.lang.CharSequence);
method public void setView(android.view.View);
method public void setView(android.view.View, int, int, int, int);
field public static final int THEME_DEVICE_DEFAULT_DARK = 4; // 0x4
field public static final int THEME_DEVICE_DEFAULT_LIGHT = 5; // 0x5
field public static final int THEME_HOLO_DARK = 2; // 0x2
field public static final int THEME_HOLO_LIGHT = 3; // 0x3
field public static final int THEME_TRADITIONAL = 1; // 0x1
field public static final deprecated int THEME_DEVICE_DEFAULT_DARK = 4; // 0x4
field public static final deprecated int THEME_DEVICE_DEFAULT_LIGHT = 5; // 0x5
field public static final deprecated int THEME_HOLO_DARK = 2; // 0x2
field public static final deprecated int THEME_HOLO_LIGHT = 3; // 0x3
field public static final deprecated int THEME_TRADITIONAL = 1; // 0x1
}
public static class AlertDialog.Builder {
@@ -3784,7 +3785,7 @@ package android.app {
method public android.app.AlertDialog.Builder setIcon(int);
method public android.app.AlertDialog.Builder setIcon(android.graphics.drawable.Drawable);
method public android.app.AlertDialog.Builder setIconAttribute(int);
method public android.app.AlertDialog.Builder setInverseBackgroundForced(boolean);
method public deprecated android.app.AlertDialog.Builder setInverseBackgroundForced(boolean);
method public android.app.AlertDialog.Builder setItems(int, android.content.DialogInterface.OnClickListener);
method public android.app.AlertDialog.Builder setItems(java.lang.CharSequence[], android.content.DialogInterface.OnClickListener);
method public android.app.AlertDialog.Builder setMessage(int);

View File

@@ -2096,6 +2096,7 @@ package android {
field public static final int ThemeOverlay_Material_ActionBar = 16974409; // 0x1030249
field public static final int ThemeOverlay_Material_Dark = 16974411; // 0x103024b
field public static final int ThemeOverlay_Material_Dark_ActionBar = 16974412; // 0x103024c
field public static final int ThemeOverlay_Material_Dialog = 16974564; // 0x10302e4
field public static final int ThemeOverlay_Material_Light = 16974410; // 0x103024a
field public static final int Theme_Black = 16973832; // 0x1030008
field public static final int Theme_Black_NoTitleBar = 16973833; // 0x1030009
@@ -3834,8 +3835,8 @@ package android.app {
public class AlertDialog extends android.app.Dialog implements android.content.DialogInterface {
ctor protected AlertDialog(android.content.Context);
ctor protected AlertDialog(android.content.Context, int);
ctor protected AlertDialog(android.content.Context, boolean, android.content.DialogInterface.OnCancelListener);
ctor protected AlertDialog(android.content.Context, int);
method public android.widget.Button getButton(int);
method public android.widget.ListView getListView();
method public void setButton(int, java.lang.CharSequence, android.os.Message);
@@ -3854,11 +3855,11 @@ package android.app {
method public void setMessage(java.lang.CharSequence);
method public void setView(android.view.View);
method public void setView(android.view.View, int, int, int, int);
field public static final int THEME_DEVICE_DEFAULT_DARK = 4; // 0x4
field public static final int THEME_DEVICE_DEFAULT_LIGHT = 5; // 0x5
field public static final int THEME_HOLO_DARK = 2; // 0x2
field public static final int THEME_HOLO_LIGHT = 3; // 0x3
field public static final int THEME_TRADITIONAL = 1; // 0x1
field public static final deprecated int THEME_DEVICE_DEFAULT_DARK = 4; // 0x4
field public static final deprecated int THEME_DEVICE_DEFAULT_LIGHT = 5; // 0x5
field public static final deprecated int THEME_HOLO_DARK = 2; // 0x2
field public static final deprecated int THEME_HOLO_LIGHT = 3; // 0x3
field public static final deprecated int THEME_TRADITIONAL = 1; // 0x1
}
public static class AlertDialog.Builder {
@@ -3873,7 +3874,7 @@ package android.app {
method public android.app.AlertDialog.Builder setIcon(int);
method public android.app.AlertDialog.Builder setIcon(android.graphics.drawable.Drawable);
method public android.app.AlertDialog.Builder setIconAttribute(int);
method public android.app.AlertDialog.Builder setInverseBackgroundForced(boolean);
method public deprecated android.app.AlertDialog.Builder setInverseBackgroundForced(boolean);
method public android.app.AlertDialog.Builder setItems(int, android.content.DialogInterface.OnClickListener);
method public android.app.AlertDialog.Builder setItems(java.lang.CharSequence[], android.content.DialogInterface.OnClickListener);
method public android.app.AlertDialog.Builder setMessage(int);

View File

@@ -38,6 +38,8 @@ import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.android.internal.R;
/**
* A subclass of Dialog that can display one, two or three buttons. If you only want to
* display a String in this dialog box, use the setMessage() method. If you
@@ -48,7 +50,7 @@ import android.widget.ListView;
* FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom);
* fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
* </pre>
*
*
* <p>The AlertDialog class takes care of automatically setting
* {@link WindowManager.LayoutParams#FLAG_ALT_FOCUSABLE_IM
* WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM} for you based on whether
@@ -70,31 +72,46 @@ public class AlertDialog extends Dialog implements DialogInterface {
/**
* Special theme constant for {@link #AlertDialog(Context, int)}: use
* the traditional (pre-Holo) alert dialog theme.
*
* @deprecated Use {@link android.R.style#Theme_Material_Dialog_Alert}.
*/
@Deprecated
public static final int THEME_TRADITIONAL = 1;
/**
* Special theme constant for {@link #AlertDialog(Context, int)}: use
* the holographic alert theme with a dark background.
*
* @deprecated Use {@link android.R.style#Theme_Material_Dialog_Alert}.
*/
@Deprecated
public static final int THEME_HOLO_DARK = 2;
/**
* Special theme constant for {@link #AlertDialog(Context, int)}: use
* the holographic alert theme with a light background.
*
* @deprecated Use {@link android.R.style#Theme_Material_Light_Dialog_Alert}.
*/
@Deprecated
public static final int THEME_HOLO_LIGHT = 3;
/**
* Special theme constant for {@link #AlertDialog(Context, int)}: use
* the device's default alert theme with a dark background.
*
* @deprecated Use {@link android.R.style#Theme_DeviceDefault_Dialog_Alert}.
*/
@Deprecated
public static final int THEME_DEVICE_DEFAULT_DARK = 4;
/**
* Special theme constant for {@link #AlertDialog(Context, int)}: use
* the device's default alert theme with a light background.
*
* @deprecated Use {@link android.R.style#Theme_DeviceDefault_Light_Dialog_Alert}.
*/
@Deprecated
public static final int THEME_DEVICE_DEFAULT_LIGHT = 5;
/**
@@ -108,55 +125,92 @@ public class AlertDialog extends Dialog implements DialogInterface {
* @hide
*/
public static final int LAYOUT_HINT_SIDE = 1;
/**
* Creates an alert dialog that uses the default alert dialog theme.
* <p>
* The default alert dialog theme is defined by
* {@link android.R.attr#alertDialogTheme} within the parent
* {@code context}'s theme.
*
* @param context the parent context
*/
protected AlertDialog(Context context) {
this(context, resolveDialogTheme(context, 0), true);
this(context, 0);
}
/**
* Construct an AlertDialog that uses an explicit theme. The actual style
* that an AlertDialog uses is a private implementation, however you can
* here supply either the name of an attribute in the theme from which
* to get the dialog's style (such as {@link android.R.attr#alertDialogTheme}
* or one of the constants {@link #THEME_TRADITIONAL},
* {@link #THEME_HOLO_DARK}, or {@link #THEME_HOLO_LIGHT}.
* Creates an alert dialog that uses the default alert dialog theme and a
* custom cancel listener.
* <p>
* This is functionally identical to:
* <pre>
* AlertDialog dialog = new AlertDialog(context);
* alertDialog.setCancelable(cancelable);
* alertDialog.setOnCancelListener(cancelListener);
* </pre>
* <p>
* The default alert dialog theme is defined by
* {@link android.R.attr#alertDialogTheme} within the parent
* {@code context}'s theme.
*
* @param context the parent context
*/
protected AlertDialog(Context context, @AttrRes int theme) {
this(context, theme, true);
protected AlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
this(context, 0);
setCancelable(cancelable);
setOnCancelListener(cancelListener);
}
AlertDialog(Context context, int theme, boolean createThemeContextWrapper) {
super(context, resolveDialogTheme(context, theme), createThemeContextWrapper);
/**
* Creates an alert dialog that uses an explicit theme resource.
* <p>
* The specified theme resource ({@code themeResId}) is applied on top of
* the parent {@code context}'s theme. It may be specified as a style
* resource containing a fully-populated theme, such as
* {@link android.R.style#Theme_Material_Dialog}, to replace all attributes
* in the parent {@code context}'s theme including primary and accent
* colors.
* <p>
* To preserve attributes such as primary and accent colors, the
* {@code themeResId} may instead be specified as an overlay theme such as
* {@link android.R.style#ThemeOverlay_Material_Dialog}. This will override
* only the window attributes necessary to style the alert window as a
* dialog.
* <p>
* Alternatively, the {@code themeResId} may be specified as {@code 0} to
* use the parent {@code context}'s resolved value for
* {@link android.R.attr#alertDialogTheme}.
*
* @param context the parent context
* @param themeResId the resource ID of the theme against which to inflate
* this dialog, or {@code 0} to use the parent
* {@code context}'s default alert dialog theme
*/
protected AlertDialog(Context context, @AttrRes int themeResId) {
super(context, resolveDialogTheme(context, themeResId));
mWindow.alwaysReadCloseOnTouchAttr();
mAlert = new AlertController(getContext(), this, getWindow());
}
protected AlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, resolveDialogTheme(context, 0));
mWindow.alwaysReadCloseOnTouchAttr();
setCancelable(cancelable);
setOnCancelListener(cancelListener);
mAlert = new AlertController(context, this, getWindow());
}
static int resolveDialogTheme(Context context, int resid) {
if (resid == THEME_TRADITIONAL) {
return com.android.internal.R.style.Theme_Dialog_Alert;
} else if (resid == THEME_HOLO_DARK) {
return com.android.internal.R.style.Theme_Holo_Dialog_Alert;
} else if (resid == THEME_HOLO_LIGHT) {
return com.android.internal.R.style.Theme_Holo_Light_Dialog_Alert;
} else if (resid == THEME_DEVICE_DEFAULT_DARK) {
return com.android.internal.R.style.Theme_DeviceDefault_Dialog_Alert;
} else if (resid == THEME_DEVICE_DEFAULT_LIGHT) {
return com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog_Alert;
} else if (resid >= 0x01000000) { // start of real resource IDs.
return resid;
static int resolveDialogTheme(Context context, int themeResId) {
if (themeResId == THEME_TRADITIONAL) {
return R.style.Theme_Dialog_Alert;
} else if (themeResId == THEME_HOLO_DARK) {
return R.style.Theme_Holo_Dialog_Alert;
} else if (themeResId == THEME_HOLO_LIGHT) {
return R.style.Theme_Holo_Light_Dialog_Alert;
} else if (themeResId == THEME_DEVICE_DEFAULT_DARK) {
return R.style.Theme_DeviceDefault_Dialog_Alert;
} else if (themeResId == THEME_DEVICE_DEFAULT_LIGHT) {
return R.style.Theme_DeviceDefault_Light_Dialog_Alert;
} else if (themeResId >= 0x01000000) { // start of real resource IDs.
return themeResId;
} else {
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(com.android.internal.R.attr.alertDialogTheme,
outValue, true);
final TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.alertDialogTheme, outValue, true);
return outValue.resourceId;
}
}
@@ -177,13 +231,13 @@ public class AlertDialog extends Dialog implements DialogInterface {
/**
* Gets the list view used in the dialog.
*
*
* @return The {@link ListView} from the dialog.
*/
public ListView getListView() {
return mAlert.getListView();
}
@Override
public void setTitle(CharSequence title) {
super.setTitle(title);
@@ -196,7 +250,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
public void setCustomTitle(View customTitleView) {
mAlert.setCustomTitle(customTitleView);
}
public void setMessage(CharSequence message) {
mAlert.setMessage(message);
}
@@ -207,9 +261,9 @@ public class AlertDialog extends Dialog implements DialogInterface {
public void setView(View view) {
mAlert.setView(view);
}
/**
* Set the view to display in that dialog, specifying the spacing to appear around that
* Set the view to display in that dialog, specifying the spacing to appear around that
* view.
*
* @param view The view to show in the content area of the dialog
@@ -233,7 +287,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
/**
* Set a message to be sent when a button is pressed.
*
*
* @param whichButton Which button to set the message for, can be one of
* {@link DialogInterface#BUTTON_POSITIVE},
* {@link DialogInterface#BUTTON_NEGATIVE}, or
@@ -244,10 +298,10 @@ public class AlertDialog extends Dialog implements DialogInterface {
public void setButton(int whichButton, CharSequence text, Message msg) {
mAlert.setButton(whichButton, text, null, msg);
}
/**
* Set a listener to be invoked when the positive button of the dialog is pressed.
*
*
* @param whichButton Which button to set the listener on, can be one of
* {@link DialogInterface#BUTTON_POSITIVE},
* {@link DialogInterface#BUTTON_NEGATIVE}, or
@@ -267,7 +321,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
public void setButton(CharSequence text, Message msg) {
setButton(BUTTON_POSITIVE, text, msg);
}
/**
* @deprecated Use {@link #setButton(int, CharSequence, Message)} with
* {@link DialogInterface#BUTTON_NEGATIVE}.
@@ -288,7 +342,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
/**
* Set a listener to be invoked when button 1 of the dialog is pressed.
*
*
* @param text The text to display in button 1.
* @param listener The {@link DialogInterface.OnClickListener} to use.
* @deprecated Use
@@ -334,7 +388,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
public void setIcon(@DrawableRes int resId) {
mAlert.setIcon(resId);
}
public void setIcon(Drawable icon) {
mAlert.setIcon(icon);
}
@@ -353,7 +407,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
public void setInverseBackgroundForced(boolean forceInverseBackground) {
mAlert.setInverseBackgroundForced(forceInverseBackground);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -371,35 +425,57 @@ public class AlertDialog extends Dialog implements DialogInterface {
if (mAlert.onKeyUp(keyCode, event)) return true;
return super.onKeyUp(keyCode, event);
}
public static class Builder {
private final AlertController.AlertParams P;
private int mTheme;
private int mThemeResId;
/**
* Constructor using a context for this builder and the {@link AlertDialog} it creates.
* Creates a builder for an alert dialog that uses the default alert
* dialog theme.
* <p>
* The default alert dialog theme is defined by
* {@link android.R.attr#alertDialogTheme} within the parent
* {@code context}'s theme.
*
* @param context the parent context
*/
public Builder(Context context) {
this(context, resolveDialogTheme(context, 0));
}
/**
* Constructor using a context and theme for this builder and
* the {@link AlertDialog} it creates. The actual theme
* that an AlertDialog uses is a private implementation, however you can
* here supply either the name of an attribute in the theme from which
* to get the dialog's style (such as {@link android.R.attr#alertDialogTheme}
* or one of the constants
* {@link AlertDialog#THEME_TRADITIONAL AlertDialog.THEME_TRADITIONAL},
* {@link AlertDialog#THEME_HOLO_DARK AlertDialog.THEME_HOLO_DARK}, or
* {@link AlertDialog#THEME_HOLO_LIGHT AlertDialog.THEME_HOLO_LIGHT}.
* Creates a builder for an alert dialog that uses an explicit theme
* resource.
* <p>
* The specified theme resource ({@code themeResId}) is applied on top
* of the parent {@code context}'s theme. It may be specified as a
* style resource containing a fully-populated theme, such as
* {@link android.R.style#Theme_Material_Dialog}, to replace all
* attributes in the parent {@code context}'s theme including primary
* and accent colors.
* <p>
* To preserve attributes such as primary and accent colors, the
* {@code themeResId} may instead be specified as an overlay theme such
* as {@link android.R.style#ThemeOverlay_Material_Dialog}. This will
* override only the window attributes necessary to style the alert
* window as a dialog.
* <p>
* Alternatively, the {@code themeResId} may be specified as {@code 0}
* to use the parent {@code context}'s resolved value for
* {@link android.R.attr#alertDialogTheme}.
*
* @param context the parent context
* @param themeResId the resource ID of the theme against which to inflate
* this dialog, or {@code 0} to use the parent
* {@code context}'s default alert dialog theme
*/
public Builder(Context context, int theme) {
public Builder(Context context, int themeResId) {
P = new AlertController.AlertParams(new ContextThemeWrapper(
context, resolveDialogTheme(context, theme)));
mTheme = theme;
context, resolveDialogTheme(context, themeResId)));
mThemeResId = themeResId;
}
/**
* Returns a {@link Context} with the appropriate theme for dialogs created by this Builder.
* Applications should use this Context for obtaining LayoutInflaters for inflating views
@@ -421,7 +497,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mTitle = P.mContext.getText(titleId);
return this;
}
/**
* Set the title displayed in the {@link Dialog}.
*
@@ -431,23 +507,28 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mTitle = title;
return this;
}
/**
* Set the title using the custom view {@code customTitleView}. The
* methods {@link #setTitle(int)} and {@link #setIcon(int)} should be
* sufficient for most titles, but this is provided if the title needs
* more customization. Using this will replace the title and icon set
* via the other methods.
*
* @param customTitleView The custom view to use as the title.
* Set the title using the custom view {@code customTitleView}.
* <p>
* The methods {@link #setTitle(int)} and {@link #setIcon(int)} should
* be sufficient for most titles, but this is provided if the title
* needs more customization. Using this will replace the title and icon
* set via the other methods.
* <p>
* <strong>Note:</strong> To ensure consistent styling, the custom view
* should be inflated or constructed using the alert dialog's themed
* context obtained via {@link #getContext()}.
*
* @return This Builder object to allow for chaining of calls to set methods
* @param customTitleView the custom view to use as the title
* @return this Builder object to allow for chaining of calls to set
* methods
*/
public Builder setCustomTitle(View customTitleView) {
P.mCustomTitleView = customTitleView;
return this;
}
/**
* Set the message to display using the given resource id.
*
@@ -457,7 +538,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mMessage = P.mContext.getText(messageId);
return this;
}
/**
* Set the message to display.
*
@@ -467,7 +548,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mMessage = message;
return this;
}
/**
* Set the resource id of the {@link Drawable} to be used in the title.
* <p>
@@ -479,11 +560,16 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mIconId = iconId;
return this;
}
/**
* Set the {@link Drawable} to be used in the title.
*
* @return This Builder object to allow for chaining of calls to set methods
* <p>
* <strong>Note:</strong> To ensure consistent styling, the drawable
* should be inflated or constructed using the alert dialog's themed
* context obtained via {@link #getContext()}.
*
* @return this Builder object to allow for chaining of calls to set
* methods
*/
public Builder setIcon(Drawable icon) {
P.mIcon = icon;
@@ -518,7 +604,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mPositiveButtonListener = listener;
return this;
}
/**
* Set a listener to be invoked when the positive button of the dialog is pressed.
* @param text The text to display in the positive button
@@ -531,7 +617,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mPositiveButtonListener = listener;
return this;
}
/**
* Set a listener to be invoked when the negative button of the dialog is pressed.
* @param textId The resource id of the text to display in the negative button
@@ -544,7 +630,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mNegativeButtonListener = listener;
return this;
}
/**
* Set a listener to be invoked when the negative button of the dialog is pressed.
* @param text The text to display in the negative button
@@ -557,7 +643,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mNegativeButtonListener = listener;
return this;
}
/**
* Set a listener to be invoked when the neutral button of the dialog is pressed.
* @param textId The resource id of the text to display in the neutral button
@@ -570,7 +656,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mNeutralButtonListener = listener;
return this;
}
/**
* Set a listener to be invoked when the neutral button of the dialog is pressed.
* @param text The text to display in the neutral button
@@ -583,7 +669,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mNeutralButtonListener = listener;
return this;
}
/**
* Sets whether the dialog is cancelable or not. Default is true.
*
@@ -593,7 +679,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mCancelable = cancelable;
return this;
}
/**
* Sets the callback that will be called if the dialog is canceled.
*
@@ -611,7 +697,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mOnCancelListener = onCancelListener;
return this;
}
/**
* Sets the callback that will be called when the dialog is dismissed for any reason.
*
@@ -631,7 +717,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mOnKeyListener = onKeyListener;
return this;
}
/**
* Set a list of items to be displayed in the dialog as the content, you will be notified of the
* selected item via the supplied listener. This should be an array type i.e. R.array.foo
@@ -643,7 +729,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mOnClickListener = listener;
return this;
}
/**
* Set a list of items to be displayed in the dialog as the content, you will be notified of the
* selected item via the supplied listener.
@@ -655,12 +741,12 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mOnClickListener = listener;
return this;
}
/**
* Set a list of items, which are supplied by the given {@link ListAdapter}, to be
* displayed in the dialog as the content, you will be notified of the
* selected item via the supplied listener.
*
*
* @param adapter The {@link ListAdapter} to supply the list of items
* @param listener The listener that will be called when an item is clicked.
*
@@ -671,12 +757,12 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mOnClickListener = listener;
return this;
}
/**
* Set a list of items, which are supplied by the given {@link Cursor}, to be
* displayed in the dialog as the content, you will be notified of the
* selected item via the supplied listener.
*
*
* @param cursor The {@link Cursor} to supply the list of items
* @param listener The listener that will be called when an item is clicked.
* @param labelColumn The column name on the cursor containing the string to display
@@ -691,7 +777,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mOnClickListener = listener;
return this;
}
/**
* Set a list of items to be displayed in the dialog as the content,
* you will be notified of the selected item via the supplied listener.
@@ -699,7 +785,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
* a check mark displayed to the right of the text for each checked
* item. Clicking on an item in the list will not dismiss the dialog.
* Clicking on a button will dismiss the dialog.
*
*
* @param itemsId the resource id of an array i.e. R.array.foo
* @param checkedItems specifies which items are checked. It should be null in which case no
* items are checked. If non null it must be exactly the same length as the array of
@@ -718,14 +804,14 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mIsMultiChoice = true;
return this;
}
/**
* Set a list of items to be displayed in the dialog as the content,
* you will be notified of the selected item via the supplied listener.
* The list will have a check mark displayed to the right of the text
* for each checked item. Clicking on an item in the list will not
* dismiss the dialog. Clicking on a button will dismiss the dialog.
*
*
* @param items the text of the items to be displayed in the list.
* @param checkedItems specifies which items are checked. It should be null in which case no
* items are checked. If non null it must be exactly the same length as the array of
@@ -736,7 +822,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
public Builder setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems,
public Builder setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems,
final OnMultiChoiceClickListener listener) {
P.mItems = items;
P.mOnCheckboxClickListener = listener;
@@ -744,14 +830,14 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mIsMultiChoice = true;
return this;
}
/**
* Set a list of items to be displayed in the dialog as the content,
* you will be notified of the selected item via the supplied listener.
* The list will have a check mark displayed to the right of the text
* for each checked item. Clicking on an item in the list will not
* dismiss the dialog. Clicking on a button will dismiss the dialog.
*
*
* @param cursor the cursor used to provide the items.
* @param isCheckedColumn specifies the column name on the cursor to use to determine
* whether a checkbox is checked or not. It must return an integer value where 1
@@ -764,7 +850,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
public Builder setMultiChoiceItems(Cursor cursor, String isCheckedColumn, String labelColumn,
public Builder setMultiChoiceItems(Cursor cursor, String isCheckedColumn, String labelColumn,
final OnMultiChoiceClickListener listener) {
P.mCursor = cursor;
P.mOnCheckboxClickListener = listener;
@@ -773,14 +859,14 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mIsMultiChoice = true;
return this;
}
/**
* Set a list of items to be displayed in the dialog as the content, you will be notified of
* the selected item via the supplied listener. This should be an array type i.e.
* R.array.foo The list will have a check mark displayed to the right of the text for the
* checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a
* button will dismiss the dialog.
*
*
* @param itemsId the resource id of an array i.e. R.array.foo
* @param checkedItem specifies which item is checked. If -1 no items are checked.
* @param listener notified when an item on the list is clicked. The dialog will not be
@@ -797,13 +883,13 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mIsSingleChoice = true;
return this;
}
/**
* Set a list of items to be displayed in the dialog as the content, you will be notified of
* the selected item via the supplied listener. The list will have a check mark displayed to
* the right of the text for the checked item. Clicking on an item in the list will not
* dismiss the dialog. Clicking on a button will dismiss the dialog.
*
*
* @param cursor the cursor to retrieve the items from.
* @param checkedItem specifies which item is checked. If -1 no items are checked.
* @param labelColumn The column name on the cursor containing the string to display in the
@@ -814,7 +900,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
public Builder setSingleChoiceItems(Cursor cursor, int checkedItem, String labelColumn,
public Builder setSingleChoiceItems(Cursor cursor, int checkedItem, String labelColumn,
final OnClickListener listener) {
P.mCursor = cursor;
P.mOnClickListener = listener;
@@ -823,13 +909,13 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mIsSingleChoice = true;
return this;
}
/**
* Set a list of items to be displayed in the dialog as the content, you will be notified of
* the selected item via the supplied listener. The list will have a check mark displayed to
* the right of the text for the checked item. Clicking on an item in the list will not
* dismiss the dialog. Clicking on a button will dismiss the dialog.
*
*
* @param items the items to be displayed.
* @param checkedItem specifies which item is checked. If -1 no items are checked.
* @param listener notified when an item on the list is clicked. The dialog will not be
@@ -844,14 +930,14 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mCheckedItem = checkedItem;
P.mIsSingleChoice = true;
return this;
}
}
/**
* Set a list of items to be displayed in the dialog as the content, you will be notified of
* the selected item via the supplied listener. The list will have a check mark displayed to
* the right of the text for the checked item. Clicking on an item in the list will not
* dismiss the dialog. Clicking on a button will dismiss the dialog.
*
*
* @param adapter The {@link ListAdapter} to supply the list of items
* @param checkedItem specifies which item is checked. If -1 no items are checked.
* @param listener notified when an item on the list is clicked. The dialog will not be
@@ -867,26 +953,25 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mIsSingleChoice = true;
return this;
}
/**
* Sets a listener to be invoked when an item in the list is selected.
*
* @param listener The listener to be invoked.
* @see AdapterView#setOnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener)
*
* @return This Builder object to allow for chaining of calls to set methods
* @param listener the listener to be invoked
* @return this Builder object to allow for chaining of calls to set methods
* @see AdapterView#setOnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener)
*/
public Builder setOnItemSelectedListener(final AdapterView.OnItemSelectedListener listener) {
P.mOnItemSelectedListener = listener;
return this;
}
/**
* Set a custom view resource to be the contents of the Dialog. The
* resource will be inflated, adding all top-level views to the screen.
*
* @param layoutResId Resource ID to be inflated.
* @return This Builder object to allow for chaining of calls to set
* @return this Builder object to allow for chaining of calls to set
* methods
*/
public Builder setView(int layoutResId) {
@@ -897,12 +982,18 @@ public class AlertDialog extends Dialog implements DialogInterface {
}
/**
* Set a custom view to be the contents of the Dialog. If the supplied view is an instance
* of a {@link ListView} the light background will be used.
* Sets a custom view to be the contents of the alert dialog.
* <p>
* When using a pre-Holo theme, if the supplied view is an instance of
* a {@link ListView} then the light background will be used.
* <p>
* <strong>Note:</strong> To ensure consistent styling, the custom view
* should be inflated or constructed using the alert dialog's themed
* context obtained via {@link #getContext()}.
*
* @param view The view to use as the contents of the Dialog.
*
* @return This Builder object to allow for chaining of calls to set methods
* @param view the view to use as the contents of the alert dialog
* @return this Builder object to allow for chaining of calls to set
* methods
*/
public Builder setView(View view) {
P.mView = view;
@@ -910,29 +1001,34 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mViewSpacingSpecified = false;
return this;
}
/**
* Set a custom view to be the contents of the Dialog, specifying the
* spacing to appear around that view. If the supplied view is an
* instance of a {@link ListView} the light background will be used.
*
* @param view The view to use as the contents of the Dialog.
* @param viewSpacingLeft Spacing between the left edge of the view and
* the dialog frame
* @param viewSpacingTop Spacing between the top edge of the view and
* the dialog frame
* @param viewSpacingRight Spacing between the right edge of the view
* and the dialog frame
* @param viewSpacingBottom Spacing between the bottom edge of the view
* and the dialog frame
* @return This Builder object to allow for chaining of calls to set
* Sets a custom view to be the contents of the alert dialog and
* specifies additional padding around that view.
* <p>
* When using a pre-Holo theme, if the supplied view is an instance of
* a {@link ListView} then the light background will be used.
* <p>
* <strong>Note:</strong> To ensure consistent styling, the custom view
* should be inflated or constructed using the alert dialog's themed
* context obtained via {@link #getContext()}.
*
* @param view the view to use as the contents of the alert dialog
* @param viewSpacingLeft spacing between the left edge of the view and
* the dialog frame
* @param viewSpacingTop spacing between the top edge of the view and
* the dialog frame
* @param viewSpacingRight spacing between the right edge of the view
* and the dialog frame
* @param viewSpacingBottom spacing between the bottom edge of the view
* and the dialog frame
* @return this Builder object to allow for chaining of calls to set
* methods
*
*
* This is currently hidden because it seems like people should just
* be able to put padding around the view.
* @hide
*
* @hide Remove once the framework usages have been replaced.
* @deprecated Set the padding on the view itself.
*/
@Deprecated
public Builder setView(View view, int viewSpacingLeft, int viewSpacingTop,
int viewSpacingRight, int viewSpacingBottom) {
P.mView = view;
@@ -944,15 +1040,18 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mViewSpacingBottom = viewSpacingBottom;
return this;
}
/**
* Sets the Dialog to use the inverse background, regardless of what the
* contents is.
*
* @param useInverseBackground Whether to use the inverse background
*
* @return This Builder object to allow for chaining of calls to set methods
* Sets the alert dialog to use the inverse background, regardless of
* what the contents is.
*
* @param useInverseBackground whether to use the inverse background
* @return this Builder object to allow for chaining of calls to set methods
* @deprecated This flag is only used for pre-Material themes. Instead,
* specify the window background using on the alert dialog
* theme.
*/
@Deprecated
public Builder setInverseBackgroundForced(boolean useInverseBackground) {
P.mForceInverseBackground = useInverseBackground;
return this;
@@ -968,13 +1067,15 @@ public class AlertDialog extends Dialog implements DialogInterface {
/**
* Creates a {@link AlertDialog} with the arguments supplied to this builder. It does not
* {@link Dialog#show()} the dialog. This allows the user to do any extra processing
* before displaying the dialog. Use {@link #show()} if you don't have any other processing
* to do and want this to be created and displayed.
* Creates an {@link AlertDialog} with the arguments supplied to this
* builder.
* <p>
* Calling this method does not display the dialog. If no additional
* processing is needed, {@link #show()} may be called instead to both
* create and display the dialog.
*/
public AlertDialog create() {
final AlertDialog dialog = new AlertDialog(P.mContext, mTheme, false);
final AlertDialog dialog = new AlertDialog(P.mContext, mThemeResId);
P.apply(dialog.mAlert);
dialog.setCancelable(P.mCancelable);
if (P.mCancelable) {
@@ -989,14 +1090,20 @@ public class AlertDialog extends Dialog implements DialogInterface {
}
/**
* Creates a {@link AlertDialog} with the arguments supplied to this builder and
* {@link Dialog#show()}'s the dialog.
* Creates an {@link AlertDialog} with the arguments supplied to this
* builder and immediately displays the dialog.
* <p>
* Calling this method is functionally identical to:
* <pre>
* AlertDialog dialog = builder.create();
* dialog.show();
* </pre>
*/
public AlertDialog show() {
AlertDialog dialog = create();
final AlertDialog dialog = create();
dialog.show();
return dialog;
}
}
}

View File

@@ -34,10 +34,13 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
/**
* An extension to TextView that supports the {@link android.widget.Checkable} interface.
* This is useful when used in a {@link android.widget.ListView ListView} where the it's
* {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has been set to
* something other than {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}.
* An extension to {@link TextView} that supports the {@link Checkable}
* interface and displays.
* <p>
* This is useful when used in a {@link android.widget.ListView ListView} where
* the {@link android.widget.ListView#setChoiceMode(int) setChoiceMode} has
* been set to something other than
* {@link android.widget.ListView#CHOICE_MODE_NONE CHOICE_MODE_NONE}.
*
* @attr ref android.R.styleable#CheckedTextView_checked
* @attr ref android.R.styleable#CheckedTextView_checkMark
@@ -116,9 +119,10 @@ public class CheckedTextView extends TextView implements Checkable {
}
/**
* <p>Changes the checked state of this text view.</p>
* Sets the checked state of this view.
*
* @param checked true to check the text, false to uncheck it
* @param checked {@code true} set the state to checked, {@code false} to
* uncheck
*/
public void setChecked(boolean checked) {
if (mChecked != checked) {
@@ -129,24 +133,24 @@ public class CheckedTextView extends TextView implements Checkable {
}
}
/**
* Set the checkmark to a given Drawable, identified by its resourece id. This will be drawn
* when {@link #isChecked()} is true.
*
* @param resid The Drawable to use for the checkmark.
* Sets the check mark to the drawable with the specified resource ID.
* <p>
* When this view is checked, the drawable's state set will include
* {@link android.R.attr#state_checked}.
*
* @param resId the resource identifier of drawable to use as the check
* mark
* @attr ref android.R.styleable#CheckedTextView_checkMark
* @see #setCheckMarkDrawable(Drawable)
* @see #getCheckMarkDrawable()
*
* @attr ref android.R.styleable#CheckedTextView_checkMark
*/
public void setCheckMarkDrawable(@DrawableRes int resid) {
if (resid != 0 && resid == mCheckMarkResource) {
public void setCheckMarkDrawable(@DrawableRes int resId) {
if (resId != 0 && resId == mCheckMarkResource) {
return;
}
mCheckMarkResource = resid;
mCheckMarkResource = resId;
Drawable d = null;
if (mCheckMarkResource != 0) {
@@ -156,14 +160,15 @@ public class CheckedTextView extends TextView implements Checkable {
}
/**
* Set the checkmark to a given Drawable. This will be drawn when {@link #isChecked()} is true.
*
* @param d The Drawable to use for the checkmark.
* Set the check mark to the specified drawable.
* <p>
* When this view is checked, the drawable's state set will include
* {@link android.R.attr#state_checked}.
*
* @param d the drawable to use for the check mark
* @attr ref android.R.styleable#CheckedTextView_checkMark
* @see #setCheckMarkDrawable(int)
* @see #getCheckMarkDrawable()
*
* @attr ref android.R.styleable#CheckedTextView_checkMark
*/
public void setCheckMarkDrawable(Drawable d) {
if (mCheckMarkDrawable != null) {

View File

@@ -2634,6 +2634,7 @@
<public type="style" name="Theme.Material.DayNight.NoActionBar.TranslucentDecor" />
<public type="style" name="Theme.Material.DayNight.Panel" />
<public type="style" name="Theme.Material.Light.LightStatusBar" />
<public type="style" name="ThemeOverlay.Material.Dialog" />
<!-- Context menu ID for the "Undo" menu item to undo the last text edit operation. -->
<public type="id" name="undo" />

View File

@@ -513,9 +513,7 @@ please see styles_device_defaults.xml.
<item name="background">@null</item>
</style>
<style name="Widget.Material.ButtonBar.AlertDialog">
<item name="background">@null</item>
</style>
<style name="Widget.Material.ButtonBar.AlertDialog" />
<style name="Widget.Material.SearchView">
<item name="layout">@layout/search_view</item>

View File

@@ -174,14 +174,14 @@ please see themes_device_defaults.xml.
<item name="windowSharedElementExitTransition">@transition/move</item>
<!-- Dialog attributes -->
<item name="dialogTheme">@style/Theme.Material.Dialog</item>
<item name="dialogTheme">@style/ThemeOverlay.Material.Dialog</item>
<item name="dialogTitleIconsDecorLayout">@layout/dialog_title_icons_material</item>
<item name="dialogCustomTitleDecorLayout">@layout/dialog_custom_title_material</item>
<item name="dialogTitleDecorLayout">@layout/dialog_title_material</item>
<item name="dialogPreferredPadding">@dimen/dialog_padding_material</item>
<!-- AlertDialog attributes -->
<item name="alertDialogTheme">@style/Theme.Material.Dialog.Alert</item>
<item name="alertDialogTheme">@style/ThemeOverlay.Material.Dialog</item>
<item name="alertDialogStyle">@style/AlertDialog.Material</item>
<item name="alertDialogCenterButtons">false</item>
<item name="alertDialogIcon">@drawable/ic_dialog_alert_material</item>
@@ -529,14 +529,14 @@ please see themes_device_defaults.xml.
<item name="windowActivityTransitions">true</item>
<!-- Dialog attributes -->
<item name="dialogTheme">@style/Theme.Material.Light.Dialog</item>
<item name="dialogTheme">@style/ThemeOverlay.Material.Dialog</item>
<item name="dialogTitleIconsDecorLayout">@layout/dialog_title_icons_material</item>
<item name="dialogCustomTitleDecorLayout">@layout/dialog_custom_title_material</item>
<item name="dialogTitleDecorLayout">@layout/dialog_title_material</item>
<item name="dialogPreferredPadding">@dimen/dialog_padding_material</item>
<!-- AlertDialog attributes -->
<item name="alertDialogTheme">@style/Theme.Material.Light.Dialog.Alert</item>
<item name="alertDialogTheme">@style/ThemeOverlay.Material.Dialog</item>
<item name="alertDialogStyle">@style/AlertDialog.Material.Light</item>
<item name="alertDialogCenterButtons">false</item>
<item name="alertDialogIcon">@drawable/ic_dialog_alert_material</item>
@@ -695,7 +695,7 @@ please see themes_device_defaults.xml.
<item name="dividerVertical">?attr/listDivider</item>
<item name="dividerHorizontal">?attr/listDivider</item>
<item name="buttonBarStyle">@style/Widget.Material.Light.ButtonBar</item>
<item name="buttonBarStyle">@style/Widget.Material.Light.ButtonBar.AlertDialog</item>
<item name="buttonBarButtonStyle">@style/Widget.Material.Light.Button.ButtonBar.AlertDialog</item>
<item name="segmentedButtonStyle">@style/Widget.Material.Light.SegmentedButton</item>
@@ -839,7 +839,7 @@ please see themes_device_defaults.xml.
secondary text color, with the primary text color. -->
<style name="ThemeOverlay.Material.ActionBar">
<item name="colorControlNormal">?attr/textColorPrimary</item>
<item name="searchViewStyle">@style/Widget.Material.Light.SearchView.ActionBar</item>
<item name="searchViewStyle">@style/Widget.Material.SearchView.ActionBar</item>
</style>
<!-- Theme overlay that replaces colors with their dark versions and replaces the normal
@@ -850,6 +850,34 @@ please see themes_device_defaults.xml.
<item name="searchViewStyle">@style/Widget.Material.SearchView.ActionBar</item>
</style>
<!-- Theme overlay that overrides window properties to display as a dialog. -->
<style name="ThemeOverlay.Material.Dialog">
<item name="colorBackground">@color/background_floating_material_light</item>
<item name="colorBackgroundCacheHint">@null</item>
<item name="windowFrame">@null</item>
<item name="windowTitleStyle">@style/DialogWindowTitle.Material</item>
<item name="windowTitleBackgroundStyle">@style/DialogWindowTitleBackground.Material</item>
<item name="windowBackground">@drawable/dialog_background_material</item>
<item name="windowElevation">@dimen/floating_window_z</item>
<item name="windowIsFloating">true</item>
<item name="windowContentOverlay">@null</item>
<item name="windowAnimationStyle">@style/Animation.Material.Dialog</item>
<item name="windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowCloseOnTouchOutside">@bool/config_closeDialogWhenTouchOutside</item>
<item name="listPreferredItemPaddingLeft">?attr/dialogPreferredPadding</item>
<item name="listPreferredItemPaddingRight">?attr/dialogPreferredPadding</item>
<item name="listPreferredItemPaddingStart">?attr/dialogPreferredPadding</item>
<item name="listPreferredItemPaddingEnd">?attr/dialogPreferredPadding</item>
<item name="listDivider">@null</item>
<item name="preferencePanelStyle">@style/PreferencePanel.Dialog</item>
</style>
<!-- Variant of the material (dark) theme with no action bar. -->
<style name="Theme.Material.NoActionBar">
<item name="windowActionBar">false</item>
@@ -1033,12 +1061,6 @@ please see themes_device_defaults.xml.
<item name="colorBackgroundCacheHint">@null</item>
<item name="buttonBarStyle">@style/Widget.Material.ButtonBar.AlertDialog</item>
<item name="borderlessButtonStyle">@style/Widget.Material.Button.Borderless</item>
<item name="textAppearance">@style/TextAppearance.Material</item>
<item name="textAppearanceInverse">@style/TextAppearance.Material.Inverse</item>
<item name="listPreferredItemPaddingLeft">24dip</item>
<item name="listPreferredItemPaddingRight">24dip</item>
<item name="listPreferredItemPaddingStart">24dip</item>
@@ -1150,12 +1172,6 @@ please see themes_device_defaults.xml.
<item name="colorBackgroundCacheHint">@null</item>
<item name="buttonBarStyle">@style/Widget.Material.Light.ButtonBar.AlertDialog</item>
<item name="borderlessButtonStyle">@style/Widget.Material.Light.Button.Borderless</item>
<item name="textAppearance">@style/TextAppearance.Material</item>
<item name="textAppearanceInverse">@style/TextAppearance.Material.Inverse</item>
<item name="listPreferredItemPaddingLeft">24dip</item>
<item name="listPreferredItemPaddingRight">24dip</item>
<item name="listPreferredItemPaddingStart">24dip</item>
@@ -1254,8 +1270,6 @@ please see themes_device_defaults.xml.
<item name="colorPrimaryDark">@color/material_blue_grey_950</item>
<item name="colorAccent">@color/material_deep_teal_500</item>
<item name="dialogTheme">@style/Theme.Material.Settings.Dialog</item>
<item name="alertDialogTheme">@style/Theme.Material.Settings.Dialog.Alert</item>
<item name="presentationTheme">@style/Theme.Material.Settings.Dialog.Presentation</item>
<item name="searchDialogTheme">@style/Theme.Material.Settings.SearchBar</item>
<item name="panelMenuListTheme">@style/Theme.Material.Settings.CompactMenu</item>