Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorFieldModel.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorFieldModel.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorFieldModel.java |
| index 12c3693194de95d2870ab011ddf896a634288434..56d1bf8f0eb3283942caffa134d5d5c3ffd9930b 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorFieldModel.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorFieldModel.java |
| @@ -34,6 +34,8 @@ public class EditorFieldModel { |
| boolean isValid(@Nullable CharSequence value); |
| } |
| + private static final int INPUT_TYPE_HINT_MIN_INCLUSIVE = 0; |
| + |
| /** Indicates a phone field. */ |
| public static final int INPUT_TYPE_HINT_PHONE = 1; |
| @@ -52,35 +54,126 @@ public class EditorFieldModel { |
| /** Indicates an alpha-numeric value, e.g., postal code or sorting code. */ |
| public static final int INPUT_TYPE_HINT_ALPHA_NUMERIC = 6; |
| + /** Indicates a credit card input. */ |
| + public static final int INPUT_TYPE_HINT_CREDIT_CARD = 7; |
| + |
| + private static final int INPUT_TYPE_HINT_MAX_TEXT_INPUT_EXCLUSIVE = 8; |
| + |
| /** Indicates a dropdown. */ |
| - public static final int INPUT_TYPE_HINT_DROPDOWN = 7; |
| + public static final int INPUT_TYPE_HINT_DROPDOWN = 9; |
| + |
| + /** Indicates a list of icons. */ |
| + public static final int INPUT_TYPE_HINT_ICONS = 10; |
| + |
| + /** Indicates a checkbox. */ |
| + public static final int INPUT_TYPE_HINT_CHECKBOX = 11; |
| + |
| + /** |
| + * Indicates a label, e.g., for a server credit card. |
| + * |
| + * LABEL |
| + * MID_LABEL [ICON] |
| + * SUB_LABEL |
| + * |
| + * Example: |
| + * |
| + * Visa***1234 |
| + * Sunee Song [VISA] |
| + * Exp. 03/21 |
| + */ |
| + public static final int INPUT_TYPE_HINT_LABEL = 12; |
| + |
| + private static final int INPUT_TYPE_HINT_MAX_EXCLUSIVE = 13; |
| private final int mInputTypeHint; |
| - @Nullable private final List<DropdownKeyValue> mDropdownKeyValues; |
| - @Nullable private final List<CharSequence> mSuggestions; |
| - @Nullable private final EditorFieldValidator mValidator; |
| - @Nullable private final CharSequence mInvalidErrorMessage; |
| - @Nullable private CharSequence mLabel; |
| + |
| + @Nullable private List<Integer> mIconResourceIds; |
| + @Nullable private List<Integer> mIconDescriptionsForAccessibility; |
| + @Nullable private List<DropdownKeyValue> mDropdownKeyValues; |
| + @Nullable private List<CharSequence> mSuggestions; |
| + @Nullable private EditorFieldValidator mValidator; |
| @Nullable private CharSequence mRequiredErrorMessage; |
| + @Nullable private CharSequence mInvalidErrorMessage; |
| @Nullable private CharSequence mErrorMessage; |
| + @Nullable private CharSequence mLabel; |
| + @Nullable private CharSequence mMidLabel; |
| + @Nullable private CharSequence mSubLabel; |
| @Nullable private CharSequence mValue; |
| @Nullable private Callback<Pair<String, Runnable>> mDropdownCallback; |
| + private int mLabelIconResourceId; |
| + private boolean mIsChecked = false; |
| private boolean mIsFullLine = true; |
| /** |
| + * Constructs a label to show in the editor. This can be, for example, description of a server |
| + * credit card and its icon. |
| + * |
| + * @param label Label. |
|
gone
2016/07/13 21:13:00
top label, middle label, bottom label? sub implie
please use gerrit instead
2016/07/14 17:21:44
Done.
|
| + * @param midLabel Mid label. |
| + * @param subLabel Sub label. |
| + * @param iconId Icon. |
| + */ |
| + public static EditorFieldModel createLabel( |
| + CharSequence label, CharSequence midLabel, CharSequence subLabel, int iconId) { |
| + assert label != null; |
| + assert midLabel != null; |
| + assert subLabel != null; |
| + EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_LABEL); |
| + result.mLabel = label; |
| + result.mMidLabel = midLabel; |
| + result.mSubLabel = subLabel; |
| + result.mLabelIconResourceId = iconId; |
| + return result; |
| + } |
| + |
| + /** |
| + * Constructs a checkbox to show in the editor. It's unchecked by default. |
| + * |
| + * @param checkboxLabel The label for the checkbox. |
| + */ |
| + public static EditorFieldModel createCheckbox(CharSequence checkboxLabel) { |
| + assert checkboxLabel != null; |
| + EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_CHECKBOX); |
| + result.mLabel = checkboxLabel; |
| + return result; |
| + } |
| + |
| + /** |
| + * Constructs a list of icons to show in the editor. This can be, for example, the list of |
| + * accepted credit cards. |
| + * |
| + * @param label The label for the icons. |
| + * @param iconIds The list of drawable resources to display, in this order. |
| + * @param descIds The list of string identifiers for descriptions of the icons. This is for |
| + * accessibility. |
| + */ |
| + public static EditorFieldModel createIconList(CharSequence label, List<Integer> iconIds, |
| + List<Integer> descIds) { |
| + assert label != null; |
| + assert iconIds != null; |
| + assert descIds != null; |
| + EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_ICONS); |
| + result.mLabel = label; |
| + result.mIconResourceIds = iconIds; |
| + result.mIconDescriptionsForAccessibility = descIds; |
| + return result; |
| + } |
| + |
| + /** |
| * Constructs a dropdown field model. |
| * |
| * @param label The human-readable label for user to understand the type of data |
| * that should be entered into this field. |
| * @param dropdownKeyValues The keyed values to display in the dropdown. |
| */ |
| - public EditorFieldModel(CharSequence label, List<DropdownKeyValue> dropdownKeyValues) { |
| - mInputTypeHint = INPUT_TYPE_HINT_DROPDOWN; |
| - mDropdownKeyValues = dropdownKeyValues; |
| - mSuggestions = null; |
| - mValidator = null; |
| - mInvalidErrorMessage = null; |
| - mLabel = label; |
| + public static EditorFieldModel createDropdown( |
| + CharSequence label, List<DropdownKeyValue> dropdownKeyValues) { |
| + assert label != null; |
| + assert dropdownKeyValues != null; |
| + EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_DROPDOWN); |
| + result.mLabel = label; |
| + result.mDropdownKeyValues = dropdownKeyValues; |
| + return result; |
| } |
| /** |
| @@ -88,14 +181,9 @@ public class EditorFieldModel { |
| * |
| * @param inputTypeHint The type of input. For example, INPUT_TYPE_HINT_PHONE. |
| */ |
| - public EditorFieldModel(int inputTypeHint) { |
| - assert inputTypeHint != INPUT_TYPE_HINT_DROPDOWN; |
| - mInputTypeHint = inputTypeHint; |
| - mDropdownKeyValues = null; |
| - mSuggestions = null; |
| - mValidator = null; |
| - mInvalidErrorMessage = null; |
| - mLabel = null; |
| + public static EditorFieldModel createTextInput(int inputTypeHint) { |
| + assert inputTypeHint >= 0 && inputTypeHint <= INPUT_TYPE_HINT_CREDIT_CARD; |
| + return new EditorFieldModel(inputTypeHint); |
| } |
| /** |
| @@ -104,7 +192,7 @@ public class EditorFieldModel { |
| * @param inputTypeHint The type of input. For example, INPUT_TYPE_HINT_PHONE. |
| * @param label The human-readable label for user to understand the type of data |
| * that should be entered into this field. |
| - * @param suggestions Optionally empty set of values to suggest to the user. |
| + * @param suggestions Optional set of values to suggest to the user. |
| * @param validator Optional validator for the values in this field. |
| * @param requiredErrorMessage The optional error message that indicates to the user that they |
| * cannot leave this field empty. |
| @@ -112,20 +200,27 @@ public class EditorFieldModel { |
| * value they have entered is not valid. |
| * @param value Optional initial value of this field. |
| */ |
| - public EditorFieldModel(int inputTypeHint, CharSequence label, |
| - Set<CharSequence> suggestions, @Nullable EditorFieldValidator validator, |
| + public static EditorFieldModel createTextInput(int inputTypeHint, CharSequence label, |
| + @Nullable Set<CharSequence> suggestions, @Nullable EditorFieldValidator validator, |
| @Nullable CharSequence requiredErrorMessage, @Nullable CharSequence invalidErrorMessage, |
| @Nullable CharSequence value) { |
| - assert inputTypeHint != INPUT_TYPE_HINT_DROPDOWN; |
| - assert suggestions != null; |
| + assert inputTypeHint >= INPUT_TYPE_HINT_MIN_INCLUSIVE; |
| + assert inputTypeHint < INPUT_TYPE_HINT_MAX_TEXT_INPUT_EXCLUSIVE; |
| + assert label != null; |
| + EditorFieldModel result = new EditorFieldModel(inputTypeHint); |
| + result.mSuggestions = suggestions == null ? null : new ArrayList<CharSequence>(suggestions); |
| + result.mValidator = validator; |
| + result.mInvalidErrorMessage = invalidErrorMessage; |
| + result.mRequiredErrorMessage = requiredErrorMessage; |
| + result.mLabel = label; |
| + result.mValue = value; |
| + return result; |
| + } |
| + |
| + private EditorFieldModel(int inputTypeHint) { |
| + assert inputTypeHint >= INPUT_TYPE_HINT_MIN_INCLUSIVE; |
| + assert inputTypeHint < INPUT_TYPE_HINT_MAX_EXCLUSIVE; |
| mInputTypeHint = inputTypeHint; |
| - mDropdownKeyValues = null; |
| - mSuggestions = new ArrayList<CharSequence>(suggestions); |
| - mValidator = validator; |
| - mInvalidErrorMessage = invalidErrorMessage; |
| - mLabel = label; |
| - mRequiredErrorMessage = requiredErrorMessage; |
| - mValue = value; |
| } |
| /** @return The type of input, for example, INPUT_TYPE_HINT_PHONE. */ |
| @@ -133,17 +228,67 @@ public class EditorFieldModel { |
| return mInputTypeHint; |
| } |
| - /** @return The spinner key values. */ |
| + /** @return Whether the checkbox is checked. */ |
| + public boolean isChecked() { |
| + assert mInputTypeHint == INPUT_TYPE_HINT_CHECKBOX; |
| + return mIsChecked; |
| + } |
| + |
| + /** Sets the checkbox state. */ |
| + public void setIsChecked(boolean isChecked) { |
| + assert mInputTypeHint == INPUT_TYPE_HINT_CHECKBOX; |
| + mIsChecked = isChecked; |
| + } |
| + |
| + /** @return The list of icons resource identifiers to display. */ |
| + public List<Integer> getIconResourceIds() { |
| + assert mInputTypeHint == INPUT_TYPE_HINT_ICONS; |
| + return mIconResourceIds; |
| + } |
| + |
| + /** @return The list of string identifiers of the descriptions of the displayed icons. This is |
| + * for the screen reader. */ |
| + public List<Integer> getIconDescriptionsForAccessibility() { |
| + assert mInputTypeHint == INPUT_TYPE_HINT_ICONS; |
| + return mIconDescriptionsForAccessibility; |
| + } |
| + |
| + /** @return The dropdown key values. */ |
| public List<DropdownKeyValue> getDropdownKeyValues() { |
| assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN; |
| return mDropdownKeyValues; |
| } |
| + /** Updates the dropdown key values. */ |
| + public void setDropdownKeyValues(List<DropdownKeyValue> dropdownKeyValues) { |
| + assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN; |
| + mDropdownKeyValues = dropdownKeyValues; |
| + } |
| + |
| + |
| /** @return The human-readable label for this field. */ |
| public CharSequence getLabel() { |
| return mLabel; |
| } |
| + /** @return The human-readable mid-level label for this field. */ |
| + public CharSequence getMidLabel() { |
| + assert mInputTypeHint == INPUT_TYPE_HINT_LABEL; |
| + return mMidLabel; |
| + } |
| + |
| + /** @return The human-readable lower-level label for this field. */ |
| + public CharSequence getSubLabel() { |
| + assert mInputTypeHint == INPUT_TYPE_HINT_LABEL; |
| + return mSubLabel; |
| + } |
| + |
| + /** @return The icon to show next to the label. */ |
| + public int getLabelIconResourceId() { |
| + assert mInputTypeHint == INPUT_TYPE_HINT_LABEL; |
| + return mLabelIconResourceId; |
| + } |
| + |
| /** |
| * Updates the label. |
| * |