| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.autofill; | 5 package org.chromium.chrome.browser.autofill; |
| 6 | 6 |
| 7 import android.app.AlertDialog; | 7 import android.app.AlertDialog; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
| 10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 public void dismiss() { | 166 public void dismiss() { |
| 167 mDialog.dismiss(); | 167 mDialog.dismiss(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 public void disableAndWaitForVerification() { | 170 public void disableAndWaitForVerification() { |
| 171 setInputsEnabled(false); | 171 setInputsEnabled(false); |
| 172 setOverlayVisibility(View.VISIBLE); | 172 setOverlayVisibility(View.VISIBLE); |
| 173 mVerificationProgressBar.setVisibility(View.VISIBLE); | 173 mVerificationProgressBar.setVisibility(View.VISIBLE); |
| 174 mVerificationView.setText(R.string.autofill_card_unmask_verification_in_
progress); | 174 mVerificationView.setText(R.string.autofill_card_unmask_verification_in_
progress); |
| 175 ApiCompatibilityUtils.announceForAccessibility( | 175 mVerificationView.announceForAccessibility(mVerificationView.getText()); |
| 176 mVerificationView, mVerificationView.getText()); | |
| 177 setInputError(null); | 176 setInputError(null); |
| 178 } | 177 } |
| 179 | 178 |
| 180 public void verificationFinished(String errorMessage, boolean allowRetry) { | 179 public void verificationFinished(String errorMessage, boolean allowRetry) { |
| 181 if (errorMessage != null) { | 180 if (errorMessage != null) { |
| 182 setOverlayVisibility(View.GONE); | 181 setOverlayVisibility(View.GONE); |
| 183 if (allowRetry) { | 182 if (allowRetry) { |
| 184 setInputError(errorMessage); | 183 setInputError(errorMessage); |
| 185 setInputsEnabled(true); | 184 setInputsEnabled(true); |
| 186 setInitialFocus(); | 185 setInitialFocus(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 h.postDelayed(new Runnable() { | 258 h.postDelayed(new Runnable() { |
| 260 @Override | 259 @Override |
| 261 public void run() { | 260 public void run() { |
| 262 mStoreLocallyTooltipPopup = null; | 261 mStoreLocallyTooltipPopup = null; |
| 263 } | 262 } |
| 264 }, 200); | 263 }, 200); |
| 265 } | 264 } |
| 266 }); | 265 }); |
| 267 mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox, | 266 mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox, |
| 268 ViewCompat.getPaddingStart(mStoreLocallyCheckbox), 0); | 267 ViewCompat.getPaddingStart(mStoreLocallyCheckbox), 0); |
| 269 ApiCompatibilityUtils.announceForAccessibility(text, text.getText()); | 268 text.announceForAccessibility(text.getText()); |
| 270 } | 269 } |
| 271 | 270 |
| 272 private void setInitialFocus() { | 271 private void setInitialFocus() { |
| 273 InputMethodManager imm = (InputMethodManager) mDialog.getContext().getSy
stemService( | 272 InputMethodManager imm = (InputMethodManager) mDialog.getContext().getSy
stemService( |
| 274 Context.INPUT_METHOD_SERVICE); | 273 Context.INPUT_METHOD_SERVICE); |
| 275 View view = mShouldRequestExpirationDate ? mMonthInput : mCardUnmaskInpu
t; | 274 View view = mShouldRequestExpirationDate ? mMonthInput : mCardUnmaskInpu
t; |
| 276 imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); | 275 imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); |
| 277 view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); | 276 view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 278 } | 277 } |
| 279 | 278 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 * Sets the error message on the cvc input. | 330 * Sets the error message on the cvc input. |
| 332 * @param message The error message to show, or null if the error state shou
ld be cleared. | 331 * @param message The error message to show, or null if the error state shou
ld be cleared. |
| 333 */ | 332 */ |
| 334 private void setInputError(String message) { | 333 private void setInputError(String message) { |
| 335 mErrorMessage.setText(message); | 334 mErrorMessage.setText(message); |
| 336 mErrorMessage.setVisibility(message == null ? View.GONE : View.VISIBLE); | 335 mErrorMessage.setVisibility(message == null ? View.GONE : View.VISIBLE); |
| 337 | 336 |
| 338 // A null message is passed in during card verification, which also make
s an announcement. | 337 // A null message is passed in during card verification, which also make
s an announcement. |
| 339 // Announcing twice in a row may cancel the first announcement. | 338 // Announcing twice in a row may cancel the first announcement. |
| 340 if (message != null) { | 339 if (message != null) { |
| 341 ApiCompatibilityUtils.announceForAccessibility(mErrorMessage, messag
e); | 340 mErrorMessage.announceForAccessibility(message); |
| 342 } | 341 } |
| 343 | 342 |
| 344 // The rest of this code makes L-specific assumptions about the backgrou
nd being used to | 343 // The rest of this code makes L-specific assumptions about the backgrou
nd being used to |
| 345 // draw the TextInput. | 344 // draw the TextInput. |
| 346 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; | 345 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; |
| 347 | 346 |
| 348 ColorFilter filter = null; | 347 ColorFilter filter = null; |
| 349 if (message != null) { | 348 if (message != null) { |
| 350 filter = new PorterDuffColorFilter(mDialog.getContext().getResources
().getColor( | 349 filter = new PorterDuffColorFilter(mDialog.getContext().getResources
().getColor( |
| 351 R.color.input_underline_error_color), PorterDuff.Mode.SRC_IN
); | 350 R.color.input_underline_error_color), PorterDuff.Mode.SRC_IN
); |
| 352 } | 351 } |
| 353 | 352 |
| 354 // TODO(estade): it would be nicer if the error were specific enough to
tell us which input | 353 // TODO(estade): it would be nicer if the error were specific enough to
tell us which input |
| 355 // was invalid. | 354 // was invalid. |
| 356 updateColorForInput(mCardUnmaskInput, filter); | 355 updateColorForInput(mCardUnmaskInput, filter); |
| 357 updateColorForInput(mMonthInput, filter); | 356 updateColorForInput(mMonthInput, filter); |
| 358 updateColorForInput(mYearInput, filter); | 357 updateColorForInput(mYearInput, filter); |
| 359 } | 358 } |
| 360 | 359 |
| 361 /** | 360 /** |
| 362 * Displays an error that indicates the user can't retry. | 361 * Displays an error that indicates the user can't retry. |
| 363 */ | 362 */ |
| 364 private void setNoRetryError(String message) { | 363 private void setNoRetryError(String message) { |
| 365 mNoRetryErrorMessage.setText(message); | 364 mNoRetryErrorMessage.setText(message); |
| 366 mNoRetryErrorMessage.setVisibility(View.VISIBLE); | 365 mNoRetryErrorMessage.setVisibility(View.VISIBLE); |
| 367 ApiCompatibilityUtils.announceForAccessibility(mNoRetryErrorMessage, mes
sage); | 366 mNoRetryErrorMessage.announceForAccessibility(message); |
| 368 } | 367 } |
| 369 | 368 |
| 370 /** | 369 /** |
| 371 * Sets the stroke color for the given input. | 370 * Sets the stroke color for the given input. |
| 372 * @param input The input to modify. | 371 * @param input The input to modify. |
| 373 * @param filter The color filter to apply to the background. | 372 * @param filter The color filter to apply to the background. |
| 374 */ | 373 */ |
| 375 private void updateColorForInput(EditText input, ColorFilter filter) { | 374 private void updateColorForInput(EditText input, ColorFilter filter) { |
| 376 input.getBackground().mutate().setColorFilter(filter); | 375 input.getBackground().mutate().setColorFilter(filter); |
| 377 } | 376 } |
| 378 | 377 |
| 379 /** | 378 /** |
| 380 * Returns the expiration year the user entered. | 379 * Returns the expiration year the user entered. |
| 381 * Two digit values (such as 17) will be converted to 4 digit years (such as
2017). | 380 * Two digit values (such as 17) will be converted to 4 digit years (such as
2017). |
| 382 * Returns -1 if the input is empty or otherwise not a valid year. | 381 * Returns -1 if the input is empty or otherwise not a valid year. |
| 383 */ | 382 */ |
| 384 private int getFourDigitYear() { | 383 private int getFourDigitYear() { |
| 385 try { | 384 try { |
| 386 int year = Integer.parseInt(mYearInput.getText().toString()); | 385 int year = Integer.parseInt(mYearInput.getText().toString()); |
| 387 if (year < 0) return -1; | 386 if (year < 0) return -1; |
| 388 if (year < 100) year += mThisYear - mThisYear % 100; | 387 if (year < 100) year += mThisYear - mThisYear % 100; |
| 389 return year; | 388 return year; |
| 390 } catch (NumberFormatException e) { | 389 } catch (NumberFormatException e) { |
| 391 return -1; | 390 return -1; |
| 392 } | 391 } |
| 393 } | 392 } |
| 394 } | 393 } |
| OLD | NEW |