Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2544)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorFieldModel.java

Issue 2163693002: [Merge M-53] Credit card editor for PaymentRequest UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a7c6dd3d886065624109e383b8f07c7d4db37a96 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,6 +11,7 @@ import org.chromium.base.Callback;
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;
@@ -34,6 +35,11 @@ public class EditorFieldModel {
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;
@@ -52,35 +58,139 @@ 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 = 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;
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 Set<String> mDropdownKeys;
+ @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 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.
*
* @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(
+ @Nullable CharSequence label, List<DropdownKeyValue> dropdownKeyValues) {
+ 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);
}
/**
@@ -88,14 +198,10 @@ 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 >= INPUT_TYPE_HINT_MIN_INCLUSIVE;
+ assert inputTypeHint < INPUT_TYPE_HINT_MAX_TEXT_INPUT_EXCLUSIVE;
+ return new EditorFieldModel(inputTypeHint);
}
/**
@@ -104,7 +210,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 +218,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 +246,73 @@ 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-value pairs. */
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;
+ }
+
/**
* Updates the label.
*

Powered by Google App Engine
This is Rietveld 408576698