From 4c0cb8a526eec87fdba6dc371e21abfa4e993ea0 Mon Sep 17 00:00:00 2001 From: Craig Stout Date: Fri, 4 Apr 2014 13:03:10 -0700 Subject: [PATCH] AlertDialog and AppError themes for TV. Leanback themes override AlertDialog styles from other themes. Makes system alert dialogs, and alert dialogs from games running on ATV, have a style more appropriate to television. Final visuals pending. Side button layout fixes DatePickerDialog and TimePickerDialog with dpad navigation. TODO: consider using side button layout for other AlertDialog cases (long messages and lists). Change-Id: I74e4e04d16d6854377580be95a87684a0385b04b --- core/java/android/app/AlertDialog.java | 20 +++ core/java/android/app/DatePickerDialog.java | 1 + core/java/android/app/TimePickerDialog.java | 1 + .../android/internal/app/AlertController.java | 27 +++- core/res/res/layout/alert_dialog_leanback.xml | 131 ++++++++++++++++ ...ert_dialog_leanback_button_panel_right.xml | 142 ++++++++++++++++++ .../res/layout/progress_dialog_leanback.xml | 48 ++++++ core/res/res/values-television/themes.xml | 23 +++ .../themes_device_defaults.xml | 19 +++ core/res/res/values/attrs.xml | 1 + core/res/res/values/colors.xml | 3 + core/res/res/values/dimens.xml | 4 + core/res/res/values/styles_leanback.xml | 59 ++++++++ core/res/res/values/symbols.xml | 1 + core/res/res/values/themes.xml | 28 ++-- core/res/res/values/themes_leanback.xml | 47 ++++++ .../policy/impl/PhoneWindowManager.java | 13 +- 17 files changed, 552 insertions(+), 16 deletions(-) create mode 100644 core/res/res/layout/alert_dialog_leanback.xml create mode 100644 core/res/res/layout/alert_dialog_leanback_button_panel_right.xml create mode 100644 core/res/res/layout/progress_dialog_leanback.xml create mode 100644 core/res/res/values-television/themes.xml create mode 100644 core/res/res/values-television/themes_device_defaults.xml create mode 100644 core/res/res/values/styles_leanback.xml create mode 100644 core/res/res/values/themes_leanback.xml diff --git a/core/java/android/app/AlertDialog.java b/core/java/android/app/AlertDialog.java index ab148a9613086..4ce78357f352d 100644 --- a/core/java/android/app/AlertDialog.java +++ b/core/java/android/app/AlertDialog.java @@ -92,6 +92,18 @@ public class AlertDialog extends Dialog implements DialogInterface { * the device's default alert theme with a light background. */ public static final int THEME_DEVICE_DEFAULT_LIGHT = 5; + + /** + * No layout hint. + * @hide + */ + public static final int LAYOUT_HINT_NONE = 0; + + /** + * Hint layout to the side. + * @hide + */ + public static final int LAYOUT_HINT_SIDE = 1; protected AlertDialog(Context context) { this(context, resolveDialogTheme(context, 0), true); @@ -207,6 +219,14 @@ public class AlertDialog extends Dialog implements DialogInterface { mAlert.setView(view, viewSpacingLeft, viewSpacingTop, viewSpacingRight, viewSpacingBottom); } + /** + * Internal api to allow hinting for the best button panel layout. + * @hide + */ + void setButtonPanelLayoutHint(int layoutHint) { + mAlert.setButtonPanelLayoutHint(layoutHint); + } + /** * Set a message to be sent when a button is pressed. * diff --git a/core/java/android/app/DatePickerDialog.java b/core/java/android/app/DatePickerDialog.java index d1688004e52da..26c2c30c27996 100644 --- a/core/java/android/app/DatePickerDialog.java +++ b/core/java/android/app/DatePickerDialog.java @@ -107,6 +107,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.date_picker_dialog, null); setView(view); + setButtonPanelLayoutHint(LAYOUT_HINT_SIDE); mDatePicker = (DatePicker) view.findViewById(R.id.datePicker); mDatePicker.init(year, monthOfYear, dayOfMonth, this); updateTitle(year, monthOfYear, dayOfMonth); diff --git a/core/java/android/app/TimePickerDialog.java b/core/java/android/app/TimePickerDialog.java index a85c61f2321f8..8cf8c250ff10d 100644 --- a/core/java/android/app/TimePickerDialog.java +++ b/core/java/android/app/TimePickerDialog.java @@ -110,6 +110,7 @@ public class TimePickerDialog extends AlertDialog (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.time_picker_dialog, null); setView(view); + setButtonPanelLayoutHint(LAYOUT_HINT_SIDE); mTimePicker = (TimePicker) view.findViewById(R.id.timePicker); // Initialize state diff --git a/core/java/com/android/internal/app/AlertController.java b/core/java/com/android/internal/app/AlertController.java index b5681215142e6..664f9db8e64ee 100644 --- a/core/java/com/android/internal/app/AlertController.java +++ b/core/java/com/android/internal/app/AlertController.java @@ -123,11 +123,14 @@ public class AlertController { private int mCheckedItem = -1; private int mAlertDialogLayout; + private int mButtonPanelSideLayout; private int mListLayout; private int mMultiChoiceItemLayout; private int mSingleChoiceItemLayout; private int mListItemLayout; + private int mButtonPanelLayoutHint = AlertDialog.LAYOUT_HINT_NONE; + private Handler mHandler; private final View.OnClickListener mButtonHandler = new View.OnClickListener() { @@ -199,6 +202,9 @@ public class AlertController { mAlertDialogLayout = a.getResourceId(com.android.internal.R.styleable.AlertDialog_layout, com.android.internal.R.layout.alert_dialog); + mButtonPanelSideLayout = a.getResourceId( + com.android.internal.R.styleable.AlertDialog_buttonPanelSideLayout, 0); + mListLayout = a.getResourceId( com.android.internal.R.styleable.AlertDialog_listLayout, com.android.internal.R.layout.select_dialog); @@ -240,10 +246,22 @@ public class AlertController { public void installContent() { /* We use a custom title so never request a window title */ mWindow.requestFeature(Window.FEATURE_NO_TITLE); - mWindow.setContentView(mAlertDialogLayout); + int contentView = selectContentView(); + mWindow.setContentView(contentView); setupView(); setupDecor(); } + + private int selectContentView() { + if (mButtonPanelSideLayout == 0) { + return mAlertDialogLayout; + } + if (mButtonPanelLayoutHint == AlertDialog.LAYOUT_HINT_SIDE) { + return mButtonPanelSideLayout; + } + // TODO: use layout hint side for long messages/lists + return mAlertDialogLayout; + } public void setTitle(CharSequence title) { mTitle = title; @@ -298,6 +316,13 @@ public class AlertController { mViewSpacingBottom = viewSpacingBottom; } + /** + * Sets a hint for the best button panel layout. + */ + public void setButtonPanelLayoutHint(int layoutHint) { + mButtonPanelLayoutHint = layoutHint; + } + /** * Sets a click listener or a message to be sent when the button is clicked. * You only need to pass one of {@code listener} or {@code msg}. diff --git a/core/res/res/layout/alert_dialog_leanback.xml b/core/res/res/layout/alert_dialog_leanback.xml new file mode 100644 index 0000000000000..8655aea8f28d1 --- /dev/null +++ b/core/res/res/layout/alert_dialog_leanback.xml @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +