| Index: ui/android/java/src/org/chromium/ui/autofill/CardUnmaskPrompt.java
|
| diff --git a/ui/android/java/src/org/chromium/ui/autofill/CardUnmaskPrompt.java b/ui/android/java/src/org/chromium/ui/autofill/CardUnmaskPrompt.java
|
| index ca09167665ec08c5b220646091f7561d8afe4e57..40ba19f1e2ba7196f8b3f5dddcdc51d78df63fde 100644
|
| --- a/ui/android/java/src/org/chromium/ui/autofill/CardUnmaskPrompt.java
|
| +++ b/ui/android/java/src/org/chromium/ui/autofill/CardUnmaskPrompt.java
|
| @@ -7,8 +7,12 @@ package org.chromium.ui.autofill;
|
| import android.app.AlertDialog;
|
| import android.content.Context;
|
| import android.content.DialogInterface;
|
| +import android.os.Handler;
|
| +import android.text.Editable;
|
| +import android.text.TextWatcher;
|
| import android.view.LayoutInflater;
|
| import android.view.View;
|
| +import android.view.inputmethod.InputMethodManager;
|
| import android.widget.Button;
|
| import android.widget.EditText;
|
| import android.widget.TextView;
|
| @@ -18,7 +22,7 @@ import org.chromium.ui.R;
|
| /**
|
| * A prompt that bugs users to enter their CVC when unmasking a Wallet instrument (credit card).
|
| */
|
| -public class CardUnmaskPrompt implements DialogInterface.OnDismissListener {
|
| +public class CardUnmaskPrompt implements DialogInterface.OnDismissListener, TextWatcher {
|
| private CardUnmaskPromptDelegate mDelegate;
|
| private AlertDialog mDialog;
|
|
|
| @@ -32,6 +36,11 @@ public class CardUnmaskPrompt implements DialogInterface.OnDismissListener {
|
| void dismissed();
|
|
|
| /**
|
| + * Returns whether |userResponse| represents a valid value.
|
| + */
|
| + boolean checkUserInputValidity(String userResponse);
|
| +
|
| + /**
|
| * Called when the user has entered a value and pressed "verify".
|
| * @param userResponse The value the user entered (a CVC), or an empty string if the
|
| * user canceled.
|
| @@ -39,14 +48,16 @@ public class CardUnmaskPrompt implements DialogInterface.OnDismissListener {
|
| void onUserInput(String userResponse);
|
| }
|
|
|
| - public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate) {
|
| + public CardUnmaskPrompt(
|
| + Context context, CardUnmaskPromptDelegate delegate, String title, String instructions) {
|
| mDelegate = delegate;
|
|
|
| LayoutInflater inflater = LayoutInflater.from(context);
|
| View v = inflater.inflate(R.layout.autofill_card_unmask_prompt, null);
|
| + ((TextView) v.findViewById(R.id.card_unmask_instructions)).setText(instructions);
|
|
|
| mDialog = new AlertDialog.Builder(context)
|
| - .setTitle("Unlocking Visa - 1111")
|
| + .setTitle(title)
|
| .setView(v)
|
| .setNegativeButton("Back", null)
|
| .setPositiveButton("Rock on", null)
|
| @@ -60,12 +71,22 @@ public class CardUnmaskPrompt implements DialogInterface.OnDismissListener {
|
| // Override the View.OnClickListener so that pressing the positive button doesn't dismiss
|
| // the dialog.
|
| Button verifyButton = mDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
| + verifyButton.setEnabled(false);
|
| verifyButton.setOnClickListener(new View.OnClickListener() {
|
| @Override
|
| public void onClick(View view) {
|
| mDelegate.onUserInput(cardUnmaskInput().getText().toString());
|
| }
|
| });
|
| +
|
| + final EditText input = cardUnmaskInput();
|
| + input.addTextChangedListener(this);
|
| + input.post(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + showKeyboardForUnmaskInput();
|
| + }
|
| + });
|
| }
|
|
|
| public void dismiss() {
|
| @@ -74,14 +95,28 @@ public class CardUnmaskPrompt implements DialogInterface.OnDismissListener {
|
|
|
| public void disableAndWaitForVerification() {
|
| cardUnmaskInput().setEnabled(false);
|
| + mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
| TextView message = verificationView();
|
| message.setText("Verifying...");
|
| message.setVisibility(View.VISIBLE);
|
| }
|
|
|
| - public void verificationFailed() {
|
| - verificationView().setText("Verification failed. Please try again.");
|
| - cardUnmaskInput().setEnabled(true);
|
| + public void verificationFinished(boolean success) {
|
| + if (!success) {
|
| + verificationView().setText("Verification failed. Please try again.");
|
| + EditText input = cardUnmaskInput();
|
| + input.setEnabled(true);
|
| + showKeyboardForUnmaskInput();
|
| + // TODO(estade): UI decision - should we clear the input?
|
| + } else {
|
| + verificationView().setText("Success!");
|
| + Handler h = new Handler();
|
| + h.postDelayed(new Runnable() {
|
| + public void run() {
|
| + dismiss();
|
| + }
|
| + }, 1000);
|
| + }
|
| }
|
|
|
| @Override
|
| @@ -89,6 +124,24 @@ public class CardUnmaskPrompt implements DialogInterface.OnDismissListener {
|
| mDelegate.dismissed();
|
| }
|
|
|
| + @Override
|
| + public void afterTextChanged(Editable s) {
|
| + boolean valid = mDelegate.checkUserInputValidity(cardUnmaskInput().getText().toString());
|
| + mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(valid);
|
| + }
|
| +
|
| + @Override
|
| + public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
| +
|
| + @Override
|
| + public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
| +
|
| + private void showKeyboardForUnmaskInput() {
|
| + InputMethodManager imm = (InputMethodManager) mDialog.getContext().getSystemService(
|
| + Context.INPUT_METHOD_SERVICE);
|
| + imm.showSoftInput(cardUnmaskInput(), InputMethodManager.SHOW_IMPLICIT);
|
| + }
|
| +
|
| private EditText cardUnmaskInput() {
|
| return (EditText) mDialog.findViewById(R.id.card_unmask_input);
|
| }
|
|
|