OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.infobar; | 5 package org.chromium.chrome.browser.infobar; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
9 import android.content.res.TypedArray; | 9 import android.content.res.TypedArray; |
10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
11 import android.graphics.Color; | 11 import android.graphics.Color; |
12 import android.graphics.drawable.Drawable; | 12 import android.graphics.drawable.Drawable; |
13 import android.text.TextUtils; | 13 import android.text.TextUtils; |
14 import android.text.method.LinkMovementMethod; | 14 import android.text.method.LinkMovementMethod; |
15 import android.view.Gravity; | 15 import android.view.Gravity; |
16 import android.view.LayoutInflater; | 16 import android.view.LayoutInflater; |
17 import android.view.View; | 17 import android.view.View; |
18 import android.view.ViewGroup; | 18 import android.view.ViewGroup; |
19 import android.widget.Button; | 19 import android.widget.Button; |
20 import android.widget.ImageButton; | 20 import android.widget.ImageButton; |
21 import android.widget.ImageView; | 21 import android.widget.ImageView; |
22 import android.widget.TextView; | 22 import android.widget.TextView; |
23 | 23 |
24 import org.chromium.base.ApiCompatibilityUtils; | 24 import org.chromium.base.ApiCompatibilityUtils; |
25 import org.chromium.chrome.R; | 25 import org.chromium.chrome.R; |
| 26 import org.chromium.chrome.browser.widget.ButtonCompat; |
| 27 |
| 28 import java.util.ArrayList; |
26 | 29 |
27 /** | 30 /** |
28 * Layout that arranges an InfoBar's views. An InfoBarLayout consists of: | 31 * Layout that arranges an InfoBar's views. An InfoBarLayout consists of: |
29 * - A message describing the action that the user can take. | 32 * - A message describing the action that the user can take. |
30 * - A close button on the right side. | 33 * - A close button on the right side. |
31 * - (optional) An icon representing the infobar's purpose on the left side. | 34 * - (optional) An icon representing the infobar's purpose on the left side. |
32 * - (optional) Additional "custom" views (e.g. a checkbox and text, or a pair o
f spinners) | 35 * - (optional) Additional "custom" views (e.g. a checkbox and text, or a pair o
f spinners) |
33 * - (optional) One or two buttons with text at the bottom. | 36 * - (optional) One or two buttons with text at the bottom. |
34 * | 37 * |
35 * When adding custom views, widths and heights defined in the LayoutParams will
be ignored. | 38 * When adding custom views, widths and heights defined in the LayoutParams will
be ignored. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 72 |
70 /** | 73 /** |
71 * The gravity of each view in Group. Must be either Gravity.START, Grav
ity.END, or | 74 * The gravity of each view in Group. Must be either Gravity.START, Grav
ity.END, or |
72 * Gravity.FILL_HORIZONTAL. | 75 * Gravity.FILL_HORIZONTAL. |
73 */ | 76 */ |
74 public int gravity = Gravity.START; | 77 public int gravity = Gravity.START; |
75 | 78 |
76 /** Whether the views are vertically stacked. */ | 79 /** Whether the views are vertically stacked. */ |
77 public boolean isStacked; | 80 public boolean isStacked; |
78 | 81 |
| 82 Group(View... views) { |
| 83 this.views = views; |
| 84 } |
| 85 |
| 86 static View[] filterNullViews(View... views) { |
| 87 ArrayList<View> viewsList = new ArrayList<View>(); |
| 88 for (View v : views) { |
| 89 if (v != null) viewsList.add(v); |
| 90 } |
| 91 return viewsList.toArray(new View[viewsList.size()]); |
| 92 } |
| 93 |
79 void setHorizontalMode(int horizontalSpacing, int startMargin, int endMa
rgin) { | 94 void setHorizontalMode(int horizontalSpacing, int startMargin, int endMa
rgin) { |
80 isStacked = false; | 95 isStacked = false; |
81 for (int i = 0; i < views.length; i++) { | 96 for (int i = 0; i < views.length; i++) { |
82 LayoutParams lp = (LayoutParams) views[i].getLayoutParams(); | 97 LayoutParams lp = (LayoutParams) views[i].getLayoutParams(); |
83 lp.startMargin = i == 0 ? startMargin : horizontalSpacing; | 98 lp.startMargin = i == 0 ? startMargin : horizontalSpacing; |
84 lp.topMargin = 0; | 99 lp.topMargin = 0; |
85 lp.endMargin = i == views.length - 1 ? endMargin : 0; | 100 lp.endMargin = i == views.length - 1 ? endMargin : 0; |
86 lp.bottomMargin = 0; | 101 lp.bottomMargin = 0; |
87 } | 102 } |
88 | |
89 } | 103 } |
90 | 104 |
91 void setVerticalMode(int verticalSpacing, int bottomMargin) { | 105 void setVerticalMode(int verticalSpacing, int bottomMargin) { |
92 isStacked = true; | 106 isStacked = true; |
93 for (int i = 0; i < views.length; i++) { | 107 for (int i = 0; i < views.length; i++) { |
94 LayoutParams lp = (LayoutParams) views[i].getLayoutParams(); | 108 LayoutParams lp = (LayoutParams) views[i].getLayoutParams(); |
95 lp.startMargin = 0; | 109 lp.startMargin = 0; |
96 lp.topMargin = i == 0 ? 0 : verticalSpacing; | 110 lp.topMargin = i == 0 ? 0 : verticalSpacing; |
97 lp.endMargin = 0; | 111 lp.endMargin = 0; |
98 lp.bottomMargin = i == views.length - 1 ? bottomMargin : 0; | 112 lp.bottomMargin = i == views.length - 1 ? bottomMargin : 0; |
99 } | 113 } |
100 } | 114 } |
101 } | 115 } |
102 | 116 |
103 private static final int ROW_MAIN = 1; | 117 private static final int ROW_MAIN = 1; |
104 private static final int ROW_OTHER = 2; | 118 private static final int ROW_OTHER = 2; |
105 | 119 |
106 private final int mMargin; | 120 private final int mMargin; |
107 private final int mIconSize; | 121 private final int mIconSize; |
108 private final int mMinWidth; | 122 private final int mMinWidth; |
109 private final int mAccentColor; | 123 private final int mAccentColor; |
110 | 124 |
111 private final InfoBarView mInfoBarView; | 125 private final InfoBarView mInfoBarView; |
112 private final TextView mMessageView; | |
113 private final ImageButton mCloseButton; | 126 private final ImageButton mCloseButton; |
| 127 private TextView mMessageTextView; |
| 128 private View mMessageView; |
114 private ImageView mIconView; | 129 private ImageView mIconView; |
| 130 private ButtonCompat mPrimaryButton; |
| 131 private Button mSecondaryButton; |
| 132 private Button mTertiaryButton; |
| 133 private View mCustomButton; |
115 | 134 |
116 private Group mMainGroup; | 135 private Group mMainGroup; |
117 private Group mCustomGroup; | 136 private Group mCustomGroup; |
118 private Group mButtonGroup; | 137 private Group mButtonGroup; |
119 | 138 |
120 /** | 139 /** |
121 * These values are used during onMeasure() to track where the next view wil
l be placed. | 140 * These values are used during onMeasure() to track where the next view wil
l be placed. |
122 * | 141 * |
123 * mWidth is the infobar width. | 142 * mWidth is the infobar width. |
124 * [mStart, mEnd) is the range of unoccupied space on the current row. | 143 * [mStart, mEnd) is the range of unoccupied space on the current row. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 mCloseButton.setImageResource(R.drawable.btn_close); | 181 mCloseButton.setImageResource(R.drawable.btn_close); |
163 TypedArray a = getContext().obtainStyledAttributes( | 182 TypedArray a = getContext().obtainStyledAttributes( |
164 new int [] {R.attr.selectableItemBackground}); | 183 new int [] {R.attr.selectableItemBackground}); |
165 Drawable closeButtonBackground = a.getDrawable(0); | 184 Drawable closeButtonBackground = a.getDrawable(0); |
166 a.recycle(); | 185 a.recycle(); |
167 ApiCompatibilityUtils.setBackgroundForView(mCloseButton, closeButtonBack
ground); | 186 ApiCompatibilityUtils.setBackgroundForView(mCloseButton, closeButtonBack
ground); |
168 mCloseButton.setPadding(mMargin, mMargin, mMargin, mMargin); | 187 mCloseButton.setPadding(mMargin, mMargin, mMargin, mMargin); |
169 mCloseButton.setOnClickListener(this); | 188 mCloseButton.setOnClickListener(this); |
170 mCloseButton.setContentDescription(res.getString(R.string.infobar_close)
); | 189 mCloseButton.setContentDescription(res.getString(R.string.infobar_close)
); |
171 mCloseButton.setLayoutParams(new LayoutParams(0, -mMargin, -mMargin, -mM
argin)); | 190 mCloseButton.setLayoutParams(new LayoutParams(0, -mMargin, -mMargin, -mM
argin)); |
172 addView(mCloseButton); | |
173 | 191 |
174 // Set up the icon. | 192 // Set up the icon. |
175 if (iconResourceId != 0 || iconBitmap != null) { | 193 if (iconResourceId != 0 || iconBitmap != null) { |
176 mIconView = new ImageView(context); | 194 mIconView = new ImageView(context); |
177 mIconView.setId(R.id.infobar_icon); | |
178 if (iconResourceId != 0) { | 195 if (iconResourceId != 0) { |
179 mIconView.setImageResource(iconResourceId); | 196 mIconView.setImageResource(iconResourceId); |
180 } else if (iconBitmap != null) { | 197 } else if (iconBitmap != null) { |
181 mIconView.setImageBitmap(iconBitmap); | 198 mIconView.setImageBitmap(iconBitmap); |
182 } | 199 } |
183 mIconView.setLayoutParams(new LayoutParams(0, 0, mMargin / 2, 0)); | 200 mIconView.setLayoutParams(new LayoutParams(0, 0, mMargin / 2, 0)); |
184 mIconView.getLayoutParams().width = mIconSize; | 201 mIconView.getLayoutParams().width = mIconSize; |
185 mIconView.getLayoutParams().height = mIconSize; | 202 mIconView.getLayoutParams().height = mIconSize; |
186 mIconView.setFocusable(false); | 203 mIconView.setFocusable(false); |
187 } | 204 } |
188 | 205 |
189 // Set up the message view. | 206 // Set up the message view. |
190 mMessageView = (TextView) LayoutInflater.from(context).inflate(R.layout.
infobar_text, null); | 207 mMessageTextView = (TextView) LayoutInflater.from(context).inflate(R.lay
out.infobar_text, |
191 mMessageView.setText(message, TextView.BufferType.SPANNABLE); | 208 null); |
192 mMessageView.setMovementMethod(LinkMovementMethod.getInstance()); | 209 mMessageTextView.setText(message, TextView.BufferType.SPANNABLE); |
193 mMessageView.setLinkTextColor(mAccentColor); | 210 mMessageTextView.setMovementMethod(LinkMovementMethod.getInstance()); |
194 mMessageView.setLayoutParams(new LayoutParams(0, mMargin / 4, 0, 0)); | 211 mMessageTextView.setLinkTextColor(mAccentColor); |
195 | 212 mMessageView = mMessageTextView; |
196 if (mIconView == null) { | |
197 mMainGroup = addGroup(mMessageView); | |
198 } else { | |
199 mMainGroup = addGroup(mIconView, mMessageView); | |
200 } | |
201 } | 213 } |
202 | 214 |
203 /** | 215 /** |
204 * Sets the message to show on the infobar. | 216 * Sets the message to show on the infobar. |
205 */ | 217 */ |
206 public void setMessage(CharSequence message) { | 218 public void setMessage(CharSequence message) { |
207 mMessageView.setText(message, TextView.BufferType.SPANNABLE); | 219 mMessageTextView.setText(message, TextView.BufferType.SPANNABLE); |
208 } | 220 } |
209 | 221 |
210 /** | 222 /** |
| 223 * Sets a custom view to show in place of the message. |
| 224 */ |
| 225 public void setMessageView(View view) { |
| 226 mMessageView = view; |
| 227 mMessageTextView = null; |
| 228 } |
| 229 |
| 230 /** |
211 * Sets the custom content of the infobar. These views will be displayed in
addition to the | 231 * Sets the custom content of the infobar. These views will be displayed in
addition to the |
212 * standard infobar controls (icon, text, buttons). Depending on the availab
le space, view1 and | 232 * standard infobar controls (icon, text, buttons). Depending on the availab
le space, view1 and |
213 * view2 will be laid out: | 233 * view2 will be laid out: |
214 * - Side by side on the main row, | 234 * - Side by side on the main row, |
215 * - Side by side on a separate row, each taking up half the width of the i
nfobar, | 235 * - Side by side on a separate row, each taking up half the width of the i
nfobar, |
216 * - Stacked above each other on two separate rows, taking up the full widt
h of the infobar. | 236 * - Stacked above each other on two separate rows, taking up the full widt
h of the infobar. |
217 */ | 237 */ |
218 public void setCustomContent(View view1, View view2) { | 238 public void setCustomContent(View view1, View view2) { |
219 mCustomGroup = addGroup(view1, view2); | 239 mCustomGroup = new Group(view1, view2); |
220 } | 240 } |
221 | 241 |
222 /** | 242 /** |
223 * Sets the custom content of the infobar to a single view. This view will b
e displayed in | 243 * Sets the custom content of the infobar to a single view. This view will b
e displayed in |
224 * addition to the standard infobar controls. Depending on the available spa
ce, the view will be | 244 * addition to the standard infobar controls. Depending on the available spa
ce, the view will be |
225 * displayed: | 245 * displayed: |
226 * - On the main row, start-aligned or end-aligned depending on whether the
re are also | 246 * - On the main row, start-aligned or end-aligned depending on whether the
re are also |
227 * buttons on the main row, OR | 247 * buttons on the main row, OR |
228 * - On a separate row, start-aligned | 248 * - On a separate row, start-aligned |
229 */ | 249 */ |
230 public void setCustomContent(View view) { | 250 public void setCustomContent(View view) { |
231 mCustomGroup = addGroup(view); | 251 mCustomGroup = new Group(view); |
232 } | 252 } |
233 | 253 |
234 /** | 254 /** |
235 * Calls setButtons(primaryText, secondaryText, null). | 255 * Calls setButtons(primaryText, secondaryText, null). |
236 */ | 256 */ |
237 public void setButtons(String primaryText, String secondaryText) { | 257 public void setButtons(String primaryText, String secondaryText) { |
238 setButtons(primaryText, secondaryText, null); | 258 setButtons(primaryText, secondaryText, null); |
239 } | 259 } |
240 | 260 |
241 /** | 261 /** |
242 * Adds one, two, or three buttons to the layout. | 262 * Adds one, two, or three buttons to the layout. |
243 * | 263 * |
244 * @param primaryText Text for the primary button. | 264 * @param primaryText Text for the primary button. |
245 * @param secondaryText Text for the secondary button, or null if there isn'
t a second button. | 265 * @param secondaryText Text for the secondary button, or null if there isn'
t a second button. |
246 * @param tertiaryText Text for the tertiary button, or null if there isn't
a third button. | 266 * @param tertiaryText Text for the tertiary button, or null if there isn't
a third button. |
247 */ | 267 */ |
248 public void setButtons(String primaryText, String secondaryText, String tert
iaryText) { | 268 public void setButtons(String primaryText, String secondaryText, String tert
iaryText) { |
249 if (TextUtils.isEmpty(primaryText)) return; | 269 if (TextUtils.isEmpty(primaryText)) return; |
250 | 270 |
251 LayoutInflater inflater = LayoutInflater.from(getContext()); | 271 mPrimaryButton = new ButtonCompat(getContext(), mAccentColor); |
252 Button primaryButton = (Button) inflater.inflate(R.layout.infobar_button
, null); | 272 mPrimaryButton.setId(R.id.button_primary); |
253 primaryButton.setId(R.id.button_primary); | 273 mPrimaryButton.setOnClickListener(this); |
254 primaryButton.setOnClickListener(this); | 274 mPrimaryButton.setText(primaryText); |
255 primaryButton.setText(primaryText); | 275 mPrimaryButton.setTextColor(Color.WHITE); |
256 primaryButton.setBackgroundResource(R.drawable.btn_infobar_blue); | |
257 primaryButton.setTextColor(Color.WHITE); | |
258 | 276 |
259 if (TextUtils.isEmpty(secondaryText)) { | 277 if (TextUtils.isEmpty(secondaryText)) return; |
260 mButtonGroup = addGroup(primaryButton); | |
261 return; | |
262 } | |
263 | 278 |
264 Button secondaryButton = (Button) inflater.inflate(R.layout.infobar_butt
on, null); | 279 mSecondaryButton = ButtonCompat.createBorderlessButton(getContext()); |
265 secondaryButton.setId(R.id.button_secondary); | 280 mSecondaryButton.setId(R.id.button_secondary); |
266 secondaryButton.setOnClickListener(this); | 281 mSecondaryButton.setOnClickListener(this); |
267 secondaryButton.setText(secondaryText); | 282 mSecondaryButton.setText(secondaryText); |
268 secondaryButton.setTextColor(mAccentColor); | 283 mSecondaryButton.setTextColor(mAccentColor); |
269 | 284 |
270 if (TextUtils.isEmpty(tertiaryText)) { | 285 if (TextUtils.isEmpty(tertiaryText)) return; |
271 mButtonGroup = addGroup(secondaryButton, primaryButton); | |
272 return; | |
273 } | |
274 | 286 |
275 Button tertiaryButton = (Button) inflater.inflate(R.layout.infobar_butto
n, null); | 287 mTertiaryButton = ButtonCompat.createBorderlessButton(getContext()); |
276 tertiaryButton.setId(R.id.button_tertiary); | 288 mTertiaryButton.setId(R.id.button_tertiary); |
277 tertiaryButton.setOnClickListener(this); | 289 mTertiaryButton.setOnClickListener(this); |
278 tertiaryButton.setText(tertiaryText); | 290 mTertiaryButton.setText(tertiaryText); |
279 tertiaryButton.setPadding(mMargin / 2, tertiaryButton.getPaddingTop(), m
Margin / 2, | 291 mTertiaryButton.setPadding(mMargin / 2, mTertiaryButton.getPaddingTop(),
mMargin / 2, |
280 tertiaryButton.getPaddingBottom()); | 292 mTertiaryButton.getPaddingBottom()); |
281 tertiaryButton.setTextColor( | 293 mTertiaryButton.setTextColor( |
282 getContext().getResources().getColor(R.color.infobar_tertiary_bu
tton_text)); | 294 getContext().getResources().getColor(R.color.infobar_tertiary_bu
tton_text)); |
283 | |
284 mButtonGroup = addGroup(tertiaryButton, secondaryButton, primaryButton); | |
285 } | 295 } |
286 | 296 |
287 /** | 297 /** |
288 * Adds a group of Views that are measured and laid out together. | 298 * Adds a custom view to show in the button row in place of the tertiary but
ton. |
289 */ | 299 */ |
290 private Group addGroup(View... views) { | 300 public void setCustomViewInButtonRow(View view) { |
291 Group group = new Group(); | 301 mCustomButton = view; |
292 group.views = views; | 302 } |
293 | 303 |
294 for (View v : views) { | 304 /** |
295 addView(v); | 305 * Sets the size of the icon and the spacing between it and the message. |
| 306 */ |
| 307 public void setIconSizeAndSpacing(int width, int height, int iconMessageSpac
ing) { |
| 308 LayoutParams lp = (LayoutParams) mIconView.getLayoutParams(); |
| 309 lp.width = width; |
| 310 lp.height = height; |
| 311 lp.endMargin = iconMessageSpacing; |
| 312 } |
| 313 |
| 314 |
| 315 /** |
| 316 * Returns the primary button, or null if it doesn't exist. |
| 317 */ |
| 318 public ButtonCompat getPrimaryButton() { |
| 319 return mPrimaryButton; |
| 320 } |
| 321 |
| 322 /** |
| 323 * Returns the icon, or null if it doesn't exist. |
| 324 */ |
| 325 public ImageView getIcon() { |
| 326 return mIconView; |
| 327 } |
| 328 |
| 329 /** |
| 330 * Must be called after the message, buttons, and custom content have been s
et, and before the |
| 331 * first call to onMeasure(). |
| 332 */ |
| 333 void onContentCreated() { |
| 334 mMessageView.setLayoutParams(new LayoutParams(0, mMargin / 4, 0, 0)); |
| 335 mMainGroup = new Group(Group.filterNullViews(mIconView, mMessageView)); |
| 336 |
| 337 View[] buttons = Group.filterNullViews(mCustomButton, mTertiaryButton, |
| 338 mSecondaryButton, mPrimaryButton); |
| 339 if (buttons.length != 0) mButtonGroup = new Group(buttons); |
| 340 |
| 341 // Add the child views in the desired focus order. |
| 342 for (View v : mMainGroup.views) addView(v); |
| 343 if (mCustomGroup != null) { |
| 344 for (View v : mCustomGroup.views) addView(v); |
296 } | 345 } |
297 return group; | 346 if (mButtonGroup != null) { |
| 347 for (View v : mButtonGroup.views) addView(v); |
| 348 } |
| 349 addView(mCloseButton); |
298 } | 350 } |
299 | 351 |
300 @Override | 352 @Override |
301 protected LayoutParams generateDefaultLayoutParams() { | 353 protected LayoutParams generateDefaultLayoutParams() { |
302 return new LayoutParams(0, 0, 0, 0); | 354 return new LayoutParams(0, 0, 0, 0); |
303 } | 355 } |
304 | 356 |
305 @Override | 357 @Override |
306 protected void onLayout(boolean changed, int left, int top, int right, int b
ottom) { | 358 protected void onLayout(boolean changed, int left, int top, int right, int b
ottom) { |
307 // Place all the views in the positions already determined during onMeas
ure(). | 359 // Place all the views in the positions already determined during onMeas
ure(). |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 placeGroup(mCustomGroup); | 439 placeGroup(mCustomGroup); |
388 } | 440 } |
389 | 441 |
390 if (mButtonGroup != null) { | 442 if (mButtonGroup != null) { |
391 if (!buttonGroupOnMainRow) { | 443 if (!buttonGroupOnMainRow) { |
392 startRow(); | 444 startRow(); |
393 updateButtonGroupForRow(ROW_OTHER); | 445 updateButtonGroupForRow(ROW_OTHER); |
394 | 446 |
395 // If the infobar consists of just a main row and a buttons row,
the buttons must be | 447 // If the infobar consists of just a main row and a buttons row,
the buttons must be |
396 // at least 32dp below the bottom of the message text. | 448 // at least 32dp below the bottom of the message text. |
397 if (mCustomGroup == null) { | 449 if (mCustomGroup == null && mMessageTextView != null) { |
398 LayoutParams lp = (LayoutParams) mMessageView.getLayoutParam
s(); | 450 LayoutParams lp = (LayoutParams) mMessageTextView.getLayoutP
arams(); |
399 int messageBottom = lp.top + mMessageView.getMeasuredHeight(
); | 451 int messageBottom = lp.top + mMessageTextView.getMeasuredHei
ght(); |
400 mTop = Math.max(mTop, messageBottom + 2 * mMargin); | 452 mTop = Math.max(mTop, messageBottom + 2 * mMargin); |
401 } | 453 } |
402 } | 454 } |
403 placeGroup(mButtonGroup); | 455 placeGroup(mButtonGroup); |
| 456 |
| 457 if (mCustomButton != null && !buttonGroupOnMainRow) { |
| 458 // The custom button is start-aligned with the message view (unl
ess that causes it |
| 459 // to overlap the primary button). |
| 460 LayoutParams primaryButtonLP = (LayoutParams) mPrimaryButton.get
LayoutParams(); |
| 461 LayoutParams customButtonLP = (LayoutParams) mCustomButton.getLa
youtParams(); |
| 462 LayoutParams messageLP = (LayoutParams) mMessageView.getLayoutPa
rams(); |
| 463 if (customButtonLP.start >= messageLP.start) { |
| 464 customButtonLP.start = messageLP.start; |
| 465 } else { |
| 466 customButtonLP.start = mMargin; |
| 467 } |
| 468 if (!mButtonGroup.isStacked) { |
| 469 // Center the custom button vertically relative to the prima
ry button. |
| 470 customButtonLP.top = primaryButtonLP.top |
| 471 + (mPrimaryButton.getMeasuredHeight() |
| 472 - mCustomButton.getMeasuredHeight()) / 2; |
| 473 } |
| 474 } |
404 } | 475 } |
405 | 476 |
406 startRow(); | 477 startRow(); |
407 | 478 |
408 // If everything fits on a single row, center everything vertically. | 479 // If everything fits on a single row, center everything vertically. |
409 if (buttonGroupOnMainRow) { | 480 if (buttonGroupOnMainRow) { |
410 int layoutHeight = mBottom; | 481 int layoutHeight = mBottom; |
411 for (int i = 0; i < getChildCount(); i++) { | 482 for (int i = 0; i < getChildCount(); i++) { |
412 View child = getChildAt(i); | 483 View child = getChildAt(i); |
413 int extraSpace = layoutHeight - child.getMeasuredHeight(); | 484 int extraSpace = layoutHeight - child.getMeasuredHeight(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 int startEndMargin = row == ROW_MAIN ? mMargin : 0; | 581 int startEndMargin = row == ROW_MAIN ? mMargin : 0; |
511 mButtonGroup.setHorizontalMode(mMargin / 2, startEndMargin, startEndMarg
in); | 582 mButtonGroup.setHorizontalMode(mMargin / 2, startEndMargin, startEndMarg
in); |
512 mButtonGroup.gravity = Gravity.END; | 583 mButtonGroup.gravity = Gravity.END; |
513 | 584 |
514 if (row == ROW_OTHER && mButtonGroup.views.length >= 2) { | 585 if (row == ROW_OTHER && mButtonGroup.views.length >= 2) { |
515 int extraWidth = availableWidth() - getWidthWithMargins(mButtonGroup
); | 586 int extraWidth = availableWidth() - getWidthWithMargins(mButtonGroup
); |
516 if (extraWidth < 0) { | 587 if (extraWidth < 0) { |
517 // Group is too wide to fit on a single row, so stack the group
items vertically. | 588 // Group is too wide to fit on a single row, so stack the group
items vertically. |
518 mButtonGroup.setVerticalMode(mMargin / 2, 0); | 589 mButtonGroup.setVerticalMode(mMargin / 2, 0); |
519 mButtonGroup.gravity = Gravity.FILL_HORIZONTAL; | 590 mButtonGroup.gravity = Gravity.FILL_HORIZONTAL; |
520 } else if (mButtonGroup.views.length == 3) { | 591 } else if (mTertiaryButton != null) { |
521 // Align tertiary button at the start and the other two buttons
at the end. | 592 // Align tertiary or custom button at the start and the other bu
ttons at the end. |
522 ((LayoutParams) mButtonGroup.views[0].getLayoutParams()).endMarg
in += extraWidth; | 593 ((LayoutParams) mTertiaryButton.getLayoutParams()).endMargin +=
extraWidth; |
523 } | 594 } |
524 } | 595 } |
| 596 if (row == ROW_MAIN && mCustomButton != null) { |
| 597 // Increase spacing between custom button and primary button. |
| 598 ((LayoutParams) mCustomButton.getLayoutParams()).endMargin = mMargin
; |
| 599 } |
525 } | 600 } |
526 | 601 |
527 /** | 602 /** |
528 * Analagous to updateButtonGroupForRow(), but for the custom group istead o
f the button group. | 603 * Analagous to updateButtonGroupForRow(), but for the custom group istead o
f the button group. |
529 */ | 604 */ |
530 private void updateCustomGroupForRow(int row) { | 605 private void updateCustomGroupForRow(int row) { |
531 int startEndMargin = row == ROW_MAIN ? mMargin : 0; | 606 int startEndMargin = row == ROW_MAIN ? mMargin : 0; |
532 mCustomGroup.setHorizontalMode(mMargin, startEndMargin, startEndMargin); | 607 mCustomGroup.setHorizontalMode(mMargin, startEndMargin, startEndMargin); |
533 mCustomGroup.gravity = Gravity.START; | 608 mCustomGroup.gravity = Gravity.START; |
534 | 609 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 mInfoBarView.onCloseButtonClicked(); | 642 mInfoBarView.onCloseButtonClicked(); |
568 } else if (view.getId() == R.id.button_primary) { | 643 } else if (view.getId() == R.id.button_primary) { |
569 mInfoBarView.onButtonClicked(true); | 644 mInfoBarView.onButtonClicked(true); |
570 } else if (view.getId() == R.id.button_secondary) { | 645 } else if (view.getId() == R.id.button_secondary) { |
571 mInfoBarView.onButtonClicked(false); | 646 mInfoBarView.onButtonClicked(false); |
572 } else if (view.getId() == R.id.button_tertiary) { | 647 } else if (view.getId() == R.id.button_tertiary) { |
573 mInfoBarView.onLinkClicked(); | 648 mInfoBarView.onLinkClicked(); |
574 } | 649 } |
575 } | 650 } |
576 } | 651 } |
OLD | NEW |