Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.payments.ui; | |
| 6 | |
| 7 import android.content.Context; | |
| 8 import android.util.AttributeSet; | |
| 9 import android.view.View; | |
| 10 import android.view.View.MeasureSpec; | |
| 11 import android.widget.LinearLayout; | |
| 12 | |
| 13 import org.chromium.chrome.R; | |
| 14 | |
| 15 /** This class represents a bar to display at the bottom of the payment request UI. */ | |
| 16 public class PaymentRequestBottomBar extends LinearLayout { | |
| 17 public PaymentRequestBottomBar(Context context, AttributeSet attrs) { | |
| 18 super(context, attrs); | |
| 19 } | |
| 20 | |
| 21 @Override | |
| 22 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
| 23 // Views layout_width must be set to match_parent. | |
| 24 assert MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; | |
| 25 | |
| 26 View logoWithName = findViewById(R.id.logo_name); | |
|
gone
2017/02/17 23:17:10
Cache the views in onFinishInflate() so you're not
gogerald1
2017/02/20 15:18:36
Done.
| |
| 27 measureChild(logoWithName, widthMeasureSpec, heightMeasureSpec); | |
| 28 int logoWithNameWidth = logoWithName.getMeasuredWidth(); | |
| 29 | |
| 30 View logo = findViewById(R.id.logo); | |
| 31 measureChild(logo, widthMeasureSpec, heightMeasureSpec); | |
| 32 int logoWidth = logo.getMeasuredWidth(); | |
| 33 | |
| 34 View primaryButton = findViewById(R.id.button_primary); | |
| 35 measureChild(primaryButton, widthMeasureSpec, heightMeasureSpec); | |
| 36 int primaryButtonWidth = primaryButton.getMeasuredWidth(); | |
| 37 | |
| 38 View secondaryButton = findViewById(R.id.button_secondary); | |
| 39 measureChild(secondaryButton, widthMeasureSpec, heightMeasureSpec); | |
| 40 int secondaryButtonWidth = secondaryButton.getMeasuredWidth(); | |
| 41 | |
| 42 int blankSpaceWidth = 0; | |
| 43 int totolWidth = MeasureSpec.getSize(widthMeasureSpec); | |
|
gone
2017/02/17 23:17:11
totalWidth
gogerald1
2017/02/20 15:18:36
Done.
| |
| 44 int widthWithoutLogo = | |
| 45 primaryButtonWidth + secondaryButtonWidth + getPaddingLeft() + g etPaddingRight(); | |
|
gone
2017/02/17 23:17:11
This calculation doesn't account for the margins d
gogerald1
2017/02/20 15:18:36
Done.
| |
| 46 if (widthWithoutLogo + logoWithNameWidth <= totolWidth) { | |
| 47 logo.setVisibility(View.GONE); | |
| 48 logoWithName.setVisibility(View.VISIBLE); | |
| 49 blankSpaceWidth = totolWidth - widthWithoutLogo - logoWithNameWidth; | |
| 50 } else if (widthWithoutLogo + logoWidth <= totolWidth) { | |
| 51 logo.setVisibility(View.VISIBLE); | |
| 52 logoWithName.setVisibility(View.GONE); | |
| 53 blankSpaceWidth = totolWidth - widthWithoutLogo - logoWidth; | |
| 54 } else { | |
| 55 logoWithName.setVisibility(View.GONE); | |
| 56 logo.setVisibility(View.GONE); | |
| 57 blankSpaceWidth = totolWidth - widthWithoutLogo; | |
| 58 assert false | |
| 59 : "Screen width is expected to fit the two buttons plus the logo at least."; | |
|
gone
2017/02/17 23:17:11
1) Asserting here isn't helpful; the fallback case
gogerald1
2017/02/20 15:18:36
Done. Thought negative would be considered as zero
| |
| 60 } | |
| 61 | |
| 62 // Sets the space width. | |
| 63 View space = findViewById(R.id.space); | |
| 64 space.getLayoutParams().width = blankSpaceWidth; | |
| 65 measureChild(space, MeasureSpec.makeMeasureSpec(blankSpaceWidth, Measure Spec.EXACTLY), | |
| 66 heightMeasureSpec); | |
| 67 | |
| 68 // Note that logoWithName and logo must have the same height. | |
| 69 int measuredHeight = getPaddingTop() + getPaddingBottom() | |
| 70 + Math.max(logoWithName.getMeasuredHeight(), | |
|
gone
2017/02/17 23:17:11
Pull out the max height calculation. The indentat
gogerald1
2017/02/20 15:18:36
Done.
| |
| 71 Math.max(primaryButton.getMeasuredHeight(), | |
| 72 secondaryButton.getMeasuredHeight())); | |
| 73 int measuredHeightSpec = MeasureSpec.makeMeasureSpec(measuredHeight, Mea sureSpec.EXACTLY); | |
| 74 setMeasuredDimension(widthMeasureSpec, measuredHeightSpec); | |
| 75 } | |
| 76 } | |
| OLD | NEW |