Index: chrome/android/java/src/org/chromium/chrome/browser/widget/PromoDialogLayout.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/PromoDialogLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/PromoDialogLayout.java |
index 41243fb19bf13bb5e2cdf9316b7eaff318866ffa..970507f7a2aa0370209ecaac4813367fd0bd8dce 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/widget/PromoDialogLayout.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/PromoDialogLayout.java |
@@ -7,19 +7,38 @@ package org.chromium.chrome.browser.widget; |
import android.content.Context; |
import android.util.AttributeSet; |
import android.view.ViewGroup; |
+import android.view.ViewStub; |
import android.widget.ImageView; |
import android.widget.LinearLayout; |
import android.widget.TextView; |
+import org.chromium.base.ApiCompatibilityUtils; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.infobar.InfoBarControlLayout; |
import org.chromium.chrome.browser.widget.PromoDialog.DialogParams; |
/** |
- * View that handles orientation changes for the promo dialogs. When the width is greater than the |
- * height, the promo content switches from vertical to horizontal and moves the illustration from |
- * the top of the text to the side of the text. |
+ * Lays out a promo dialog that is shown when Clank starts up. |
+ * |
+ * Because of the versatility of dialog content and screen sizes, this layout exhibits a bunch of |
+ * specific behaviors (see go/snowflake-dialogs for details): |
+ * |
+ * + It hides controls when their resources are not specified by the {@link DialogParams}. |
+ * The only two required components are the header text and the primary button label. |
+ * |
+ * + When the width is greater than the height, the promo content switches from vertical to |
+ * horizontal and moves the illustration from the top of the text to the side of the text. |
+ * |
+ * + The buttons are always locked to the bottom of the dialog and stack when there isn't enough |
+ * room to display them on one row. |
+ * |
+ * + If there is no promo illustration, the header text becomes locked to the top of the dialog and |
+ * doesn't scroll away. |
*/ |
public final class PromoDialogLayout extends BoundedLinearLayout { |
+ /** Content in the dialog that will flip orientation when the screen is wide. */ |
+ private LinearLayout mFlippableContent; |
+ |
/** Content in the dialog that can be scrolled. */ |
private LinearLayout mScrollableContent; |
@@ -29,6 +48,9 @@ public final class PromoDialogLayout extends BoundedLinearLayout { |
/** View containing the header of the promo. */ |
private TextView mHeaderView; |
+ /** View containing the header of the promo. */ |
+ private TextView mFooterView; |
+ |
/** View containing text explaining the promo. */ |
private TextView mSubheaderView; |
@@ -41,7 +63,8 @@ public final class PromoDialogLayout extends BoundedLinearLayout { |
@Override |
public void onFinishInflate() { |
- mScrollableContent = (LinearLayout) findViewById(R.id.promo_content); |
+ mFlippableContent = (LinearLayout) findViewById(R.id.full_promo_content); |
+ mScrollableContent = (LinearLayout) findViewById(R.id.scrollable_promo_content); |
mIllustrationView = (ImageView) findViewById(R.id.illustration); |
mHeaderView = (TextView) findViewById(R.id.header); |
mSubheaderView = (TextView) findViewById(R.id.subheader); |
@@ -52,37 +75,59 @@ public final class PromoDialogLayout extends BoundedLinearLayout { |
/** Initializes the dialog contents using the given params. Should only be called once. */ |
void initialize(DialogParams params) { |
assert mParams == null && params != null; |
+ assert params.headerStringResource != 0; |
+ assert params.primaryButtonStringResource != 0; |
mParams = params; |
if (mParams.drawableResource == 0) { |
+ // Dialogs with no illustration make the header stay visible at all times instead of |
+ // scrolling off on small screens. |
((ViewGroup) mIllustrationView.getParent()).removeView(mIllustrationView); |
+ ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView); |
+ addView(mHeaderView, 0); |
+ |
+ // The margins only apply here (after it moves to the root) because the scroll layout it |
+ // is normally in has implicit padding. |
+ int marginSize = |
+ getContext().getResources().getDimensionPixelSize(R.dimen.dialog_header_margin); |
+ ApiCompatibilityUtils.setMarginStart( |
+ (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSize); |
+ ApiCompatibilityUtils.setMarginEnd( |
+ (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSize); |
} else { |
mIllustrationView.setImageResource(mParams.drawableResource); |
} |
- // TODO(dfalcantara): Lock the title in place, if requested by the DialogParams. |
+ // Create the header. |
mHeaderView.setText(mParams.headerStringResource); |
+ // Set up the subheader text. |
if (mParams.subheaderStringResource == 0) { |
((ViewGroup) mSubheaderView.getParent()).removeView(mSubheaderView); |
} else { |
mSubheaderView.setText(mParams.subheaderStringResource); |
} |
+ // Create the footer. |
+ ViewStub footerStub = (ViewStub) findViewById(R.id.footer_stub); |
+ if (mParams.footerStringResource == 0) { |
+ ((ViewGroup) footerStub.getParent()).removeView(footerStub); |
+ } else { |
+ mFooterView = (TextView) footerStub.inflate(); |
+ mFooterView.setText(mParams.footerStringResource); |
+ } |
+ |
+ // Create the buttons. |
DualControlLayout buttonBar = (DualControlLayout) findViewById(R.id.button_bar); |
- if (mParams.primaryButtonStringResource != 0) { |
- String primaryString = getResources().getString(mParams.primaryButtonStringResource); |
+ String primaryString = getResources().getString(mParams.primaryButtonStringResource); |
+ buttonBar.addView( |
+ DualControlLayout.createButtonForLayout(getContext(), true, primaryString, null)); |
+ |
+ if (mParams.secondaryButtonStringResource != 0) { |
+ String secondaryString = |
+ getResources().getString(mParams.secondaryButtonStringResource); |
buttonBar.addView(DualControlLayout.createButtonForLayout( |
- getContext(), true, primaryString, null)); |
- |
- if (mParams.secondaryButtonStringResource != 0) { |
- String secondaryString = |
- getResources().getString(mParams.secondaryButtonStringResource); |
- buttonBar.addView(DualControlLayout.createButtonForLayout( |
- getContext(), false, secondaryString, null)); |
- } |
- } else { |
- assert mParams.secondaryButtonStringResource == 0; |
+ getContext(), false, secondaryString, null)); |
} |
} |
@@ -92,11 +137,19 @@ public final class PromoDialogLayout extends BoundedLinearLayout { |
int availableHeight = MeasureSpec.getSize(heightMeasureSpec); |
if (availableWidth > availableHeight * 1.5) { |
- mScrollableContent.setOrientation(LinearLayout.HORIZONTAL); |
+ mFlippableContent.setOrientation(LinearLayout.HORIZONTAL); |
} else { |
- mScrollableContent.setOrientation(LinearLayout.VERTICAL); |
+ mFlippableContent.setOrientation(LinearLayout.VERTICAL); |
} |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
} |
+ |
+ /** Adds a standardized set of controls to the layout. */ |
+ InfoBarControlLayout addControlLayout() { |
+ InfoBarControlLayout layout = new InfoBarControlLayout(getContext()); |
+ mScrollableContent.addView( |
+ layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); |
+ return layout; |
+ } |
} |