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 d080271686b1a294205ae7498a15d76ea82f57a6..12c3693194de95d2870ab011ddf896a634288434 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 |
@@ -11,7 +11,6 @@ |
import org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue; |
import java.util.ArrayList; |
-import java.util.HashSet; |
import java.util.List; |
import java.util.Set; |
@@ -35,11 +34,6 @@ |
boolean isValid(@Nullable CharSequence value); |
} |
- private static final int INPUT_TYPE_HINT_MIN_INCLUSIVE = 0; |
- |
- /** Text input with no special formatting rules, e.g., a city, a suburb, or a company name. */ |
- private static final int INPUT_TYPE_HINT_NONE = 0; |
- |
/** Indicates a phone field. */ |
public static final int INPUT_TYPE_HINT_PHONE = 1; |
@@ -58,115 +52,20 @@ |
/** 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 = 8; |
- |
- /** Indicates a list of icons. */ |
- public static final int INPUT_TYPE_HINT_ICONS = 9; |
- |
- /** Indicates a checkbox. */ |
- public static final int INPUT_TYPE_HINT_CHECKBOX = 10; |
- |
- /** |
- * Indicates a label, e.g., for a server credit card. |
- * |
- * TOP_LABEL |
- * MID_LABEL [ICON] |
- * BOTTOM_LABEL |
- * |
- * Example: |
- * |
- * Visa***1234 |
- * First Last [VISA] |
- * Exp: 03/2021 |
- */ |
- public static final int INPUT_TYPE_HINT_LABEL = 11; |
- |
- private static final int INPUT_TYPE_HINT_MAX_EXCLUSIVE = 12; |
+ public static final int INPUT_TYPE_HINT_DROPDOWN = 7; |
private final int mInputTypeHint; |
- |
- @Nullable private List<Integer> mIconResourceIds; |
- @Nullable private List<Integer> mIconDescriptionsForAccessibility; |
- @Nullable private List<DropdownKeyValue> mDropdownKeyValues; |
- @Nullable private Set<String> mDropdownKeys; |
- @Nullable private List<CharSequence> mSuggestions; |
- @Nullable private EditorFieldValidator mValidator; |
+ @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 CharSequence mRequiredErrorMessage; |
- @Nullable private CharSequence mInvalidErrorMessage; |
@Nullable private CharSequence mErrorMessage; |
- @Nullable private CharSequence mLabel; |
- @Nullable private CharSequence mMidLabel; |
- @Nullable private CharSequence mBottomLabel; |
@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. Layout: |
- * |
- * topLabel |
- * midLabel iconId |
- * bottomLabel |
- * |
- * @param topLabel Top label. |
- * @param midLabel Middle label. |
- * @param bottomLabel Bottom label. |
- * @param iconId Icon. |
- */ |
- public static EditorFieldModel createLabel( |
- CharSequence topLabel, CharSequence midLabel, CharSequence bottomLabel, int iconId) { |
- assert topLabel != null; |
- assert midLabel != null; |
- assert bottomLabel != null; |
- EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_LABEL); |
- result.mLabel = topLabel; |
- result.mMidLabel = midLabel; |
- result.mBottomLabel = bottomLabel; |
- 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. |
@@ -175,23 +74,13 @@ |
* that should be entered into this field. |
* @param dropdownKeyValues The keyed values to display in the dropdown. |
*/ |
- 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; |
- result.mDropdownKeys = new HashSet<>(); |
- for (int i = 0; i < result.mDropdownKeyValues.size(); i++) { |
- result.mDropdownKeys.add(result.mDropdownKeyValues.get(i).getKey()); |
- } |
- return result; |
- } |
- |
- /** Constructs a text input field model without any special text formatting hints. */ |
- public static EditorFieldModel createTextInput() { |
- return new EditorFieldModel(INPUT_TYPE_HINT_NONE); |
+ public EditorFieldModel(CharSequence label, List<DropdownKeyValue> dropdownKeyValues) { |
+ mInputTypeHint = INPUT_TYPE_HINT_DROPDOWN; |
+ mDropdownKeyValues = dropdownKeyValues; |
+ mSuggestions = null; |
+ mValidator = null; |
+ mInvalidErrorMessage = null; |
+ mLabel = label; |
} |
/** |
@@ -199,10 +88,14 @@ |
* |
* @param inputTypeHint The type of input. For example, INPUT_TYPE_HINT_PHONE. |
*/ |
- public static EditorFieldModel createTextInput(int inputTypeHint) { |
- assert inputTypeHint >= INPUT_TYPE_HINT_MIN_INCLUSIVE; |
- assert inputTypeHint < INPUT_TYPE_HINT_MAX_TEXT_INPUT_EXCLUSIVE; |
- return new EditorFieldModel(inputTypeHint); |
+ public EditorFieldModel(int inputTypeHint) { |
+ assert inputTypeHint != INPUT_TYPE_HINT_DROPDOWN; |
+ mInputTypeHint = inputTypeHint; |
+ mDropdownKeyValues = null; |
+ mSuggestions = null; |
+ mValidator = null; |
+ mInvalidErrorMessage = null; |
+ mLabel = null; |
} |
/** |
@@ -211,7 +104,7 @@ |
* @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 Optional set of values to suggest to the user. |
+ * @param suggestions Optionally empty 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. |
@@ -219,27 +112,20 @@ |
* value they have entered is not valid. |
* @param value Optional initial value of this field. |
*/ |
- public static EditorFieldModel createTextInput(int inputTypeHint, CharSequence label, |
- @Nullable Set<CharSequence> suggestions, @Nullable EditorFieldValidator validator, |
+ public EditorFieldModel(int inputTypeHint, CharSequence label, |
+ Set<CharSequence> suggestions, @Nullable EditorFieldValidator validator, |
@Nullable CharSequence requiredErrorMessage, @Nullable CharSequence invalidErrorMessage, |
@Nullable CharSequence value) { |
- 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; |
+ assert inputTypeHint != INPUT_TYPE_HINT_DROPDOWN; |
+ assert suggestions != null; |
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. */ |
@@ -247,71 +133,15 @@ |
return mInputTypeHint; |
} |
- /** @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-value pairs. */ |
+ /** @return The spinner key values. */ |
public List<DropdownKeyValue> getDropdownKeyValues() { |
assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN; |
return mDropdownKeyValues; |
} |
- /** @return The dropdown keys. */ |
- public Set<String> getDropdownKeys() { |
- assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN; |
- return mDropdownKeys; |
- } |
- |
- /** 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 getBottomLabel() { |
- assert mInputTypeHint == INPUT_TYPE_HINT_LABEL; |
- return mBottomLabel; |
- } |
- |
- /** @return The icon to show next to the label. */ |
- public int getLabelIconResourceId() { |
- assert mInputTypeHint == INPUT_TYPE_HINT_LABEL; |
- return mLabelIconResourceId; |
} |
/** |