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

Side by Side Diff: ui/android/java/src/org/chromium/ui/autofill/CardUnmaskPrompt.java

Issue 828063004: Update Android Card Unmask prompt to rely on the controller a bit more. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use newt's description Created 5 years, 11 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 unified diff | Download patch
OLDNEW
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.ui.autofill; 5 package org.chromium.ui.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.os.Handler;
11 import android.text.Editable;
12 import android.text.TextWatcher;
10 import android.view.LayoutInflater; 13 import android.view.LayoutInflater;
11 import android.view.View; 14 import android.view.View;
15 import android.view.inputmethod.InputMethodManager;
12 import android.widget.Button; 16 import android.widget.Button;
13 import android.widget.EditText; 17 import android.widget.EditText;
14 import android.widget.TextView; 18 import android.widget.TextView;
15 19
16 import org.chromium.ui.R; 20 import org.chromium.ui.R;
17 21
18 /** 22 /**
19 * A prompt that bugs users to enter their CVC when unmasking a Wallet instrumen t (credit card). 23 * A prompt that bugs users to enter their CVC when unmasking a Wallet instrumen t (credit card).
20 */ 24 */
21 public class CardUnmaskPrompt implements DialogInterface.OnDismissListener { 25 public class CardUnmaskPrompt implements DialogInterface.OnDismissListener, Text Watcher {
22 private CardUnmaskPromptDelegate mDelegate; 26 private CardUnmaskPromptDelegate mDelegate;
23 private AlertDialog mDialog; 27 private AlertDialog mDialog;
24 28
25 /** 29 /**
26 * An interface to handle the interaction with an CardUnmaskPrompt object. 30 * An interface to handle the interaction with an CardUnmaskPrompt object.
27 */ 31 */
28 public interface CardUnmaskPromptDelegate { 32 public interface CardUnmaskPromptDelegate {
29 /** 33 /**
30 * Called when the dialog has been dismissed. 34 * Called when the dialog has been dismissed.
31 */ 35 */
32 void dismissed(); 36 void dismissed();
33 37
34 /** 38 /**
39 * Returns whether |userResponse| represents a valid value.
40 */
41 boolean checkUserInputValidity(String userResponse);
42
43 /**
35 * Called when the user has entered a value and pressed "verify". 44 * Called when the user has entered a value and pressed "verify".
36 * @param userResponse The value the user entered (a CVC), or an empty s tring if the 45 * @param userResponse The value the user entered (a CVC), or an empty s tring if the
37 * user canceled. 46 * user canceled.
38 */ 47 */
39 void onUserInput(String userResponse); 48 void onUserInput(String userResponse);
40 } 49 }
41 50
42 public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate) { 51 public CardUnmaskPrompt(
52 Context context, CardUnmaskPromptDelegate delegate, String title, St ring instructions) {
43 mDelegate = delegate; 53 mDelegate = delegate;
44 54
45 LayoutInflater inflater = LayoutInflater.from(context); 55 LayoutInflater inflater = LayoutInflater.from(context);
46 View v = inflater.inflate(R.layout.autofill_card_unmask_prompt, null); 56 View v = inflater.inflate(R.layout.autofill_card_unmask_prompt, null);
57 ((TextView) v.findViewById(R.id.card_unmask_instructions)).setText(instr uctions);
47 58
48 mDialog = new AlertDialog.Builder(context) 59 mDialog = new AlertDialog.Builder(context)
49 .setTitle("Unlocking Visa - 1111") 60 .setTitle(title)
50 .setView(v) 61 .setView(v)
51 .setNegativeButton("Back", null) 62 .setNegativeButton("Back", null)
52 .setPositiveButton("Rock on", null) 63 .setPositiveButton("Rock on", null)
53 .setOnDismissListener(this) 64 .setOnDismissListener(this)
54 .create(); 65 .create();
55 } 66 }
56 67
57 public void show() { 68 public void show() {
58 mDialog.show(); 69 mDialog.show();
59 70
60 // Override the View.OnClickListener so that pressing the positive butto n doesn't dismiss 71 // Override the View.OnClickListener so that pressing the positive butto n doesn't dismiss
61 // the dialog. 72 // the dialog.
62 Button verifyButton = mDialog.getButton(AlertDialog.BUTTON_POSITIVE); 73 Button verifyButton = mDialog.getButton(AlertDialog.BUTTON_POSITIVE);
74 verifyButton.setEnabled(false);
63 verifyButton.setOnClickListener(new View.OnClickListener() { 75 verifyButton.setOnClickListener(new View.OnClickListener() {
64 @Override 76 @Override
65 public void onClick(View view) { 77 public void onClick(View view) {
66 mDelegate.onUserInput(cardUnmaskInput().getText().toString()); 78 mDelegate.onUserInput(cardUnmaskInput().getText().toString());
67 } 79 }
68 }); 80 });
81
82 final EditText input = cardUnmaskInput();
83 input.addTextChangedListener(this);
84 input.post(new Runnable() {
85 @Override
86 public void run() {
87 showKeyboardForUnmaskInput();
88 }
89 });
69 } 90 }
70 91
71 public void dismiss() { 92 public void dismiss() {
72 mDialog.dismiss(); 93 mDialog.dismiss();
73 } 94 }
74 95
75 public void disableAndWaitForVerification() { 96 public void disableAndWaitForVerification() {
76 cardUnmaskInput().setEnabled(false); 97 cardUnmaskInput().setEnabled(false);
98 mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
77 TextView message = verificationView(); 99 TextView message = verificationView();
78 message.setText("Verifying..."); 100 message.setText("Verifying...");
79 message.setVisibility(View.VISIBLE); 101 message.setVisibility(View.VISIBLE);
80 } 102 }
81 103
82 public void verificationFailed() { 104 public void verificationFinished(boolean success) {
83 verificationView().setText("Verification failed. Please try again."); 105 if (!success) {
84 cardUnmaskInput().setEnabled(true); 106 verificationView().setText("Verification failed. Please try again.") ;
107 EditText input = cardUnmaskInput();
108 input.setEnabled(true);
109 showKeyboardForUnmaskInput();
110 // TODO(estade): UI decision - should we clear the input?
111 } else {
112 verificationView().setText("Success!");
113 Handler h = new Handler();
114 h.postDelayed(new Runnable() {
115 public void run() {
116 dismiss();
117 }
118 }, 1000);
119 }
85 } 120 }
86 121
87 @Override 122 @Override
88 public void onDismiss(DialogInterface dialog) { 123 public void onDismiss(DialogInterface dialog) {
89 mDelegate.dismissed(); 124 mDelegate.dismissed();
90 } 125 }
91 126
127 @Override
128 public void afterTextChanged(Editable s) {
129 boolean valid = mDelegate.checkUserInputValidity(cardUnmaskInput().getTe xt().toString());
130 mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(valid);
131 }
132
133 @Override
134 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) {}
135
136 @Override
137 public void onTextChanged(CharSequence s, int start, int before, int count) {}
138
139 private void showKeyboardForUnmaskInput() {
140 InputMethodManager imm = (InputMethodManager) mDialog.getContext().getSy stemService(
141 Context.INPUT_METHOD_SERVICE);
142 imm.showSoftInput(cardUnmaskInput(), InputMethodManager.SHOW_IMPLICIT);
143 }
144
92 private EditText cardUnmaskInput() { 145 private EditText cardUnmaskInput() {
93 return (EditText) mDialog.findViewById(R.id.card_unmask_input); 146 return (EditText) mDialog.findViewById(R.id.card_unmask_input);
94 } 147 }
95 148
96 private TextView verificationView() { 149 private TextView verificationView() {
97 return (TextView) mDialog.findViewById(R.id.card_unmask_verification_mes sage); 150 return (TextView) mDialog.findViewById(R.id.card_unmask_verification_mes sage);
98 } 151 }
99 } 152 }
OLDNEW
« no previous file with comments | « ui/android/java/res/layout/autofill_card_unmask_prompt.xml ('k') | ui/android/java/strings/android_ui_strings.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698