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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java

Issue 2286563002: Add credit card scanner to payments UI. (Closed)
Patch Set: Rename flag to match histograms.xml Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
index 87aba70c6025289dd75736f2134ada7542302fe5..e9e7a9bdb24f958a355d957d08d7ea74dd19df2e 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
@@ -11,6 +11,8 @@ import android.util.Pair;
import org.chromium.base.Callback;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ChromeFeatureList;
+import org.chromium.chrome.browser.autofill.CreditCardScanner;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
@@ -19,6 +21,7 @@ import org.chromium.chrome.browser.payments.ui.EditorFieldModel;
import org.chromium.chrome.browser.payments.ui.EditorFieldModel.EditorFieldValidator;
import org.chromium.chrome.browser.payments.ui.EditorModel;
import org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue;
+import org.chromium.content.browser.ContentViewCore;
import org.chromium.content_public.browser.WebContents;
import java.text.SimpleDateFormat;
@@ -39,7 +42,8 @@ import javax.annotation.Nullable;
* A credit card editor. Can be used for editing both local and server credit cards. Everything in
* local cards can be edited. For server cards, only the billing address is editable.
*/
-public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
+public class CardEditor extends EditorBase<AutofillPaymentInstrument>
+ implements CreditCardScanner.Delegate {
/** Description of a card type. */
private static class CardTypeInfo {
/** The identifier for the drawable resource of the card type, e.g., R.drawable.pr_visa. */
@@ -61,7 +65,7 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
this.icon = icon;
this.description = description;
}
- };
+ }
/** The dropdown key that indicates absence of billing address. */
private static final String BILLING_ADDRESS_NONE = "";
@@ -115,6 +119,9 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
@Nullable private EditorFieldModel mYearField;
@Nullable private EditorFieldModel mBillingAddressField;
@Nullable private EditorFieldModel mSaveCardCheckbox;
+ @Nullable private CreditCardScanner mCardScanner;
+ private boolean mCanScan;
+ private boolean mIsScanning;
/**
* Builds a credit card editor.
@@ -331,7 +338,7 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
* Adds the following fields to the editor.
*
* [ accepted card types hint images ]
- * [ card number ]
+ * [ card number [ocr icon] ]
* [ name on card ]
* [ expiration month ][ expiration year ]
*/
@@ -350,6 +357,15 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
}
editor.addField(mIconHint);
+ // Card scanner is expensive to query.
+ if (mCardScanner == null
+ && ChromeFeatureList.isEnabled(ChromeFeatureList.SCAN_CARDS_IN_WEB_PAYMENTS)) {
+ mCardScanner = CreditCardScanner.create(mContext,
+ ContentViewCore.fromWebContents(mWebContents).getWindowAndroid(),
+ this);
+ mCanScan = mCardScanner.canScan();
+ }
+
// Card number is validated.
if (mNumberField == null) {
mNumberField = EditorFieldModel.createTextInput(
@@ -359,6 +375,17 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
mContext.getString(R.string.payments_field_required_validation_message),
mContext.getString(R.string.payments_card_number_invalid_validation_message),
null);
+ if (mCanScan) {
+ mNumberField.addActionIcon(R.drawable.ic_photo_camera,
+ R.string.autofill_scan_credit_card, new Runnable() {
+ @Override
+ public void run() {
+ if (mIsScanning) return;
+ mIsScanning = true;
+ mCardScanner.scan();
+ }
+ });
+ }
}
mNumberField.setValue(card.getNumber());
editor.addField(mNumberField);
@@ -406,7 +433,7 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
List<DropdownKeyValue> result = new ArrayList<>();
Locale locale = Locale.getDefault();
- SimpleDateFormat keyFormatter = new SimpleDateFormat("MM", locale);
+ SimpleDateFormat keyFormatter = new SimpleDateFormat("M", locale);
SimpleDateFormat valueFormatter = new SimpleDateFormat("MMMM (MM)", locale);
calendar.set(Calendar.DAY_OF_MONTH, 1);
@@ -564,4 +591,24 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> {
card.setGUID(pdm.setCreditCard(card));
}
}
+
+ @Override
+ public void onScanCompleted(
+ String cardHolderName, String cardNumber, int expirationMonth, int expirationYear) {
+ if (!TextUtils.isEmpty(cardHolderName)) mNameField.setValue(cardHolderName);
+ if (!TextUtils.isEmpty(cardNumber)) mNumberField.setValue(cardNumber);
+ if (expirationYear >= 2000) mYearField.setValue(Integer.toString(expirationYear));
+
+ if (expirationMonth >= 1 && expirationMonth <= 12) {
+ mMonthField.setValue(Integer.toString(expirationMonth));
+ }
+
+ mEditorView.update();
+ mIsScanning = false;
+ }
+
+ @Override
+ public void onScanCancelled() {
+ mIsScanning = false;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698