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

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

Issue 2902793002: Add better handling for very, very small promo dialogs. (Closed)
Patch Set: Address comments 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.support.graphics.drawable.VectorDrawableCompat; 8 import android.support.graphics.drawable.VectorDrawableCompat;
9 import android.util.AttributeSet; 9 import android.util.AttributeSet;
10 import android.view.View; 10 import android.view.View;
(...skipping 22 matching lines...) Expand all
33 * + The buttons are always locked to the bottom of the dialog and stack when th ere isn't enough 33 * + The buttons are always locked to the bottom of the dialog and stack when th ere isn't enough
34 * room to display them on one row. 34 * room to display them on one row.
35 * 35 *
36 * + If there is no promo illustration, the header text becomes locked to the to p of the dialog and 36 * + If there is no promo illustration, the header text becomes locked to the to p of the dialog and
37 * doesn't scroll away. 37 * doesn't scroll away.
38 */ 38 */
39 public final class PromoDialogLayout extends BoundedLinearLayout { 39 public final class PromoDialogLayout extends BoundedLinearLayout {
40 /** Content in the dialog that will flip orientation when the screen is wide . */ 40 /** Content in the dialog that will flip orientation when the screen is wide . */
41 private LinearLayout mFlippableContent; 41 private LinearLayout mFlippableContent;
42 42
43 /** The scrolling container for the scrollable content. */
44 private ViewGroup mScrollingContainer;
45
43 /** Content in the dialog that can be scrolled. */ 46 /** Content in the dialog that can be scrolled. */
44 private LinearLayout mScrollableContent; 47 private LinearLayout mScrollableContent;
45 48
46 /** Illustration that teases the thing being promoted. */ 49 /** Illustration that teases the thing being promoted. */
47 private ImageView mIllustrationView; 50 private ImageView mIllustrationView;
48 51
49 /** View containing the header of the promo. */ 52 /** View containing the header of the promo. */
50 private TextView mHeaderView; 53 private TextView mHeaderView;
51 54
52 /** View containing the header of the promo. */ 55 /** View containing the header of the promo. */
53 private TextView mFooterView; 56 private TextView mFooterView;
54 57
55 /** View containing text explaining the promo. */ 58 /** View containing text explaining the promo. */
56 private TextView mSubheaderView; 59 private TextView mSubheaderView;
57 60
58 /** Paramters used to build the promo. */ 61 /** Paramters used to build the promo. */
59 private DialogParams mParams; 62 private DialogParams mParams;
60 63
61 public PromoDialogLayout(Context context, AttributeSet attrs) { 64 public PromoDialogLayout(Context context, AttributeSet attrs) {
62 super(context, attrs); 65 super(context, attrs);
63 } 66 }
64 67
65 @Override 68 @Override
66 public void onFinishInflate() { 69 public void onFinishInflate() {
67 mFlippableContent = (LinearLayout) findViewById(R.id.full_promo_content) ; 70 mFlippableContent = (LinearLayout) findViewById(R.id.full_promo_content) ;
71 mScrollingContainer = (ViewGroup) findViewById(R.id.promo_container);
68 mScrollableContent = (LinearLayout) findViewById(R.id.scrollable_promo_c ontent); 72 mScrollableContent = (LinearLayout) findViewById(R.id.scrollable_promo_c ontent);
69 mIllustrationView = (ImageView) findViewById(R.id.illustration); 73 mIllustrationView = (ImageView) findViewById(R.id.illustration);
70 mHeaderView = (TextView) findViewById(R.id.header); 74 mHeaderView = (TextView) findViewById(R.id.header);
71 mSubheaderView = (TextView) findViewById(R.id.subheader); 75 mSubheaderView = (TextView) findViewById(R.id.subheader);
72 76
73 super.onFinishInflate(); 77 super.onFinishInflate();
74 } 78 }
75 79
76 /** Initializes the dialog contents using the given params. Should only be called once. */ 80 /** Initializes the dialog contents using the given params. Should only be called once. */
77 void initialize(DialogParams params) { 81 void initialize(DialogParams params) {
78 assert mParams == null && params != null; 82 assert mParams == null && params != null;
79 assert params.headerStringResource != 0; 83 assert params.headerStringResource != 0;
80 assert params.primaryButtonStringResource != 0; 84 assert params.primaryButtonStringResource != 0;
81 mParams = params; 85 mParams = params;
82 86
83 if (mParams.drawableResource == 0 && mParams.vectorDrawableResource == 0 ) { 87 if (mParams.drawableResource == 0 && mParams.vectorDrawableResource == 0 ) {
84 // Dialogs with no illustration make the header stay visible at all times instead of 88 // Dialogs with no illustration make the header stay visible at all times instead of
85 // scrolling off on small screens. 89 // scrolling off on small screens.
86 ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustration View); 90 ((ViewGroup) mIllustrationView.getParent()).removeView(mIllustration View);
87 ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView);
88 addView(mHeaderView, 0);
89
90 // The margins only apply here (after it moves to the root) because the scroll layout it
91 // is normally in has implicit padding.
92 int marginSize =
93 getContext().getResources().getDimensionPixelSize(R.dimen.di alog_header_margin);
94 ApiCompatibilityUtils.setMarginStart(
95 (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSi ze);
96 ApiCompatibilityUtils.setMarginEnd(
97 (MarginLayoutParams) mHeaderView.getLayoutParams(), marginSi ze);
98 } else if (mParams.vectorDrawableResource != 0) { 91 } else if (mParams.vectorDrawableResource != 0) {
99 mIllustrationView.setImageDrawable(VectorDrawableCompat.create( 92 mIllustrationView.setImageDrawable(VectorDrawableCompat.create(
100 getResources(), mParams.vectorDrawableResource, getContext() .getTheme())); 93 getResources(), mParams.vectorDrawableResource, getContext() .getTheme()));
101 } else { 94 } else {
102 mIllustrationView.setImageResource(mParams.drawableResource); 95 mIllustrationView.setImageResource(mParams.drawableResource);
103 } 96 }
104 97
105 // Create the header. 98 // Create the header.
106 mHeaderView.setText(mParams.headerStringResource); 99 mHeaderView.setText(mParams.headerStringResource);
107 100
(...skipping 20 matching lines...) Expand all
128 DualControlLayout.createButtonForLayout(getContext(), true, prim aryString, null)); 121 DualControlLayout.createButtonForLayout(getContext(), true, prim aryString, null));
129 122
130 if (mParams.secondaryButtonStringResource != 0) { 123 if (mParams.secondaryButtonStringResource != 0) {
131 String secondaryString = 124 String secondaryString =
132 getResources().getString(mParams.secondaryButtonStringResour ce); 125 getResources().getString(mParams.secondaryButtonStringResour ce);
133 buttonBar.addView(DualControlLayout.createButtonForLayout( 126 buttonBar.addView(DualControlLayout.createButtonForLayout(
134 getContext(), false, secondaryString, null)); 127 getContext(), false, secondaryString, null));
135 } 128 }
136 } 129 }
137 130
131 /**
132 * Determines whether the header layout needs to be adjusted to ensure the s crollable content
133 * is usable in small form factors.
134 *
135 * @return Whether the layout needed to be adjusted.
136 */
137 private boolean fixupHeader() {
138 if (mParams.drawableResource != 0 || mParams.vectorDrawableResource != 0 ) return false;
139
140 int minScrollHeight =
141 getResources().getDimensionPixelSize(R.dimen.promo_dialog_min_sc rollable_height);
142 boolean shouldHeaderScroll = mScrollingContainer.getMeasuredHeight() < m inScrollHeight;
143 ViewGroup desiredParent;
144 boolean applyHeaderPadding;
145 if (shouldHeaderScroll) {
146 desiredParent = mScrollableContent;
147 applyHeaderPadding = false;
148 } else {
149 desiredParent = this;
150 applyHeaderPadding = true;
151 }
152 if (mHeaderView.getParent() == desiredParent) return false;
153 ((ViewGroup) mHeaderView.getParent()).removeView(mHeaderView);
154 desiredParent.addView(mHeaderView, 0);
155
156 int startEndPadding = applyHeaderPadding
157 ? getResources().getDimensionPixelSize(R.dimen.promo_dialog_padd ing)
158 : 0;
159 ApiCompatibilityUtils.setPaddingRelative(
160 mHeaderView, startEndPadding, 0, startEndPadding, 0);
161 return true;
162 }
163
138 @Override 164 @Override
139 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 165 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
140 int availableWidth = MeasureSpec.getSize(widthMeasureSpec); 166 int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
141 int availableHeight = MeasureSpec.getSize(heightMeasureSpec); 167 int availableHeight = MeasureSpec.getSize(heightMeasureSpec);
142 168
143 if (availableWidth > availableHeight * 1.5) { 169 if (availableWidth > availableHeight * 1.5) {
144 mFlippableContent.setOrientation(LinearLayout.HORIZONTAL); 170 mFlippableContent.setOrientation(LinearLayout.HORIZONTAL);
145 } else { 171 } else {
146 mFlippableContent.setOrientation(LinearLayout.VERTICAL); 172 mFlippableContent.setOrientation(LinearLayout.VERTICAL);
147 } 173 }
148 174
149 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 175 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
176 if (fixupHeader()) super.onMeasure(widthMeasureSpec, heightMeasureSpec);
150 } 177 }
151 178
152 /** Adds a View to the layout within the scrollable area. */ 179 /** Adds a View to the layout within the scrollable area. */
153 void addControl(View control) { 180 void addControl(View control) {
154 mScrollableContent.addView( 181 mScrollableContent.addView(
155 control, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParam s.WRAP_CONTENT)); 182 control, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParam s.WRAP_CONTENT));
156 } 183 }
157 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698