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 7a68d2e54a178111949d16f7dd81dc970f16bda6..cfda5293d0186a95e8fb3337cdfaaf5f8b469964 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 |
@@ -6,6 +6,9 @@ package org.chromium.chrome.browser.payments.ui; |
import android.text.TextUtils; |
+import org.chromium.base.Callback; |
+import org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.SpinnerKeyValue; |
+ |
import java.util.List; |
import javax.annotation.Nullable; |
@@ -28,23 +31,88 @@ public class EditorFieldModel { |
boolean isValid(@Nullable CharSequence value); |
} |
+ /** |
+ * The data sent to the controller when a spinner changes its value. This spinner is assumed to |
+ * change the number and type of fields in the editor. |
+ */ |
+ public static class SpinnerChangedEventData { |
gone
2016/06/28 17:30:29
Can you just use a Pair<String, Runnable>, or do y
please use gerrit instead
2016/06/29 00:28:45
Using Pair.
|
+ /** The new key of the spinner. */ |
+ public final String key; |
+ |
+ /** |
+ * The callback to invoke when the spinner value change has been processed. The view should |
+ * re-read the fields in the editor model after this callback has been fired. |
+ */ |
+ public final Runnable callback; |
+ |
+ SpinnerChangedEventData(String key, Runnable callback) { |
+ this.key = key; |
+ this.callback = callback; |
+ } |
+ } |
+ |
/** Indicates a phone field. */ |
public static final int INPUT_TYPE_HINT_PHONE = 1; |
/** Indicates an email field. */ |
public static final int INPUT_TYPE_HINT_EMAIL = 2; |
+ /** Indicates a multi-line address field that may include numbers. */ |
+ public static final int INPUT_TYPE_HINT_STREET_LINES = 3; |
+ |
+ /** Indicates a person's name. */ |
+ public static final int INPUT_TYPE_HINT_PERSON_NAME = 4; |
+ |
+ /** Indicates a region or an administrative area, e.g., a state or a province. */ |
+ public static final int INPUT_TYPE_HINT_REGION = 5; |
+ |
+ /** Indicates an alpha-numeric value, e.g., postal code or sorting code. */ |
+ public static final int INPUT_TYPE_HINT_ALPHA_NUMERIC = 6; |
+ |
private final int mInputTypeHint; |
- private final CharSequence mLabel; |
+ @Nullable private final List<SpinnerKeyValue> mSpinnerKeyValues; |
@Nullable private final List<CharSequence> mSuggestions; |
@Nullable private final EditorFieldValidator mValidator; |
- @Nullable private final CharSequence mRequiredErrorMessage; |
@Nullable private final CharSequence mInvalidErrorMessage; |
+ @Nullable private CharSequence mLabel; |
+ @Nullable private CharSequence mRequiredErrorMessage; |
@Nullable private CharSequence mErrorMessage; |
@Nullable private CharSequence mValue; |
+ @Nullable private Callback<SpinnerChangedEventData> mSpinnerCallback; |
+ private boolean mIsFullLine = true; |
+ |
+ /** |
+ * Constructs a spinner field model. |
+ * |
+ * @param label The human-readable label for user to understand the type of data that |
+ * should be entered into this field. |
+ * @param spinnerKeyValues The keyed values to display in a spinner. |
+ */ |
+ public EditorFieldModel(CharSequence label, List<SpinnerKeyValue> spinnerKeyValues) { |
+ mInputTypeHint = 0; |
gone
2016/06/28 17:30:29
Why didn't you make a new InputTypeHint here?
please use gerrit instead
2016/06/29 00:28:45
Done.
|
+ mSpinnerKeyValues = spinnerKeyValues; |
+ mSuggestions = null; |
+ mValidator = null; |
+ mInvalidErrorMessage = null; |
+ mLabel = label; |
+ } |
+ |
+ /** |
+ * Constructs a text input field model. |
+ * |
+ * @param inputTypeHint The type of input. For example, INPUT_TYPE_HINT_PHONE. |
+ */ |
+ public EditorFieldModel(int inputTypeHint) { |
+ mInputTypeHint = inputTypeHint; |
+ mSpinnerKeyValues = null; |
+ mSuggestions = null; |
+ mValidator = null; |
+ mInvalidErrorMessage = null; |
+ mLabel = null; |
+ } |
/** |
- * Constructs a field model. |
+ * Constructs a text input field model. |
* |
* @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 |
@@ -62,24 +130,45 @@ public class EditorFieldModel { |
@Nullable CharSequence requiredErrorMessage, @Nullable CharSequence invalidErrorMessage, |
@Nullable CharSequence value) { |
mInputTypeHint = inputTypeHint; |
- mLabel = label; |
+ mSpinnerKeyValues = null; |
mSuggestions = suggestions; |
mValidator = validator; |
- mRequiredErrorMessage = requiredErrorMessage; |
mInvalidErrorMessage = invalidErrorMessage; |
+ mLabel = label; |
+ mRequiredErrorMessage = requiredErrorMessage; |
mValue = value; |
} |
+ /** @return Whether this field is a spinner. */ |
+ public boolean isSpinner() { |
+ return mSpinnerKeyValues != null; |
+ } |
+ |
/** @return The type of input, for example, INPUT_TYPE_HINT_PHONE. */ |
public int getInputTypeHint() { |
return mInputTypeHint; |
} |
+ /** @return The spinner key values. */ |
+ public List<SpinnerKeyValue> getSpinnerKeyValues() { |
+ assert isSpinner(); |
+ return mSpinnerKeyValues; |
+ } |
+ |
/** @return The human-readable label for this field. */ |
public CharSequence getLabel() { |
return mLabel; |
} |
+ /** |
+ * Updates the label. |
+ * |
+ * @param label The new label to use. |
+ */ |
+ public void setLabel(CharSequence label) { |
+ mLabel = label; |
+ } |
+ |
/** @return Suggested values for this field. Can be null. */ |
@Nullable public List<CharSequence> getSuggestions() { |
return mSuggestions; |
@@ -90,27 +179,53 @@ public class EditorFieldModel { |
return mErrorMessage; |
} |
- /** @return The value that the user has entered into the field. Can be null. */ |
+ /** @return The value that the user has typed into the field or the key of the value that the |
+ * user has selected in the spinner. Can be null. */ |
@Nullable public CharSequence getValue() { |
return mValue; |
} |
/** |
* Updates the value of this field. Does not trigger validation or update the last error |
- * message. |
+ * message. Should be called only for text fields. |
* |
- * @param value The new value that the user has entered. |
+ * @param value The new value that the user has typed in. |
*/ |
public void setValue(@Nullable CharSequence value) { |
+ assert !isSpinner(); |
mValue = value; |
} |
+ /** |
+ * Updates the spinner value. |
+ * |
+ * @param key The new spinner key. |
+ * @param callback The callback to invoke when the change has been processed. |
+ */ |
+ public void setSpinnerKey(String key, Runnable callback) { |
+ assert isSpinner(); |
+ mValue = key; |
+ if (mSpinnerCallback != null) { |
+ mSpinnerCallback.onResult(new SpinnerChangedEventData(key, callback)); |
+ } |
+ } |
+ |
/** @return Whether or not the field is required. */ |
public boolean isRequired() { |
return !TextUtils.isEmpty(mRequiredErrorMessage); |
} |
/** |
+ * Updates the required error message. |
+ * |
+ * @param message The error message to use if this field is required, but empty. If null, then |
+ * this field is optional. |
+ */ |
+ public void setRequiredErrorMessage(@Nullable CharSequence message) { |
+ mRequiredErrorMessage = message; |
+ } |
+ |
+ /** |
* Returns true if the field value is valid. Also updates the error message. |
* |
* @return Whether the field value is valid. |
@@ -130,4 +245,30 @@ public class EditorFieldModel { |
mErrorMessage = null; |
return true; |
} |
+ |
+ /** |
+ * Sets the spinner callback. |
+ * |
+ * @param callback The callback to invoke when the spinner value has changed. |
+ */ |
+ public void setSpinnerCallback(Callback<SpinnerChangedEventData> callback) { |
+ assert isSpinner(); |
+ mSpinnerCallback = callback; |
+ } |
+ |
+ /** @return True if the input field should take up the full line, instead of sharing with other |
+ * input fields. This is the default.*/ |
+ public boolean isFullLine() { |
+ return mIsFullLine; |
+ } |
+ |
+ /** |
+ * Sets whether this input field should take up the full line. All fields take up the full line |
+ * by default. |
+ * |
+ * @param isFullLine Whether the input field should take up the full line. |
+ */ |
+ public void setIsFullLine(boolean isFullLine) { |
+ mIsFullLine = isFullLine; |
+ } |
} |