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

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

Issue 2838833002: 🔍 Introduce default search engine dialog (Closed)
Patch Set: Some adjusments Created 3 years, 7 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
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.widget.ImageView; 11 import android.widget.ImageView;
11 import android.widget.LinearLayout; 12 import android.widget.LinearLayout;
12 import android.widget.TextView; 13 import android.widget.TextView;
13 14
15 import org.chromium.base.ApiCompatibilityUtils;
14 import org.chromium.chrome.R; 16 import org.chromium.chrome.R;
17 import org.chromium.chrome.browser.infobar.InfoBarControlLayout;
15 import org.chromium.chrome.browser.widget.PromoDialog.DialogParams; 18 import org.chromium.chrome.browser.widget.PromoDialog.DialogParams;
16 19
17 /** 20 /**
18 * 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.
19 * height, the promo content switches from vertical to horizontal and moves the illustration from 22 *
20 * 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:52:36 Clarified why this class is a bit messy by expandi
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.
21 */ 37 */
22 public final class PromoDialogLayout extends BoundedLinearLayout { 38 public final class PromoDialogLayout extends BoundedLinearLayout {
39 /** Content in the dialog that will flip orientation when the screen is wide . */
40 private LinearLayout mFlippableContent;
41
23 /** Content in the dialog that can be scrolled. */ 42 /** Content in the dialog that can be scrolled. */
24 private LinearLayout mScrollableContent; 43 private LinearLayout mScrollableContent;
25 44
26 /** Illustration that teases the thing being promoted. */ 45 /** Illustration that teases the thing being promoted. */
27 private ImageView mIllustrationView; 46 private ImageView mIllustrationView;
28 47
29 /** View containing the header of the promo. */ 48 /** View containing the header of the promo. */
30 private TextView mHeaderView; 49 private TextView mHeaderView;
31 50
51 /** View containing the header of the promo. */
52 private TextView mFooterView;
53
32 /** View containing text explaining the promo. */ 54 /** View containing text explaining the promo. */
33 private TextView mSubheaderView; 55 private TextView mSubheaderView;
34 56
35 /** Paramters used to build the promo. */ 57 /** Paramters used to build the promo. */
36 private DialogParams mParams; 58 private DialogParams mParams;
37 59
38 public PromoDialogLayout(Context context, AttributeSet attrs) { 60 public PromoDialogLayout(Context context, AttributeSet attrs) {
39 super(context, attrs); 61 super(context, attrs);
40 } 62 }
41 63
42 @Override 64 @Override
43 public void onFinishInflate() { 65 public void onFinishInflate() {
44 mScrollableContent = (LinearLayout) findViewById(R.id.promo_content); 66 mFlippableContent = (LinearLayout) findViewById(R.id.full_promo_content) ;
67 mScrollableContent = (LinearLayout) findViewById(R.id.scrollable_promo_c ontent);
45 mIllustrationView = (ImageView) findViewById(R.id.illustration); 68 mIllustrationView = (ImageView) findViewById(R.id.illustration);
46 mHeaderView = (TextView) findViewById(R.id.header); 69 mHeaderView = (TextView) findViewById(R.id.header);
47 mSubheaderView = (TextView) findViewById(R.id.subheader); 70 mSubheaderView = (TextView) findViewById(R.id.subheader);
48 71
49 super.onFinishInflate(); 72 super.onFinishInflate();
50 } 73 }
51 74
52 /** 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. */
53 void initialize(DialogParams params) { 76 void initialize(DialogParams params) {
54 assert mParams == null && params != null; 77 assert mParams == null && params != null;
78 assert params.headerStringResource != 0;
79 assert params.primaryButtonStringResource != 0;
55 mParams = params; 80 mParams = params;
56 81
57 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.
58 ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustration View); 85 ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustration View);
86 ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView);
87 addView(mHeaderView, 0);
88
89 // The margins only apply here (after it moves to the root) because the scroll layout it
90 // is normally in has implicit padding.
91 int marginSize =
92 getContext().getResources().getDimensionPixelSize(R.dimen.di alog_header_margin);
93 ApiCompatibilityUtils.setMarginStart(
94 (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSi ze);
95 ApiCompatibilityUtils.setMarginEnd(
96 (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSi ze);
59 } else { 97 } else {
60 mIllustrationView.setImageResource(mParams.drawableResource); 98 mIllustrationView.setImageResource(mParams.drawableResource);
61 } 99 }
62 100
63 // TODO(dfalcantara): Lock the title in place, if requested by the Dialo gParams. 101 // Create the header.
64 mHeaderView.setText(mParams.headerStringResource); 102 mHeaderView.setText(mParams.headerStringResource);
65 103
104 // Set up the subheader text.
66 if (mParams.subheaderStringResource == 0) { 105 if (mParams.subheaderStringResource == 0) {
67 ((ViewGroup) mSubheaderView.getParent()).removeView(mSubheaderView); 106 ((ViewGroup) mSubheaderView.getParent()).removeView(mSubheaderView);
68 } else { 107 } else {
69 mSubheaderView.setText(mParams.subheaderStringResource); 108 mSubheaderView.setText(mParams.subheaderStringResource);
70 } 109 }
71 110
111 // Create the footer.
112 ViewStub footerStub = (ViewStub) findViewById(R.id.footer_stub);
113 if (mParams.footerStringResource == 0) {
114 ((ViewGroup) footerStub.getParent()).removeView(footerStub);
115 } else {
116 mFooterView = (TextView) footerStub.inflate();
117 mFooterView.setText(mParams.footerStringResource);
118 }
119
120 // Create the buttons.
72 DualControlLayout buttonBar = (DualControlLayout) findViewById(R.id.butt on_bar); 121 DualControlLayout buttonBar = (DualControlLayout) findViewById(R.id.butt on_bar);
73 if (mParams.primaryButtonStringResource != 0) { 122 String primaryString = getResources().getString(mParams.primaryButtonStr ingResource);
74 String primaryString = getResources().getString(mParams.primaryButto nStringResource); 123 buttonBar.addView(
124 DualControlLayout.createButtonForLayout(getContext(), true, prim aryString, null));
125
126 if (mParams.secondaryButtonStringResource != 0) {
127 String secondaryString =
128 getResources().getString(mParams.secondaryButtonStringResour ce);
75 buttonBar.addView(DualControlLayout.createButtonForLayout( 129 buttonBar.addView(DualControlLayout.createButtonForLayout(
76 getContext(), true, primaryString, null)); 130 getContext(), false, secondaryString, null));
77
78 if (mParams.secondaryButtonStringResource != 0) {
79 String secondaryString =
80 getResources().getString(mParams.secondaryButtonStringRe source);
81 buttonBar.addView(DualControlLayout.createButtonForLayout(
82 getContext(), false, secondaryString, null));
83 }
84 } else {
85 assert mParams.secondaryButtonStringResource == 0;
86 } 131 }
87 } 132 }
88 133
89 @Override 134 @Override
90 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 135 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
91 int availableWidth = MeasureSpec.getSize(widthMeasureSpec); 136 int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
92 int availableHeight = MeasureSpec.getSize(heightMeasureSpec); 137 int availableHeight = MeasureSpec.getSize(heightMeasureSpec);
93 138
94 if (availableWidth > availableHeight * 1.5) { 139 if (availableWidth > availableHeight * 1.5) {
95 mScrollableContent.setOrientation(LinearLayout.HORIZONTAL); 140 mFlippableContent.setOrientation(LinearLayout.HORIZONTAL);
96 } else { 141 } else {
97 mScrollableContent.setOrientation(LinearLayout.VERTICAL); 142 mFlippableContent.setOrientation(LinearLayout.VERTICAL);
98 } 143 }
99 144
100 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 145 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
101 } 146 }
147
148 /** Adds a standardized set of controls to the layout. */
149 InfoBarControlLayout addControlLayout() {
150 InfoBarControlLayout layout = new InfoBarControlLayout(getContext());
151 mScrollableContent.addView(
152 layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams .WRAP_CONTENT));
153 return layout;
154 }
102 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698