Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.payments.ui; | 5 package org.chromium.chrome.browser.payments.ui; |
| 6 | 6 |
| 7 import android.graphics.drawable.Drawable; | |
| 8 | |
| 7 import javax.annotation.Nullable; | 9 import javax.annotation.Nullable; |
| 8 | 10 |
| 9 /** | 11 /** |
| 10 * An option that the user can select, e.g., a shipping option, a shipping addre ss, or a payment | 12 * An option that the user can select, e.g., a shipping option, a shipping addre ss, or a payment |
| 11 * method. | 13 * method. |
| 12 */ | 14 */ |
| 13 public class PaymentOption implements Completable { | 15 public class PaymentOption implements Completable { |
| 14 /** The placeholder value that indicates the absence of an icon for this opt ion. */ | |
| 15 public static final int NO_ICON = 0; | |
| 16 | |
| 17 protected boolean mIsComplete; | 16 protected boolean mIsComplete; |
| 18 private String mId; | 17 private String mId; |
| 19 private int mIcon; | 18 private Drawable mIcon; |
| 20 private String[] mLabels = {null, null, null}; | 19 private String[] mLabels = {null, null, null}; |
| 21 private boolean mIsValid = true; | 20 private boolean mIsValid = true; |
| 22 | 21 |
| 23 /** See {@link #PaymentOption(String, String, String, String, int)}. */ | 22 /** See {@link #PaymentOption(String, String, String, String, int)}. */ |
| 24 public PaymentOption(String id, @Nullable String label, @Nullable String sub label, int icon) { | 23 public PaymentOption(String id, @Nullable String label, @Nullable String sub label, |
| 24 @Nullable Drawable icon) { | |
| 25 this(id, label, sublabel, null, icon); | 25 this(id, label, sublabel, null, icon); |
| 26 } | 26 } |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * Constructs a payment option. | 29 * Constructs a payment option. |
| 30 * | 30 * |
| 31 * @param id The identifier. | 31 * @param id The identifier. |
| 32 * @param label The label. | 32 * @param label The label. |
| 33 * @param sublabel The optional sublabel. | 33 * @param sublabel The optional sublabel. |
| 34 * @param tertiarylabel The optional tertiary label. | 34 * @param tertiarylabel The optional tertiary label. |
| 35 * @param icon The drawable icon identifier or NO_ICON. | 35 * @param icon The drawable icon identifier or null. |
| 36 */ | 36 */ |
| 37 public PaymentOption(String id, @Nullable String label, @Nullable String sub label, | 37 public PaymentOption(String id, @Nullable String label, @Nullable String sub label, |
| 38 @Nullable String tertiarylabel, int icon) { | 38 @Nullable String tertiarylabel, @Nullable Drawable icon) { |
| 39 updateIdentifierLabelsAndIcon(id, label, sublabel, tertiarylabel, icon); | 39 updateIdentifierLabelsAndIcon(id, label, sublabel, tertiarylabel, icon); |
| 40 } | 40 } |
| 41 | 41 |
| 42 @Override | 42 @Override |
| 43 public boolean isComplete() { | 43 public boolean isComplete() { |
| 44 return mIsComplete; | 44 return mIsComplete; |
| 45 } | 45 } |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * The non-human readable identifier for this option. For example, "standard _shipping" or the | 48 * The non-human readable identifier for this option. For example, "standard _shipping" or the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 } | 88 } |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Updates the identifier, labels, and icon of this option. Called after the user has | 91 * Updates the identifier, labels, and icon of this option. Called after the user has |
| 92 * edited this option. | 92 * edited this option. |
| 93 * | 93 * |
| 94 * @param id The new id to use. Should not be null. | 94 * @param id The new id to use. Should not be null. |
| 95 * @param label The new label to use. Should not be null. | 95 * @param label The new label to use. Should not be null. |
| 96 * @param sublabel The new sublabel to use. Can be null. | 96 * @param sublabel The new sublabel to use. Can be null. |
| 97 * @param tertiarylabel The new tertiary label to use. Can be null. | 97 * @param tertiarylabel The new tertiary label to use. Can be null. |
| 98 * @param icon The drawable icon identifier or NO_ICON. | 98 * @param icon The drawable icon identifier or null. |
| 99 */ | 99 */ |
| 100 protected void updateIdentifierLabelsAndIcon( | 100 protected void updateIdentifierLabelsAndIcon( |
| 101 String id, String label, @Nullable String sublabel, @Nullable String tertiarylabel, | 101 String id, String label, @Nullable String sublabel, @Nullable String tertiarylabel, |
| 102 int icon) { | 102 @Nullable Drawable icon) { |
| 103 updateIdentifierAndLabels(id, label, sublabel, tertiarylabel); | 103 updateIdentifierAndLabels(id, label, sublabel, tertiarylabel); |
| 104 mIcon = icon; | 104 mIcon = icon; |
| 105 } | 105 } |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * The identifier for the drawable icon for this payment option. For example , R.drawable.pr_visa | 108 * The drawable icon for this payment option. |
| 109 * or NO_ICON. | |
| 110 */ | 109 */ |
|
please use gerrit instead
2016/10/20 15:22:18
This comment is short enough to collapse into a si
| |
| 111 public int getDrawableIconId() { | 110 public Drawable getDrawableIcon() { |
| 112 return mIcon; | 111 return mIcon; |
| 113 } | 112 } |
| 114 | 113 |
| 115 /** | 114 /** |
| 116 * Marks this option as invalid. For example, this can be a shipping address that's not served | 115 * Marks this option as invalid. For example, this can be a shipping address that's not served |
| 117 * by the merchant. | 116 * by the merchant. |
| 118 */ | 117 */ |
| 119 public void setInvalid() { | 118 public void setInvalid() { |
| 120 mIsValid = false; | 119 mIsValid = false; |
| 121 } | 120 } |
| 122 | 121 |
| 123 /** @return True if this option is valid. */ | 122 /** @return True if this option is valid. */ |
| 124 public boolean isValid() { | 123 public boolean isValid() { |
| 125 return mIsValid; | 124 return mIsValid; |
| 126 } | 125 } |
| 127 } | 126 } |
| OLD | NEW |