Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/PromoDialogLayout.java

Issue 2842943002: 🔍 PromoDialog tests (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.widget; 5 package org.chromium.chrome.browser.widget;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.util.AttributeSet; 8 import android.util.AttributeSet;
9 import android.view.ViewGroup; 9 import android.view.ViewGroup;
10 import android.view.ViewStub; 10 import android.view.ViewStub;
11 import android.widget.ImageView; 11 import android.widget.ImageView;
12 import android.widget.LinearLayout; 12 import android.widget.LinearLayout;
13 import android.widget.TextView; 13 import android.widget.TextView;
14 14
15 import org.chromium.base.ApiCompatibilityUtils; 15 import org.chromium.base.ApiCompatibilityUtils;
16 import org.chromium.chrome.R; 16 import org.chromium.chrome.R;
17 import org.chromium.chrome.browser.infobar.InfoBarControlLayout; 17 import org.chromium.chrome.browser.infobar.InfoBarControlLayout;
18 import org.chromium.chrome.browser.widget.PromoDialog.DialogParams; 18 import org.chromium.chrome.browser.widget.PromoDialog.DialogParams;
19 19
20 /** 20 /**
21 * View that handles orientation changes for the promo dialogs. When the width i s greater than the 21 * Lays out a promo dialog that is shown when Clank starts up.
22 * height, the promo content switches from vertical to horizontal and moves the illustration from 22 *
23 * the top of the text to the side of the text. 23 * Because of the versatility of dialog content and screen sizes, this layout ex hibits a bunch of
24 * 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
25 *
26 * + It hides controls when their resources are not specified by the {@link Dial ogParams}.
27 * The only two required components are the header text and the primary button label.
28 *
29 * + When the width is greater than the height, the promo content switches from vertical to
30 * horizontal and moves the illustration from the top of the text to the side of the text.
31 *
32 * + The buttons are always locked to the bottom of the dialog and stack when th ere isn't enough
33 * room to display them on one row.
34 *
35 * + If there is no promo illustration, the header text becomes locked to the to p of the dialog and
36 * doesn't scroll away.
24 */ 37 */
25 public final class PromoDialogLayout extends BoundedLinearLayout { 38 public final class PromoDialogLayout extends BoundedLinearLayout {
26 /** Content in the dialog that will flip orientation when the screen is wide . */ 39 /** Content in the dialog that will flip orientation when the screen is wide . */
27 private LinearLayout mFlippableContent; 40 private LinearLayout mFlippableContent;
28 41
29 /** Content in the dialog that can be scrolled. */ 42 /** Content in the dialog that can be scrolled. */
30 private LinearLayout mScrollableContent; 43 private LinearLayout mScrollableContent;
31 44
32 /** Illustration that teases the thing being promoted. */ 45 /** Illustration that teases the thing being promoted. */
33 private ImageView mIllustrationView; 46 private ImageView mIllustrationView;
(...skipping 21 matching lines...) Expand all
55 mIllustrationView = (ImageView) findViewById(R.id.illustration); 68 mIllustrationView = (ImageView) findViewById(R.id.illustration);
56 mHeaderView = (TextView) findViewById(R.id.header); 69 mHeaderView = (TextView) findViewById(R.id.header);
57 mSubheaderView = (TextView) findViewById(R.id.subheader); 70 mSubheaderView = (TextView) findViewById(R.id.subheader);
58 71
59 super.onFinishInflate(); 72 super.onFinishInflate();
60 } 73 }
61 74
62 /** Initializes the dialog contents using the given params. Should only be called once. */ 75 /** Initializes the dialog contents using the given params. Should only be called once. */
63 void initialize(DialogParams params) { 76 void initialize(DialogParams params) {
64 assert mParams == null && params != null; 77 assert mParams == null && params != null;
78 assert params.headerStringResource != 0;
79 assert params.primaryButtonStringResource != 0;
65 mParams = params; 80 mParams = params;
66 81
67 if (mParams.drawableResource == 0) { 82 if (mParams.drawableResource == 0) {
83 // Dialogs with no illustration make the header stay visible at all times instead of
84 // scrolling off on small screens.
68 ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustration View); 85 ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustration View);
69 ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView); 86 ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView);
70 addView(mHeaderView, 0); 87 addView(mHeaderView, 0);
71 } else { 88 } else {
72 mIllustrationView.setImageResource(mParams.drawableResource); 89 mIllustrationView.setImageResource(mParams.drawableResource);
73 } 90 }
74 91
75 // TODO(dfalcantara): Lock the title in place, if requested by the Dialo gParams. 92 // Create the header. Its margins are set here because they can be re-p arented above.
76 mHeaderView.setText(mParams.headerStringResource); 93 mHeaderView.setText(mParams.headerStringResource);
77 ApiCompatibilityUtils.setMarginStart((MarginLayoutParams) mHeaderView.ge tLayoutParams(), 94 ApiCompatibilityUtils.setMarginStart((MarginLayoutParams) mHeaderView.ge tLayoutParams(),
78 getContext().getResources().getDimensionPixelSize(R.dimen.dialog _header_margin)); 95 getContext().getResources().getDimensionPixelSize(R.dimen.dialog _header_margin));
79 ApiCompatibilityUtils.setMarginEnd((MarginLayoutParams) mHeaderView.getL ayoutParams(), 96 ApiCompatibilityUtils.setMarginEnd((MarginLayoutParams) mHeaderView.getL ayoutParams(),
80 getContext().getResources().getDimensionPixelSize(R.dimen.dialog _header_margin)); 97 getContext().getResources().getDimensionPixelSize(R.dimen.dialog _header_margin));
81 98
99 // Set up the subheader text.
82 if (mParams.subheaderStringResource == 0) { 100 if (mParams.subheaderStringResource == 0) {
83 ((ViewGroup) mSubheaderView.getParent()).removeView(mSubheaderView); 101 ((ViewGroup) mSubheaderView.getParent()).removeView(mSubheaderView);
84 } else { 102 } else {
85 mSubheaderView.setText(mParams.subheaderStringResource); 103 mSubheaderView.setText(mParams.subheaderStringResource);
86 } 104 }
87 105
106 // Create the footer.
88 ViewStub footerStub = (ViewStub) findViewById(R.id.footer_stub); 107 ViewStub footerStub = (ViewStub) findViewById(R.id.footer_stub);
89 if (mParams.footerStringResource == 0) { 108 if (mParams.footerStringResource == 0) {
90 ((ViewGroup) footerStub.getParent()).removeView(footerStub); 109 ((ViewGroup) footerStub.getParent()).removeView(footerStub);
91 } else { 110 } else {
92 mFooterView = (TextView) footerStub.inflate(); 111 mFooterView = (TextView) footerStub.inflate();
93 mFooterView.setText(mParams.footerStringResource); 112 mFooterView.setText(mParams.footerStringResource);
94 } 113 }
95 114
115 // Create the buttons.
96 DualControlLayout buttonBar = (DualControlLayout) findViewById(R.id.butt on_bar); 116 DualControlLayout buttonBar = (DualControlLayout) findViewById(R.id.butt on_bar);
97 if (mParams.primaryButtonStringResource != 0) { 117 String primaryString = getResources().getString(mParams.primaryButtonStr ingResource);
98 String primaryString = getResources().getString(mParams.primaryButto nStringResource); 118 buttonBar.addView(
119 DualControlLayout.createButtonForLayout(getContext(), true, prim aryString, null));
120
121 if (mParams.secondaryButtonStringResource != 0) {
122 String secondaryString =
123 getResources().getString(mParams.secondaryButtonStringResour ce);
99 buttonBar.addView(DualControlLayout.createButtonForLayout( 124 buttonBar.addView(DualControlLayout.createButtonForLayout(
100 getContext(), true, primaryString, null)); 125 getContext(), false, secondaryString, null));
101
102 if (mParams.secondaryButtonStringResource != 0) {
103 String secondaryString =
104 getResources().getString(mParams.secondaryButtonStringRe source);
105 buttonBar.addView(DualControlLayout.createButtonForLayout(
106 getContext(), false, secondaryString, null));
107 }
108 } else {
109 assert mParams.secondaryButtonStringResource == 0;
110 } 126 }
111 } 127 }
112 128
113 @Override 129 @Override
114 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 130 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
115 int availableWidth = MeasureSpec.getSize(widthMeasureSpec); 131 int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
116 int availableHeight = MeasureSpec.getSize(heightMeasureSpec); 132 int availableHeight = MeasureSpec.getSize(heightMeasureSpec);
117 133
118 if (availableWidth > availableHeight * 1.5) { 134 if (availableWidth > availableHeight * 1.5) {
119 mFlippableContent.setOrientation(LinearLayout.HORIZONTAL); 135 mFlippableContent.setOrientation(LinearLayout.HORIZONTAL);
120 } else { 136 } else {
121 mFlippableContent.setOrientation(LinearLayout.VERTICAL); 137 mFlippableContent.setOrientation(LinearLayout.VERTICAL);
122 } 138 }
123 139
124 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 140 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
125 } 141 }
126 142
127 /** Adds a standardized set of controls to the layout. */ 143 /** Adds a standardized set of controls to the layout. */
128 InfoBarControlLayout addControlLayout() { 144 InfoBarControlLayout addControlLayout() {
129 InfoBarControlLayout layout = new InfoBarControlLayout(getContext()); 145 InfoBarControlLayout layout = new InfoBarControlLayout(getContext());
130 mScrollableContent.addView( 146 mScrollableContent.addView(
131 layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams .WRAP_CONTENT)); 147 layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams .WRAP_CONTENT));
132 return layout; 148 return layout;
133 } 149 }
134 } 150 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698