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.graphics.Bitmap; | |
9 import android.text.Spannable; | |
10 import android.text.SpannableString; | |
11 import android.text.style.ForegroundColorSpan; | |
12 import android.util.AttributeSet; | |
13 import android.widget.FrameLayout; | |
14 import android.widget.ImageView; | |
15 import android.widget.TextView; | |
16 | |
17 import org.chromium.base.ApiCompatibilityUtils; | |
18 import org.chromium.chrome.R; | |
19 import org.chromium.chrome.browser.UrlConstants; | |
20 import org.chromium.chrome.browser.widget.TintedDrawable; | |
21 | |
22 /** This class represents a bar to display at the top of the payment request UI. */ | |
23 public class PaymentRequestHeader extends FrameLayout { | |
24 private Context mContext; | |
25 | |
26 public PaymentRequestHeader(Context context, AttributeSet attrs) { | |
27 super(context, attrs); | |
28 mContext = context; | |
29 } | |
30 | |
31 /** | |
32 * Sets the bitmap of the icon on the left of the header. | |
33 * | |
34 * @param bitmap The bitmap to display. | |
35 */ | |
36 public void setTitleBitmap(Bitmap bitmap) { | |
37 ((ImageView) findViewById(R.id.icon_view)).setImageBitmap(bitmap); | |
38 } | |
39 | |
40 /** | |
41 * Sets the title and origin on the header. | |
42 * | |
43 * @param title The title to display on the header. | |
44 * @param origin The origin to display on the header. | |
45 */ | |
46 public void setTitleAndOrigin(String title, String origin) { | |
47 ((TextView) findViewById(R.id.page_title)).setText(title); | |
48 | |
49 TextView hostName = (TextView) findViewById(R.id.hostname); | |
50 if (origin.startsWith(UrlConstants.HTTPS_URL_PREFIX)) { | |
51 // Tint https scheme and add compound drawable for security display. | |
52 hostName.setText(tintUrlSchemeForSecurityDisplay(origin)); | |
53 ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBound s(hostName, | |
54 TintedDrawable.constructTintedDrawable(mContext.getResources (), | |
55 R.drawable.omnibox_https_valid, R.color.google_green _700), | |
56 null, null, null); | |
57 | |
58 // Remove left padding to align left compound drawable with the titl e. Note that the | |
59 // left compound drawable has transparent boundary. | |
60 hostName.setPaddingRelative(0, 0, 0, 0); | |
61 } else { | |
62 hostName.setText(origin); | |
63 } | |
64 } | |
65 | |
66 private CharSequence tintUrlSchemeForSecurityDisplay(String uri) { | |
67 SpannableString spannableUri = new SpannableString(uri); | |
68 int color = | |
69 ApiCompatibilityUtils.getColor(mContext.getResources(), R.color. google_green_700); | |
70 spannableUri.setSpan(new ForegroundColorSpan(color), 0, | |
71 spannableUri.toString().indexOf(":"), Spannable.SPAN_EXCLUSIVE_E XCLUSIVE); | |
gone
2017/02/17 01:53:54
Shouldn't this be INCLUSIVE_EXCLUSIVE?
gogerald1
2017/02/17 17:28:28
I think SPAN_EXCLUSIVE_EXCLUSIVE is better since w
| |
72 return spannableUri; | |
73 } | |
74 } | |
OLD | NEW |