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 9073bae5dd6ecc067e3d1bb9918dbe61fd7631f2..ebac4f49cead0322b4c838c1226b212efb3ada55 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 |
@@ -18,9 +18,22 @@ 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): |
gone
2017/04/26 05:11:47
Not entirely sure if it makes sense to link to the
|
+ * |
+ * + 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. */ |
@@ -62,9 +75,13 @@ 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); |
@@ -72,19 +89,21 @@ public final class PromoDialogLayout extends BoundedLinearLayout { |
mIllustrationView.setImageResource(mParams.drawableResource); |
} |
- // TODO(dfalcantara): Lock the title in place, if requested by the DialogParams. |
+ // Create the header. Its margins are set here because they can be re-parented above. |
mHeaderView.setText(mParams.headerStringResource); |
ApiCompatibilityUtils.setMarginStart((MarginLayoutParams) mHeaderView.getLayoutParams(), |
getContext().getResources().getDimensionPixelSize(R.dimen.dialog_header_margin)); |
ApiCompatibilityUtils.setMarginEnd((MarginLayoutParams) mHeaderView.getLayoutParams(), |
getContext().getResources().getDimensionPixelSize(R.dimen.dialog_header_margin)); |
+ // 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); |
@@ -93,20 +112,17 @@ public final class PromoDialogLayout extends BoundedLinearLayout { |
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)); |
} |
} |