 Chromium Code Reviews
 Chromium Code Reviews Issue 2698703003:
  [Payments] Add UI elements to secure branding for payments  (Closed)
    
  
    Issue 2698703003:
  [Payments] Add UI elements to secure branding for payments  (Closed) 
  | Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestBottomBar.java | 
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestBottomBar.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestBottomBar.java | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..63c6fda0d99da1985546664dcb598bdc2b6cdb92 | 
| --- /dev/null | 
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestBottomBar.java | 
| @@ -0,0 +1,76 @@ | 
| +// Copyright 2017 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +package org.chromium.chrome.browser.payments.ui; | 
| + | 
| +import android.content.Context; | 
| +import android.util.AttributeSet; | 
| +import android.view.View; | 
| +import android.view.View.MeasureSpec; | 
| +import android.widget.LinearLayout; | 
| + | 
| +import org.chromium.chrome.R; | 
| + | 
| +/** This class represents a bar to display at the bottom of the payment request UI. */ | 
| +public class PaymentRequestBottomBar extends LinearLayout { | 
| + public PaymentRequestBottomBar(Context context, AttributeSet attrs) { | 
| + super(context, attrs); | 
| + } | 
| + | 
| + @Override | 
| + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 
| + // Views layout_width must be set to match_parent. | 
| + assert MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY; | 
| + | 
| + 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.
 | 
| + measureChild(logoWithName, widthMeasureSpec, heightMeasureSpec); | 
| + int logoWithNameWidth = logoWithName.getMeasuredWidth(); | 
| + | 
| + View logo = findViewById(R.id.logo); | 
| + measureChild(logo, widthMeasureSpec, heightMeasureSpec); | 
| + int logoWidth = logo.getMeasuredWidth(); | 
| + | 
| + View primaryButton = findViewById(R.id.button_primary); | 
| + measureChild(primaryButton, widthMeasureSpec, heightMeasureSpec); | 
| + int primaryButtonWidth = primaryButton.getMeasuredWidth(); | 
| + | 
| + View secondaryButton = findViewById(R.id.button_secondary); | 
| + measureChild(secondaryButton, widthMeasureSpec, heightMeasureSpec); | 
| + int secondaryButtonWidth = secondaryButton.getMeasuredWidth(); | 
| + | 
| + int blankSpaceWidth = 0; | 
| + int totolWidth = MeasureSpec.getSize(widthMeasureSpec); | 
| 
gone
2017/02/17 23:17:11
totalWidth
 
gogerald1
2017/02/20 15:18:36
Done.
 | 
| + int widthWithoutLogo = | 
| + primaryButtonWidth + secondaryButtonWidth + getPaddingLeft() + getPaddingRight(); | 
| 
gone
2017/02/17 23:17:11
This calculation doesn't account for the margins d
 
gogerald1
2017/02/20 15:18:36
Done.
 | 
| + if (widthWithoutLogo + logoWithNameWidth <= totolWidth) { | 
| + logo.setVisibility(View.GONE); | 
| + logoWithName.setVisibility(View.VISIBLE); | 
| + blankSpaceWidth = totolWidth - widthWithoutLogo - logoWithNameWidth; | 
| + } else if (widthWithoutLogo + logoWidth <= totolWidth) { | 
| + logo.setVisibility(View.VISIBLE); | 
| + logoWithName.setVisibility(View.GONE); | 
| + blankSpaceWidth = totolWidth - widthWithoutLogo - logoWidth; | 
| + } else { | 
| + logoWithName.setVisibility(View.GONE); | 
| + logo.setVisibility(View.GONE); | 
| + blankSpaceWidth = totolWidth - widthWithoutLogo; | 
| + assert false | 
| + : "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
 | 
| + } | 
| + | 
| + // Sets the space width. | 
| + View space = findViewById(R.id.space); | 
| + space.getLayoutParams().width = blankSpaceWidth; | 
| + measureChild(space, MeasureSpec.makeMeasureSpec(blankSpaceWidth, MeasureSpec.EXACTLY), | 
| + heightMeasureSpec); | 
| + | 
| + // Note that logoWithName and logo must have the same height. | 
| + int measuredHeight = getPaddingTop() + getPaddingBottom() | 
| + + 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.
 | 
| + Math.max(primaryButton.getMeasuredHeight(), | 
| + secondaryButton.getMeasuredHeight())); | 
| + int measuredHeightSpec = MeasureSpec.makeMeasureSpec(measuredHeight, MeasureSpec.EXACTLY); | 
| + setMeasuredDimension(widthMeasureSpec, measuredHeightSpec); | 
| + } | 
| +} |