summaryrefslogtreecommitdiffstats
path: root/core/java/com
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2015-02-26 09:47:10 -0800
committerAlan Viverette <alanv@google.com>2015-02-26 09:47:10 -0800
commit62c79e9a64c3b2cafd5500ed3064977dff7b7da3 (patch)
tree46b781ce1875852dc20613954c314707260a6e7c /core/java/com
parent40d13f260c50ac5235f7405e1c3a83d6f46a8d62 (diff)
downloadframeworks_base-62c79e9a64c3b2cafd5500ed3064977dff7b7da3.zip
frameworks_base-62c79e9a64c3b2cafd5500ed3064977dff7b7da3.tar.gz
frameworks_base-62c79e9a64c3b2cafd5500ed3064977dff7b7da3.tar.bz2
Implement landscape layout for time picker dialog
Adds support overriding default alert dialog panel elements by including them in the dialog's custom content view, but no public API (yet!) since the panel IDs have never been public. Some minor cleanup and refactoring in TimePickerDialog. Removes Holo styles for "clock" and "calendar" style pickers since they are new in Material. If the new styles are used against Holo they will match Material but with Holo primary/accent colors. Also implements themed color state lists to resolve TODOs in both time and date pickers. Bug: 19431361 Change-Id: I095fd8d653e02d9e5d20d66611432a08a7a5685e
Diffstat (limited to 'core/java/com')
-rw-r--r--core/java/com/android/internal/app/AlertController.java157
1 files changed, 109 insertions, 48 deletions
diff --git a/core/java/com/android/internal/app/AlertController.java b/core/java/com/android/internal/app/AlertController.java
index 20d209f..9dabb4e 100644
--- a/core/java/com/android/internal/app/AlertController.java
+++ b/core/java/com/android/internal/app/AlertController.java
@@ -20,6 +20,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import com.android.internal.R;
+import android.annotation.Nullable;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -38,7 +39,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
-import android.view.ViewTreeObserver;
+import android.view.ViewStub;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
@@ -450,27 +451,107 @@ public class AlertController {
}
}
+ /**
+ * Resolves whether a custom or default panel should be used. Removes the
+ * default panel if a custom panel should be used. If the resolved panel is
+ * a view stub, inflates before returning.
+ *
+ * @param customPanel the custom panel
+ * @param defaultPanel the default panel
+ * @return the panel to use
+ */
+ @Nullable
+ private ViewGroup resolvePanel(@Nullable View customPanel, @Nullable View defaultPanel) {
+ if (customPanel == null) {
+ // Inflate the default panel, if needed.
+ if (defaultPanel instanceof ViewStub) {
+ defaultPanel = ((ViewStub) defaultPanel).inflate();
+ }
+
+ return (ViewGroup) defaultPanel;
+ }
+
+ // Remove the default panel entirely.
+ if (defaultPanel != null) {
+ final ViewParent parent = defaultPanel.getParent();
+ if (parent instanceof ViewGroup) {
+ ((ViewGroup) parent).removeView(defaultPanel);
+ }
+ }
+
+ // Inflate the custom panel, if needed.
+ if (customPanel instanceof ViewStub) {
+ customPanel = ((ViewStub) customPanel).inflate();
+ }
+
+ return (ViewGroup) customPanel;
+ }
+
private void setupView() {
- final ViewGroup contentPanel = (ViewGroup) mWindow.findViewById(R.id.contentPanel);
- setupContent(contentPanel);
- final boolean hasButtons = setupButtons();
+ final View parentPanel = mWindow.findViewById(R.id.parentPanel);
+ final View defaultTopPanel = parentPanel.findViewById(R.id.topPanel);
+ final View defaultContentPanel = parentPanel.findViewById(R.id.contentPanel);
+ final View defaultButtonPanel = parentPanel.findViewById(R.id.buttonPanel);
- final ViewGroup topPanel = (ViewGroup) mWindow.findViewById(R.id.topPanel);
- final TypedArray a = mContext.obtainStyledAttributes(
- null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0);
- final boolean hasTitle = setupTitle(topPanel);
+ // Install custom content before setting up the title or buttons so
+ // that we can handle panel overrides.
+ final ViewGroup customPanel = (ViewGroup) parentPanel.findViewById(R.id.customPanel);
+ setupCustomContent(customPanel);
- final View buttonPanel = mWindow.findViewById(R.id.buttonPanel);
- if (!hasButtons) {
- buttonPanel.setVisibility(View.GONE);
- final View spacer = mWindow.findViewById(R.id.textSpacerNoButtons);
- if (spacer != null) {
- spacer.setVisibility(View.VISIBLE);
+ final View customTopPanel = customPanel.findViewById(R.id.topPanel);
+ final View customContentPanel = customPanel.findViewById(R.id.contentPanel);
+ final View customButtonPanel = customPanel.findViewById(R.id.buttonPanel);
+
+ // Resolve the correct panels and remove the defaults, if needed.
+ final ViewGroup topPanel = resolvePanel(customTopPanel, defaultTopPanel);
+ final ViewGroup contentPanel = resolvePanel(customContentPanel, defaultContentPanel);
+ final ViewGroup buttonPanel = resolvePanel(customButtonPanel, defaultButtonPanel);
+
+ setupContent(contentPanel);
+ setupButtons(buttonPanel);
+ setupTitle(topPanel);
+
+ final boolean hasCustomPanel = customPanel != null
+ && customPanel.getVisibility() != View.GONE;
+ final boolean hasTopPanel = topPanel != null
+ && topPanel.getVisibility() != View.GONE;
+ final boolean hasButtonPanel = buttonPanel != null
+ && buttonPanel.getVisibility() != View.GONE;
+
+ // Only display the text spacer if we don't have buttons.
+ if (!hasButtonPanel) {
+ if (contentPanel != null) {
+ final View spacer = contentPanel.findViewById(R.id.textSpacerNoButtons);
+ if (spacer != null) {
+ spacer.setVisibility(View.VISIBLE);
+ }
}
mWindow.setCloseOnTouchOutsideIfNotSet(true);
}
- final FrameLayout customPanel = (FrameLayout) mWindow.findViewById(R.id.customPanel);
+ // Only display the divider if we have a title and a custom view or a
+ // message.
+ if (hasTopPanel) {
+ final View divider;
+ if (mMessage != null || hasCustomPanel || mListView != null) {
+ divider = topPanel.findViewById(R.id.titleDivider);
+ } else {
+ divider = topPanel.findViewById(R.id.titleDividerTop);
+ }
+
+ if (divider != null) {
+ divider.setVisibility(View.VISIBLE);
+ }
+ }
+
+ final TypedArray a = mContext.obtainStyledAttributes(
+ null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0);
+ setBackground(a, topPanel, contentPanel, customPanel, buttonPanel,
+ hasTopPanel, hasCustomPanel, hasButtonPanel);
+ a.recycle();
+ }
+
+ private void setupCustomContent(ViewGroup customPanel) {
final View customView;
if (mView != null) {
customView = mView;
@@ -502,30 +583,9 @@ public class AlertController {
} else {
customPanel.setVisibility(View.GONE);
}
-
- // Only display the divider if we have a title and a custom view or a
- // message.
- if (hasTitle) {
- final View divider;
- if (mMessage != null || customView != null || mListView != null) {
- divider = mWindow.findViewById(R.id.titleDivider);
- } else {
- divider = mWindow.findViewById(R.id.titleDividerTop);
- }
-
- if (divider != null) {
- divider.setVisibility(View.VISIBLE);
- }
- }
-
- setBackground(a, topPanel, contentPanel, customPanel, buttonPanel, hasTitle, hasCustomView,
- hasButtons);
- a.recycle();
}
- private boolean setupTitle(ViewGroup topPanel) {
- boolean hasTitle = true;
-
+ private void setupTitle(ViewGroup topPanel) {
if (mCustomTitleView != null) {
// Add the custom title view directly to the topPanel layout
LayoutParams lp = new LayoutParams(
@@ -567,18 +627,16 @@ public class AlertController {
titleTemplate.setVisibility(View.GONE);
mIconView.setVisibility(View.GONE);
topPanel.setVisibility(View.GONE);
- hasTitle = false;
}
}
- return hasTitle;
}
private void setupContent(ViewGroup contentPanel) {
- mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView);
+ mScrollView = (ScrollView) contentPanel.findViewById(R.id.scrollView);
mScrollView.setFocusable(false);
// Special case for users that only want to display a String
- mMessageView = (TextView) mWindow.findViewById(R.id.message);
+ mMessageView = (TextView) contentPanel.findViewById(R.id.message);
if (mMessageView == null) {
return;
}
@@ -601,8 +659,8 @@ public class AlertController {
}
// Set up scroll indicators (if present).
- final View indicatorUp = mWindow.findViewById(R.id.scrollIndicatorUp);
- final View indicatorDown = mWindow.findViewById(R.id.scrollIndicatorDown);
+ final View indicatorUp = contentPanel.findViewById(R.id.scrollIndicatorUp);
+ final View indicatorDown = contentPanel.findViewById(R.id.scrollIndicatorDown);
if (indicatorUp != null || indicatorDown != null) {
if (mMessage != null) {
// We're just showing the ScrollView, set up listener.
@@ -663,12 +721,12 @@ public class AlertController {
}
}
- private boolean setupButtons() {
+ private void setupButtons(ViewGroup buttonPanel) {
int BIT_BUTTON_POSITIVE = 1;
int BIT_BUTTON_NEGATIVE = 2;
int BIT_BUTTON_NEUTRAL = 4;
int whichButtons = 0;
- mButtonPositive = (Button) mWindow.findViewById(R.id.button1);
+ mButtonPositive = (Button) buttonPanel.findViewById(R.id.button1);
mButtonPositive.setOnClickListener(mButtonHandler);
if (TextUtils.isEmpty(mButtonPositiveText)) {
@@ -679,7 +737,7 @@ public class AlertController {
whichButtons = whichButtons | BIT_BUTTON_POSITIVE;
}
- mButtonNegative = (Button) mWindow.findViewById(R.id.button2);
+ mButtonNegative = (Button) buttonPanel.findViewById(R.id.button2);
mButtonNegative.setOnClickListener(mButtonHandler);
if (TextUtils.isEmpty(mButtonNegativeText)) {
@@ -691,7 +749,7 @@ public class AlertController {
whichButtons = whichButtons | BIT_BUTTON_NEGATIVE;
}
- mButtonNeutral = (Button) mWindow.findViewById(R.id.button3);
+ mButtonNeutral = (Button) buttonPanel.findViewById(R.id.button3);
mButtonNeutral.setOnClickListener(mButtonHandler);
if (TextUtils.isEmpty(mButtonNeutralText)) {
@@ -717,7 +775,10 @@ public class AlertController {
}
}
- return whichButtons != 0;
+ final boolean hasButtons = whichButtons != 0;
+ if (!hasButtons) {
+ buttonPanel.setVisibility(View.GONE);
+ }
}
private void centerButton(Button button) {