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; | |
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; |
17 import android.support.v4.view.MarginLayoutParamsCompat; | |
15 import android.support.v4.view.ViewCompat; | 18 import android.support.v4.view.ViewCompat; |
16 import android.text.Editable; | 19 import android.text.Editable; |
17 import android.text.TextWatcher; | 20 import android.text.TextWatcher; |
18 import android.view.LayoutInflater; | 21 import android.view.LayoutInflater; |
19 import android.view.View; | 22 import android.view.View; |
23 import android.view.View.OnLongClickListener; | |
20 import android.view.ViewGroup; | 24 import android.view.ViewGroup; |
25 import android.view.ViewGroup.LayoutParams; | |
21 import android.view.inputmethod.InputMethodManager; | 26 import android.view.inputmethod.InputMethodManager; |
22 import android.widget.Button; | 27 import android.widget.Button; |
23 import android.widget.CheckBox; | 28 import android.widget.CheckBox; |
24 import android.widget.EditText; | 29 import android.widget.EditText; |
25 import android.widget.ImageView; | 30 import android.widget.ImageView; |
31 import android.widget.PopupWindow; | |
26 import android.widget.ProgressBar; | 32 import android.widget.ProgressBar; |
33 import android.widget.RelativeLayout; | |
27 import android.widget.TextView; | 34 import android.widget.TextView; |
28 | 35 |
29 import org.chromium.chrome.R; | 36 import org.chromium.chrome.R; |
30 | 37 |
31 import java.util.Calendar; | 38 import java.util.Calendar; |
32 | 39 |
33 /** | 40 /** |
34 * A prompt that bugs users to enter their CVC when unmasking a Wallet instrumen t (credit card). | 41 * A prompt that bugs users to enter their CVC when unmasking a Wallet instrumen t (credit card). |
35 */ | 42 */ |
36 public class CardUnmaskPrompt implements DialogInterface.OnDismissListener, Text Watcher { | 43 public class CardUnmaskPrompt |
44 implements DialogInterface.OnDismissListener, TextWatcher, OnLongClickLi stener { | |
37 private final CardUnmaskPromptDelegate mDelegate; | 45 private final CardUnmaskPromptDelegate mDelegate; |
38 private final AlertDialog mDialog; | 46 private final AlertDialog mDialog; |
39 private final boolean mShouldRequestExpirationDate; | 47 private final boolean mShouldRequestExpirationDate; |
40 private final int mThisYear; | 48 private final int mThisYear; |
41 | 49 |
50 private final View mMainView; | |
42 private final TextView mNoRetryErrorMessage; | 51 private final TextView mNoRetryErrorMessage; |
43 private final EditText mCardUnmaskInput; | 52 private final EditText mCardUnmaskInput; |
44 private final EditText mMonthInput; | 53 private final EditText mMonthInput; |
45 private final EditText mYearInput; | 54 private final EditText mYearInput; |
46 private final View mExpirationContainer; | 55 private final View mExpirationContainer; |
47 private final TextView mErrorMessage; | 56 private final TextView mErrorMessage; |
48 private final CheckBox mStoreLocallyCheckbox; | 57 private final CheckBox mStoreLocallyCheckbox; |
58 private final ImageView mStoreLocallyTooltipIcon; | |
59 private PopupWindow mStoreLocallyTooltipPopup; | |
49 private final ViewGroup mMainContents; | 60 private final ViewGroup mMainContents; |
50 private final View mVerificationOverlay; | 61 private final View mVerificationOverlay; |
51 private final ProgressBar mVerificationProgressBar; | 62 private final ProgressBar mVerificationProgressBar; |
52 private final TextView mVerificationView; | 63 private final TextView mVerificationView; |
53 | 64 |
54 /** | 65 /** |
55 * An interface to handle the interaction with an CardUnmaskPrompt object. | 66 * An interface to handle the interaction with an CardUnmaskPrompt object. |
56 */ | 67 */ |
57 public interface CardUnmaskPromptDelegate { | 68 public interface CardUnmaskPromptDelegate { |
58 /** | 69 /** |
(...skipping 19 matching lines...) Expand all Loading... | |
78 | 89 |
79 public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate, String title, | 90 public CardUnmaskPrompt(Context context, CardUnmaskPromptDelegate delegate, String title, |
80 String instructions, int drawableId, boolean shouldRequestExpiration Date, | 91 String instructions, int drawableId, boolean shouldRequestExpiration Date, |
81 boolean defaultToStoringLocally) { | 92 boolean defaultToStoringLocally) { |
82 mDelegate = delegate; | 93 mDelegate = delegate; |
83 | 94 |
84 LayoutInflater inflater = LayoutInflater.from(context); | 95 LayoutInflater inflater = LayoutInflater.from(context); |
85 View v = inflater.inflate(R.layout.autofill_card_unmask_prompt, null); | 96 View v = inflater.inflate(R.layout.autofill_card_unmask_prompt, null); |
86 ((TextView) v.findViewById(R.id.instructions)).setText(instructions); | 97 ((TextView) v.findViewById(R.id.instructions)).setText(instructions); |
87 | 98 |
99 mMainView = v; | |
88 mNoRetryErrorMessage = (TextView) v.findViewById(R.id.no_retry_error_mes sage); | 100 mNoRetryErrorMessage = (TextView) v.findViewById(R.id.no_retry_error_mes sage); |
89 mCardUnmaskInput = (EditText) v.findViewById(R.id.card_unmask_input); | 101 mCardUnmaskInput = (EditText) v.findViewById(R.id.card_unmask_input); |
90 mMonthInput = (EditText) v.findViewById(R.id.expiration_month); | 102 mMonthInput = (EditText) v.findViewById(R.id.expiration_month); |
91 mYearInput = (EditText) v.findViewById(R.id.expiration_year); | 103 mYearInput = (EditText) v.findViewById(R.id.expiration_year); |
92 mExpirationContainer = v.findViewById(R.id.expiration_container); | 104 mExpirationContainer = v.findViewById(R.id.expiration_container); |
93 mErrorMessage = (TextView) v.findViewById(R.id.error_message); | 105 mErrorMessage = (TextView) v.findViewById(R.id.error_message); |
94 mStoreLocallyCheckbox = (CheckBox) v.findViewById(R.id.store_locally_che ckbox); | 106 mStoreLocallyCheckbox = (CheckBox) v.findViewById(R.id.store_locally_che ckbox); |
95 mStoreLocallyCheckbox.setChecked(defaultToStoringLocally); | 107 mStoreLocallyCheckbox.setChecked(defaultToStoringLocally); |
108 mStoreLocallyTooltipIcon = (ImageView) v.findViewById(R.id.store_locally _tooltip_icon); | |
109 mStoreLocallyTooltipIcon.setOnLongClickListener(this); | |
96 mMainContents = (ViewGroup) v.findViewById(R.id.main_contents); | 110 mMainContents = (ViewGroup) v.findViewById(R.id.main_contents); |
97 mVerificationOverlay = v.findViewById(R.id.verification_overlay); | 111 mVerificationOverlay = v.findViewById(R.id.verification_overlay); |
98 mVerificationProgressBar = (ProgressBar) v.findViewById(R.id.verificatio n_progress_bar); | 112 mVerificationProgressBar = (ProgressBar) v.findViewById(R.id.verificatio n_progress_bar); |
99 mVerificationView = (TextView) v.findViewById(R.id.verification_message) ; | 113 mVerificationView = (TextView) v.findViewById(R.id.verification_message) ; |
100 ((ImageView) v.findViewById(R.id.cvc_hint_image)).setImageResource(drawa bleId); | 114 ((ImageView) v.findViewById(R.id.cvc_hint_image)).setImageResource(drawa bleId); |
101 | 115 |
102 mDialog = new AlertDialog.Builder(context) | 116 mDialog = new AlertDialog.Builder(context) |
103 .setTitle(title) | 117 .setTitle(title) |
104 .setView(v) | 118 .setView(v) |
105 .setNegativeButton(R.string.cancel, null) | 119 .setNegativeButton(R.string.cancel, null) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 public void afterTextChanged(Editable s) { | 207 public void afterTextChanged(Editable s) { |
194 mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(areInputsValid ()); | 208 mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(areInputsValid ()); |
195 } | 209 } |
196 | 210 |
197 @Override | 211 @Override |
198 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) {} | 212 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) {} |
199 | 213 |
200 @Override | 214 @Override |
201 public void onTextChanged(CharSequence s, int start, int before, int count) {} | 215 public void onTextChanged(CharSequence s, int start, int before, int count) {} |
202 | 216 |
217 @Override | |
218 public boolean onLongClick(View v) { | |
219 assert v == mStoreLocallyTooltipIcon; | |
220 if (mStoreLocallyTooltipPopup == null) { | |
221 mStoreLocallyTooltipPopup = new PopupWindow(mDialog.getContext()); | |
222 TextView text = new TextView(mDialog.getContext()); | |
223 text.setText(R.string.autofill_card_unmask_prompt_storage_tooltip); | |
224 // Width is the dialog's width less the margins and padding around t he checkbox and | |
225 // icon. | |
226 text.setWidth(mMainView.getWidth() - ViewCompat.getPaddingStart(mSto reLocallyCheckbox) | |
227 - ViewCompat.getPaddingEnd(mStoreLocallyTooltipIcon) | |
228 - MarginLayoutParamsCompat.getMarginStart((RelativeLayout.La youtParams) | |
229 mStoreLocallyCheckbox.getLayoutParams()) | |
230 - MarginLayoutParamsCompat.getMarginEnd((RelativeLayout.Layo utParams) | |
231 mStoreLocallyTooltipIcon.getLayoutParams())); | |
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); | |
newt (away)
2015/03/09 20:53:56
crash :/
Evan Stade
2015/03/09 21:23:28
Done.
| |
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 Loading... | |
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 } |
OLD | NEW |