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

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

Issue 990543002: Android Autofill card unmasking prompt - Add tooltip (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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.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;
11 import android.graphics.Color;
10 import android.graphics.ColorFilter; 12 import android.graphics.ColorFilter;
11 import android.graphics.PorterDuff; 13 import android.graphics.PorterDuff;
12 import android.graphics.PorterDuffColorFilter; 14 import android.graphics.PorterDuffColorFilter;
13 import android.os.Build; 15 import android.os.Build;
14 import android.os.Handler; 16 import android.os.Handler;
15 import android.support.v4.view.ViewCompat; 17 import android.support.v4.view.ViewCompat;
16 import android.text.Editable; 18 import android.text.Editable;
17 import android.text.TextWatcher; 19 import android.text.TextWatcher;
18 import android.view.LayoutInflater; 20 import android.view.LayoutInflater;
19 import android.view.View; 21 import android.view.View;
22 import android.view.View.OnLongClickListener;
20 import android.view.ViewGroup; 23 import android.view.ViewGroup;
24 import android.view.ViewGroup.LayoutParams;
21 import android.view.inputmethod.InputMethodManager; 25 import android.view.inputmethod.InputMethodManager;
22 import android.widget.Button; 26 import android.widget.Button;
23 import android.widget.CheckBox; 27 import android.widget.CheckBox;
24 import android.widget.EditText; 28 import android.widget.EditText;
25 import android.widget.ImageView; 29 import android.widget.ImageView;
30 import android.widget.PopupWindow;
26 import android.widget.ProgressBar; 31 import android.widget.ProgressBar;
32 import android.widget.RelativeLayout;
27 import android.widget.TextView; 33 import android.widget.TextView;
28 34
29 import org.chromium.chrome.R; 35 import org.chromium.chrome.R;
30 36
31 import java.util.Calendar; 37 import java.util.Calendar;
32 38
33 /** 39 /**
34 * A prompt that bugs users to enter their CVC when unmasking a Wallet instrumen t (credit card). 40 * A prompt that bugs users to enter their CVC when unmasking a Wallet instrumen t (credit card).
35 */ 41 */
36 public class CardUnmaskPrompt implements DialogInterface.OnDismissListener, Text Watcher { 42 public class CardUnmaskPrompt
43 implements DialogInterface.OnDismissListener, TextWatcher, OnLongClickLi stener {
37 private final CardUnmaskPromptDelegate mDelegate; 44 private final CardUnmaskPromptDelegate mDelegate;
38 private final AlertDialog mDialog; 45 private final AlertDialog mDialog;
39 private final boolean mShouldRequestExpirationDate; 46 private final boolean mShouldRequestExpirationDate;
40 private final int mThisYear; 47 private final int mThisYear;
41 48
49 private final View mMainView;
42 private final TextView mNoRetryErrorMessage; 50 private final TextView mNoRetryErrorMessage;
43 private final EditText mCardUnmaskInput; 51 private final EditText mCardUnmaskInput;
44 private final EditText mMonthInput; 52 private final EditText mMonthInput;
45 private final EditText mYearInput; 53 private final EditText mYearInput;
46 private final View mExpirationContainer; 54 private final View mExpirationContainer;
47 private final TextView mErrorMessage; 55 private final TextView mErrorMessage;
48 private final CheckBox mStoreLocallyCheckbox; 56 private final CheckBox mStoreLocallyCheckbox;
57 private final ImageView mStoreLocallyTooltipIcon;
58 private PopupWindow mStoreLocallyTooltipPopup;
49 private final ViewGroup mMainContents; 59 private final ViewGroup mMainContents;
50 private final View mVerificationOverlay; 60 private final View mVerificationOverlay;
51 private final ProgressBar mVerificationProgressBar; 61 private final ProgressBar mVerificationProgressBar;
52 private final TextView mVerificationView; 62 private final TextView mVerificationView;
53 63
54 /** 64 /**
55 * An interface to handle the interaction with an CardUnmaskPrompt object. 65 * An interface to handle the interaction with an CardUnmaskPrompt object.
56 */ 66 */
57 public interface CardUnmaskPromptDelegate { 67 public interface CardUnmaskPromptDelegate {
58 /** 68 /**
(...skipping 19 matching lines...) Expand all
78 88
79 public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate, String title, 89 public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate, String title,
80 String instructions, int drawableId, boolean shouldRequestExpiration Date, 90 String instructions, int drawableId, boolean shouldRequestExpiration Date,
81 boolean defaultToStoringLocally) { 91 boolean defaultToStoringLocally) {
82 mDelegate = delegate; 92 mDelegate = delegate;
83 93
84 LayoutInflater inflater = LayoutInflater.from(context); 94 LayoutInflater inflater = LayoutInflater.from(context);
85 View v = inflater.inflate(R.layout.autofill_card_unmask_prompt, null); 95 View v = inflater.inflate(R.layout.autofill_card_unmask_prompt, null);
86 ((TextView) v.findViewById(R.id.instructions)).setText(instructions); 96 ((TextView) v.findViewById(R.id.instructions)).setText(instructions);
87 97
98 mMainView = v;
88 mNoRetryErrorMessage = (TextView) v.findViewById(R.id.no_retry_error_mes sage); 99 mNoRetryErrorMessage = (TextView) v.findViewById(R.id.no_retry_error_mes sage);
89 mCardUnmaskInput = (EditText) v.findViewById(R.id.card_unmask_input); 100 mCardUnmaskInput = (EditText) v.findViewById(R.id.card_unmask_input);
90 mMonthInput = (EditText) v.findViewById(R.id.expiration_month); 101 mMonthInput = (EditText) v.findViewById(R.id.expiration_month);
91 mYearInput = (EditText) v.findViewById(R.id.expiration_year); 102 mYearInput = (EditText) v.findViewById(R.id.expiration_year);
92 mExpirationContainer = v.findViewById(R.id.expiration_container); 103 mExpirationContainer = v.findViewById(R.id.expiration_container);
93 mErrorMessage = (TextView) v.findViewById(R.id.error_message); 104 mErrorMessage = (TextView) v.findViewById(R.id.error_message);
94 mStoreLocallyCheckbox = (CheckBox) v.findViewById(R.id.store_locally_che ckbox); 105 mStoreLocallyCheckbox = (CheckBox) v.findViewById(R.id.store_locally_che ckbox);
95 mStoreLocallyCheckbox.setChecked(defaultToStoringLocally); 106 mStoreLocallyCheckbox.setChecked(defaultToStoringLocally);
107 mStoreLocallyTooltipIcon = (ImageView) v.findViewById(R.id.store_locally _tooltip_icon);
108 mStoreLocallyTooltipIcon.setOnLongClickListener(this);
96 mMainContents = (ViewGroup) v.findViewById(R.id.main_contents); 109 mMainContents = (ViewGroup) v.findViewById(R.id.main_contents);
97 mVerificationOverlay = v.findViewById(R.id.verification_overlay); 110 mVerificationOverlay = v.findViewById(R.id.verification_overlay);
98 mVerificationProgressBar = (ProgressBar) v.findViewById(R.id.verificatio n_progress_bar); 111 mVerificationProgressBar = (ProgressBar) v.findViewById(R.id.verificatio n_progress_bar);
99 mVerificationView = (TextView) v.findViewById(R.id.verification_message) ; 112 mVerificationView = (TextView) v.findViewById(R.id.verification_message) ;
100 ((ImageView) v.findViewById(R.id.cvc_hint_image)).setImageResource(drawa bleId); 113 ((ImageView) v.findViewById(R.id.cvc_hint_image)).setImageResource(drawa bleId);
101 114
102 mDialog = new AlertDialog.Builder(context) 115 mDialog = new AlertDialog.Builder(context)
103 .setTitle(title) 116 .setTitle(title)
104 .setView(v) 117 .setView(v)
105 .setNegativeButton(R.string.cancel, null) 118 .setNegativeButton(R.string.cancel, null)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 public void afterTextChanged(Editable s) { 206 public void afterTextChanged(Editable s) {
194 mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(areInputsValid ()); 207 mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(areInputsValid ());
195 } 208 }
196 209
197 @Override 210 @Override
198 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) {} 211 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) {}
199 212
200 @Override 213 @Override
201 public void onTextChanged(CharSequence s, int start, int before, int count) {} 214 public void onTextChanged(CharSequence s, int start, int before, int count) {}
202 215
216 @Override
217 public boolean onLongClick(View v) {
218 assert (v == mStoreLocallyTooltipIcon);
newt (away) 2015/03/09 18:15:53 nit: don't need () around assert statement
Evan Stade 2015/03/09 18:54:13 Done.
219 if (mStoreLocallyTooltipPopup == null) {
220 mStoreLocallyTooltipPopup = new PopupWindow(mDialog.getContext());
221 TextView text = new TextView(mDialog.getContext());
222 // TODO(estade): change to AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_TOOLT IP.
223 text.setText(R.string.card_unmask_input_hint);
224 // Width is the dialog's width less the margins and padding around t he checkbox and
225 // icon.
226 text.setWidth(mMainView.getWidth() - mStoreLocallyCheckbox.getPaddin gStart()
newt (away) 2015/03/09 18:15:53 All these *start() and *end() methods were added i
Evan Stade 2015/03/09 18:54:13 Done. No lint errors seen (just a bunch of resourc
227 - mStoreLocallyTooltipIcon.getPaddingEnd()
228 - ((RelativeLayout.LayoutParams) mStoreLocallyCheckbox.getLa youtParams())
229 .getMarginStart()
230 - ((RelativeLayout.LayoutParams) mStoreLocallyTooltipIcon.ge tLayoutParams())
231 .getMarginEnd());
232 text.setTextColor(Color.WHITE);
233 Resources resources = mDialog.getContext().getResources();
234 int hPadding = resources.getDimensionPixelSize(
235 R.dimen.autofill_card_unmask_tooltip_horizontal_padding);
236 int vPadding = resources.getDimensionPixelSize(
237 R.dimen.autofill_card_unmask_tooltip_vertical_padding);
238 text.setPadding(hPadding, vPadding, hPadding, vPadding);
239
240 mStoreLocallyTooltipPopup.setContentView(text);
241 mStoreLocallyTooltipPopup.setWindowLayoutMode(
242 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
243 mStoreLocallyTooltipPopup.setOutsideTouchable(true);
244 mStoreLocallyTooltipPopup.setBackgroundDrawable(
245 resources.getDrawable(R.drawable.store_locally_tooltip_backg round));
246 }
247 mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox,
248 mStoreLocallyCheckbox.getPaddingStart(), 0);
249 return true;
250 }
251
203 private void setInitialFocus() { 252 private void setInitialFocus() {
204 InputMethodManager imm = (InputMethodManager) mDialog.getContext().getSy stemService( 253 InputMethodManager imm = (InputMethodManager) mDialog.getContext().getSy stemService(
205 Context.INPUT_METHOD_SERVICE); 254 Context.INPUT_METHOD_SERVICE);
206 imm.showSoftInput(mShouldRequestExpirationDate ? mMonthInput : mCardUnma skInput, 255 imm.showSoftInput(mShouldRequestExpirationDate ? mMonthInput : mCardUnma skInput,
207 InputMethodManager.SHOW_IMPLICIT); 256 InputMethodManager.SHOW_IMPLICIT);
208 } 257 }
209 258
210 private boolean areInputsValid() { 259 private boolean areInputsValid() {
211 if (mShouldRequestExpirationDate) { 260 if (mShouldRequestExpirationDate) {
212 try { 261 try {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 try { 351 try {
303 int year = Integer.parseInt(mYearInput.getText().toString()); 352 int year = Integer.parseInt(mYearInput.getText().toString());
304 if (year < 0) return -1; 353 if (year < 0) return -1;
305 if (year < 100) year += mThisYear - mThisYear % 100; 354 if (year < 100) year += mThisYear - mThisYear % 100;
306 return year; 355 return year;
307 } catch (NumberFormatException e) { 356 } catch (NumberFormatException e) {
308 return -1; 357 return -1;
309 } 358 }
310 } 359 }
311 } 360 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698