Update alert dialogs in ApiDemos for Material theme
BUG: 17415772
Change-Id: Ifc1de793458f678a3c40b734d5ab08b2eb382f7a
diff --git a/samples/ApiDemos/res/layout/alert_dialog.xml b/samples/ApiDemos/res/layout/alert_dialog.xml
index f8261f8..deb712a 100644
--- a/samples/ApiDemos/res/layout/alert_dialog.xml
+++ b/samples/ApiDemos/res/layout/alert_dialog.xml
@@ -38,6 +38,9 @@
<Button android:id="@+id/progress_button"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="@string/alert_dialog_progress_button"/>
+ <Button android:id="@+id/progress_spinner_button"
+ android:layout_width="match_parent" android:layout_height="wrap_content"
+ android:text="@string/alert_dialog_progress_spinner_button"/>
<Button android:id="@+id/radio_button"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="@string/alert_dialog_single_choice"/>
diff --git a/samples/ApiDemos/res/layout/alert_dialog_text_entry.xml b/samples/ApiDemos/res/layout/alert_dialog_text_entry.xml
index 1f4d093..61bd3f5 100644
--- a/samples/ApiDemos/res/layout/alert_dialog_text_entry.xml
+++ b/samples/ApiDemos/res/layout/alert_dialog_text_entry.xml
@@ -17,14 +17,14 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:paddingStart="24dp"
+ android:paddingEnd="24dp"
android:orientation="vertical">
<TextView
android:id="@+id/username_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
android:text="@string/alert_dialog_username"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
@@ -33,8 +33,6 @@
android:id="@+id/username_edit"
android:layout_height="wrap_content"
android:layout_width="match_parent"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
@@ -45,8 +43,6 @@
android:id="@+id/password_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
android:text="@string/alert_dialog_password"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium" />
@@ -55,8 +51,6 @@
android:id="@+id/password_edit"
android:layout_height="wrap_content"
android:layout_width="match_parent"
- android:layout_marginLeft="20dip"
- android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:autoText="false"
android:capitalize="none"
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 7835bd9..58daf39 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -530,7 +530,8 @@
<string name="alert_dialog_single_choice">Single choice list</string>
<string name="alert_dialog_multi_choice">Repeat alarm</string>
<string name="alert_dialog_multi_choice_cursor">Send Call to VoiceMail</string>
- <string name="alert_dialog_progress_button">Progress dialog</string>
+ <string name="alert_dialog_progress_button">Progress bar dialog</string>
+ <string name="alert_dialog_progress_spinner_button">Progress spinner dialog</string>
<string name="alert_dialog_text_entry">Text Entry dialog</string>
<string name="alert_dialog_username">Name:</string>
<string name="alert_dialog_password">Password:</string>
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.java b/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.java
index da0a0a0..7a6f384 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/AlertDialogSamples.java
@@ -69,9 +69,11 @@
private static final int DIALOG_YES_NO_HOLO_LIGHT_MESSAGE = 11;
private static final int DIALOG_YES_NO_DEFAULT_LIGHT_MESSAGE = 12;
private static final int DIALOG_YES_NO_DEFAULT_DARK_MESSAGE = 13;
+ private static final int DIALOG_PROGRESS_SPINNER = 14;
private static final int MAX_PROGRESS = 100;
-
+
+ private ProgressDialog mProgressSpinnerDialog;
private ProgressDialog mProgressDialog;
private int mProgress;
private Handler mProgressHandler;
@@ -81,7 +83,6 @@
switch (id) {
case DIALOG_YES_NO_MESSAGE:
return new AlertDialog.Builder(AlertDialogSamples.this)
- .setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.alert_dialog_two_buttons_title)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
@@ -124,7 +125,6 @@
.create();
case DIALOG_YES_NO_DEFAULT_LIGHT_MESSAGE:
return new AlertDialog.Builder(AlertDialogSamples.this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
- .setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.alert_dialog_two_buttons_title)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
@@ -137,7 +137,6 @@
.create();
case DIALOG_YES_NO_DEFAULT_DARK_MESSAGE:
return new AlertDialog.Builder(AlertDialogSamples.this, AlertDialog.THEME_DEVICE_DEFAULT_DARK)
- .setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.alert_dialog_two_buttons_title)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
@@ -150,7 +149,6 @@
.create();
case DIALOG_YES_NO_LONG_MESSAGE:
return new AlertDialog.Builder(AlertDialogSamples.this)
- .setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.alert_dialog_two_buttons_msg)
.setMessage(R.string.alert_dialog_two_buttons2_msg)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
@@ -174,7 +172,6 @@
.create();
case DIALOG_YES_NO_ULTRA_LONG_MESSAGE:
return new AlertDialog.Builder(AlertDialogSamples.this)
- .setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.alert_dialog_two_buttons_msg)
.setMessage(R.string.alert_dialog_two_buttons2ultra_msg)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
@@ -212,7 +209,6 @@
.create();
case DIALOG_PROGRESS:
mProgressDialog = new ProgressDialog(AlertDialogSamples.this);
- mProgressDialog.setIconAttribute(android.R.attr.alertDialogIcon);
mProgressDialog.setTitle(R.string.select_dialog);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setMax(MAX_PROGRESS);
@@ -231,9 +227,27 @@
}
});
return mProgressDialog;
+ case DIALOG_PROGRESS_SPINNER:
+ mProgressSpinnerDialog = new ProgressDialog(AlertDialogSamples.this);
+ mProgressSpinnerDialog.setTitle(R.string.select_dialog);
+ mProgressSpinnerDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ mProgressSpinnerDialog.setButton(DialogInterface.BUTTON_POSITIVE,
+ getText(R.string.alert_dialog_hide), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+
+ /* User clicked Yes so do some stuff */
+ }
+ });
+ mProgressSpinnerDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
+ getText(R.string.alert_dialog_cancel), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+
+ /* User clicked No so do some stuff */
+ }
+ });
+ return mProgressSpinnerDialog;
case DIALOG_SINGLE_CHOICE:
return new AlertDialog.Builder(AlertDialogSamples.this)
- .setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.alert_dialog_single_choice)
.setSingleChoiceItems(R.array.select_dialog_items2, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
@@ -256,7 +270,6 @@
.create();
case DIALOG_MULTIPLE_CHOICE:
return new AlertDialog.Builder(AlertDialogSamples.this)
- .setIcon(R.drawable.ic_popup_reminder)
.setTitle(R.string.alert_dialog_multi_choice)
.setMultiChoiceItems(R.array.select_dialog_items3,
new boolean[]{false, true, false, true, false, false, false},
@@ -282,35 +295,33 @@
}
})
.create();
- case DIALOG_MULTIPLE_CHOICE_CURSOR:
- String[] projection = new String[] {
- ContactsContract.Contacts._ID,
+ case DIALOG_MULTIPLE_CHOICE_CURSOR:
+ String[] projection = new String[] {
+ ContactsContract.Contacts._ID,
+ ContactsContract.Contacts.DISPLAY_NAME,
+ ContactsContract.Contacts.SEND_TO_VOICEMAIL
+ };
+ Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI,
+ projection, null, null, null);
+ return new AlertDialog.Builder(AlertDialogSamples.this)
+ .setTitle(R.string.alert_dialog_multi_choice_cursor)
+ .setMultiChoiceItems(cursor,
+ ContactsContract.Contacts.SEND_TO_VOICEMAIL,
ContactsContract.Contacts.DISPLAY_NAME,
- ContactsContract.Contacts.SEND_TO_VOICEMAIL
- };
- Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI,
- projection, null, null, null);
- return new AlertDialog.Builder(AlertDialogSamples.this)
- .setIcon(R.drawable.ic_popup_reminder)
- .setTitle(R.string.alert_dialog_multi_choice_cursor)
- .setMultiChoiceItems(cursor,
- ContactsContract.Contacts.SEND_TO_VOICEMAIL,
- ContactsContract.Contacts.DISPLAY_NAME,
- new DialogInterface.OnMultiChoiceClickListener() {
- public void onClick(DialogInterface dialog, int whichButton,
- boolean isChecked) {
- Toast.makeText(AlertDialogSamples.this,
- "Readonly Demo Only - Data will not be updated",
- Toast.LENGTH_SHORT).show();
- }
- })
- .create();
+ new DialogInterface.OnMultiChoiceClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton,
+ boolean isChecked) {
+ Toast.makeText(AlertDialogSamples.this,
+ "Readonly Demo Only - Data will not be updated",
+ Toast.LENGTH_SHORT).show();
+ }
+ })
+ .create();
case DIALOG_TEXT_ENTRY:
// This example shows how to add a custom layout to an AlertDialog
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
return new AlertDialog.Builder(AlertDialogSamples.this)
- .setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(R.string.alert_dialog_text_entry)
.setView(textEntryView)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
@@ -385,6 +396,14 @@
mProgressHandler.sendEmptyMessage(0);
}
});
+
+ /* Display a custom progress bar */
+ Button progressSpinnerButton = (Button) findViewById(R.id.progress_spinner_button);
+ progressButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ showDialog(DIALOG_PROGRESS_SPINNER);
+ }
+ });
/* Display a radio button group */
Button radioButton = (Button) findViewById(R.id.radio_button);