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.text.TextUtils; | 7 import android.text.TextUtils; |
| 8 import android.text.TextWatcher; |
8 import android.util.Pair; | 9 import android.util.Pair; |
9 | 10 |
10 import org.chromium.base.Callback; | 11 import org.chromium.base.Callback; |
11 import org.chromium.base.ContextUtils; | 12 import org.chromium.base.ContextUtils; |
12 import org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.Dr
opdownKeyValue; | 13 import org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.Dr
opdownKeyValue; |
13 | 14 |
14 import java.util.ArrayList; | 15 import java.util.ArrayList; |
15 import java.util.HashSet; | 16 import java.util.HashSet; |
16 import java.util.List; | 17 import java.util.List; |
17 import java.util.Set; | 18 import java.util.Set; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 112 |
112 private static final int INPUT_TYPE_HINT_MAX_EXCLUSIVE = 12; | 113 private static final int INPUT_TYPE_HINT_MAX_EXCLUSIVE = 12; |
113 | 114 |
114 private final int mInputTypeHint; | 115 private final int mInputTypeHint; |
115 | 116 |
116 @Nullable private List<Integer> mIconResourceIds; | 117 @Nullable private List<Integer> mIconResourceIds; |
117 @Nullable private List<Integer> mIconDescriptionsForAccessibility; | 118 @Nullable private List<Integer> mIconDescriptionsForAccessibility; |
118 @Nullable private List<DropdownKeyValue> mDropdownKeyValues; | 119 @Nullable private List<DropdownKeyValue> mDropdownKeyValues; |
119 @Nullable private Set<String> mDropdownKeys; | 120 @Nullable private Set<String> mDropdownKeys; |
120 @Nullable private List<CharSequence> mSuggestions; | 121 @Nullable private List<CharSequence> mSuggestions; |
| 122 @Nullable |
| 123 private TextWatcher mFormatter; |
121 @Nullable private EditorFieldValidator mValidator; | 124 @Nullable private EditorFieldValidator mValidator; |
122 @Nullable private EditorValueIconGenerator mValueIconGenerator; | 125 @Nullable private EditorValueIconGenerator mValueIconGenerator; |
123 @Nullable private CharSequence mRequiredErrorMessage; | 126 @Nullable private CharSequence mRequiredErrorMessage; |
124 @Nullable private CharSequence mInvalidErrorMessage; | 127 @Nullable private CharSequence mInvalidErrorMessage; |
125 @Nullable private CharSequence mErrorMessage; | 128 @Nullable private CharSequence mErrorMessage; |
126 @Nullable private CharSequence mLabel; | 129 @Nullable private CharSequence mLabel; |
127 @Nullable private CharSequence mMidLabel; | 130 @Nullable private CharSequence mMidLabel; |
128 @Nullable private CharSequence mBottomLabel; | 131 @Nullable private CharSequence mBottomLabel; |
129 @Nullable private CharSequence mValue; | 132 @Nullable private CharSequence mValue; |
130 @Nullable private CharSequence mHint; | 133 @Nullable private CharSequence mHint; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return result; | 263 return result; |
261 } | 264 } |
262 | 265 |
263 /** | 266 /** |
264 * Constructs a text input field model. | 267 * Constructs a text input field model. |
265 * | 268 * |
266 * @param inputTypeHint The type of input. For example, INPUT_TYPE_HI
NT_PHONE. | 269 * @param inputTypeHint The type of input. For example, INPUT_TYPE_HI
NT_PHONE. |
267 * @param label The human-readable label for user to understa
nd the type of data | 270 * @param label The human-readable label for user to understa
nd the type of data |
268 * that should be entered into this field. | 271 * that should be entered into this field. |
269 * @param suggestions Optional set of values to suggest to the user
. | 272 * @param suggestions Optional set of values to suggest to the user
. |
| 273 * @param formatter Optional formatter for the values in this fie
ld. |
270 * @param validator Optional validator for the values in this fie
ld. | 274 * @param validator Optional validator for the values in this fie
ld. |
271 * @param valueIconGenerator Optional icon generator for the values in thi
s field. | 275 * @param valueIconGenerator Optional icon generator for the values in thi
s field. |
272 * @param requiredErrorMessage The optional error message that indicates to
the user that they | 276 * @param requiredErrorMessage The optional error message that indicates to
the user that they |
273 * cannot leave this field empty. | 277 * cannot leave this field empty. |
274 * @param invalidErrorMessage The optional error message that indicates to
the user that the | 278 * @param invalidErrorMessage The optional error message that indicates to
the user that the |
275 * value they have entered is not valid. | 279 * value they have entered is not valid. |
276 * @param value Optional initial value of this field. | 280 * @param value Optional initial value of this field. |
277 */ | 281 */ |
278 public static EditorFieldModel createTextInput(int inputTypeHint, CharSequen
ce label, | 282 public static EditorFieldModel createTextInput(int inputTypeHint, CharSequen
ce label, |
279 @Nullable Set<CharSequence> suggestions, @Nullable EditorFieldValida
tor validator, | 283 @Nullable Set<CharSequence> suggestions, @Nullable TextWatcher forma
tter, |
| 284 @Nullable EditorFieldValidator validator, |
280 @Nullable EditorValueIconGenerator valueIconGenerator, | 285 @Nullable EditorValueIconGenerator valueIconGenerator, |
281 @Nullable CharSequence requiredErrorMessage, @Nullable CharSequence
invalidErrorMessage, | 286 @Nullable CharSequence requiredErrorMessage, @Nullable CharSequence
invalidErrorMessage, |
282 @Nullable CharSequence value) { | 287 @Nullable CharSequence value) { |
283 assert label != null; | 288 assert label != null; |
284 EditorFieldModel result = new EditorFieldModel(inputTypeHint); | 289 EditorFieldModel result = new EditorFieldModel(inputTypeHint); |
285 assert result.isTextField(); | 290 assert result.isTextField(); |
286 result.mSuggestions = suggestions == null ? null : new ArrayList<CharSeq
uence>(suggestions); | 291 result.mSuggestions = suggestions == null ? null : new ArrayList<CharSeq
uence>(suggestions); |
| 292 result.mFormatter = formatter; |
287 result.mValidator = validator; | 293 result.mValidator = validator; |
288 result.mValueIconGenerator = valueIconGenerator; | 294 result.mValueIconGenerator = valueIconGenerator; |
289 result.mInvalidErrorMessage = invalidErrorMessage; | 295 result.mInvalidErrorMessage = invalidErrorMessage; |
290 result.mRequiredErrorMessage = requiredErrorMessage; | 296 result.mRequiredErrorMessage = requiredErrorMessage; |
291 result.mLabel = label; | 297 result.mLabel = label; |
292 result.mValue = value; | 298 result.mValue = value; |
293 return result; | 299 return result; |
294 } | 300 } |
295 | 301 |
296 /** | 302 /** |
(...skipping 27 matching lines...) Expand all Loading... |
324 assert isTextField(); | 330 assert isTextField(); |
325 return mActionIconDescriptionForAccessibility; | 331 return mActionIconDescriptionForAccessibility; |
326 } | 332 } |
327 | 333 |
328 /** @return The action to invoke when the action icon has been tapped. */ | 334 /** @return The action to invoke when the action icon has been tapped. */ |
329 public Runnable getActionIconAction() { | 335 public Runnable getActionIconAction() { |
330 assert isTextField(); | 336 assert isTextField(); |
331 return mActionIconAction; | 337 return mActionIconAction; |
332 } | 338 } |
333 | 339 |
| 340 /** @return The value formatter or null if not exist. */ |
| 341 @Nullable |
| 342 public TextWatcher getFormatter() { |
| 343 assert isTextField(); |
| 344 return mFormatter; |
| 345 } |
| 346 |
334 /** @return The value icon generator or null if not exist. */ | 347 /** @return The value icon generator or null if not exist. */ |
335 public EditorValueIconGenerator getValueIconGenerator() { | 348 public EditorValueIconGenerator getValueIconGenerator() { |
336 assert isTextField(); | 349 assert isTextField(); |
337 return mValueIconGenerator; | 350 return mValueIconGenerator; |
338 } | 351 } |
339 | 352 |
340 /** @return Whether the input is a text field. */ | 353 /** @return Whether the input is a text field. */ |
341 public boolean isTextField() { | 354 public boolean isTextField() { |
342 return mInputTypeHint >= INPUT_TYPE_HINT_MIN_INCLUSIVE | 355 return mInputTypeHint >= INPUT_TYPE_HINT_MIN_INCLUSIVE |
343 && mInputTypeHint < INPUT_TYPE_HINT_MAX_TEXT_INPUT_EXCLUSIVE; | 356 && mInputTypeHint < INPUT_TYPE_HINT_MAX_TEXT_INPUT_EXCLUSIVE; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 /** | 563 /** |
551 * Sets whether this input field should take up the full line. All fields ta
ke up the full line | 564 * Sets whether this input field should take up the full line. All fields ta
ke up the full line |
552 * by default. | 565 * by default. |
553 * | 566 * |
554 * @param isFullLine Whether the input field should take up the full line. | 567 * @param isFullLine Whether the input field should take up the full line. |
555 */ | 568 */ |
556 public void setIsFullLine(boolean isFullLine) { | 569 public void setIsFullLine(boolean isFullLine) { |
557 mIsFullLine = isFullLine; | 570 mIsFullLine = isFullLine; |
558 } | 571 } |
559 } | 572 } |
OLD | NEW |