Java Code Examples for org.chromium.chrome.browser.autofill.PersonalDataManager#getInstance()
The following examples show how to use
org.chromium.chrome.browser.autofill.PersonalDataManager#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutofillPaymentApp.java From delion with Apache License 2.0 | 6 votes |
@Override public void getInstruments(JSONObject unusedDetails, final InstrumentsCallback callback) { PersonalDataManager pdm = PersonalDataManager.getInstance(); List<CreditCard> cards = pdm.getCreditCardsToSuggest(); final List<PaymentInstrument> instruments = new ArrayList<>(cards.size()); for (int i = 0; i < cards.size(); i++) { CreditCard card = cards.get(i); AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId()) ? null : pdm.getProfile(card.getBillingAddressId()); instruments.add(new AutofillPaymentInstrument(mWebContents, card, billingAddress)); } new Handler().post(new Runnable() { @Override public void run() { callback.onInstrumentsReady(AutofillPaymentApp.this, instruments); } }); }
Example 2
Source File: AutofillLocalCardEditor.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override protected boolean saveEntry() { // Remove all spaces in editText. String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", ""); PersonalDataManager personalDataManager = PersonalDataManager.getInstance(); // Card Payment Type will be empty if credit card number is not valid. if (TextUtils.isEmpty(personalDataManager.getBasicCardPaymentType(cardNumber, true /* emptyIfInvalid */))) { mNumberLabel.setError(mContext.getString( R.string.payments_card_number_invalid_validation_message)); return false; } CreditCard card = new CreditCard(mGUID, AutofillPreferences.SETTINGS_ORIGIN, true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(), cardNumber, "" /* obfuscatedNumber */, String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1), (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */, 0 /* issuerIconDrawableId */, ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */, "" /* serverId */); personalDataManager.setCreditCard(card); return true; }
Example 3
Source File: AutofillLocalCardEditor.java From 365browser with Apache License 2.0 | 6 votes |
@Override protected boolean saveEntry() { // Remove all spaces in editText. String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", ""); PersonalDataManager personalDataManager = PersonalDataManager.getInstance(); // Issuer network will be empty if credit card number is not valid. if (TextUtils.isEmpty(personalDataManager.getBasicCardIssuerNetwork( cardNumber, true /* emptyIfInvalid */))) { mNumberLabel.setError(mContext.getString( R.string.payments_card_number_invalid_validation_message)); return false; } CreditCard card = new CreditCard(mGUID, AutofillAndPaymentsPreferences.SETTINGS_ORIGIN, true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(), cardNumber, "" /* obfuscatedNumber */, String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1), (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */, 0 /* issuerIconDrawableId */, ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */, "" /* serverId */); personalDataManager.setCreditCard(card); return true; }
Example 4
Source File: AddressEditor.java From delion with Apache License 2.0 | 5 votes |
/** Saves the edited profile on disk. */ private void commitChanges(AutofillProfile profile) { // Country code and phone number are always required and are always collected from the // editor model. profile.setCountryCode(mCountryField.getValue().toString()); profile.setPhoneNumber(mPhoneField.getValue().toString()); // Autofill profile bridge normalizes the language code for the autofill profile. profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode()); // Collect data from all visible fields and store it in the autofill profile. Set<Integer> visibleFields = new HashSet<>(); for (int i = 0; i < mAddressUiComponents.size(); i++) { AddressUiComponent component = mAddressUiComponents.get(i); visibleFields.add(component.id); if (component.id != AddressField.COUNTRY) { setProfileField(profile, component.id, mAddressFields.get(component.id).getValue()); } } // Clear the fields that are hidden from the user interface, so // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings. for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) { if (!visibleFields.contains(entry.getKey())) { setProfileField(profile, entry.getKey(), ""); } } // Calculate the label for this profile. The label's format depends on the country and // language code for the profile. PersonalDataManager pmd = PersonalDataManager.getInstance(); profile.setLabel(pmd.getGetAddressLabelForPaymentRequest(profile)); // Save the edited autofill profile. pmd.setProfile(profile); }
Example 5
Source File: CardEditor.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Saves the edited credit card. * * If this is a server card, then only its billing address identifier is updated. * * If this is a new local card, then it's saved on this device only if the user has checked the * "save this card" checkbox. */ private void commitChanges(CreditCard card, boolean isNewCard) { card.setBillingAddressId(mBillingAddressField.getValue().toString()); PersonalDataManager pdm = PersonalDataManager.getInstance(); if (!card.getIsLocal()) { pdm.updateServerCardBillingAddress(card.getServerId(), card.getBillingAddressId()); return; } card.setNumber(mNumberField.getValue().toString().replace(" ", "").replace("-", "")); card.setName(mNameField.getValue().toString()); card.setMonth(mMonthField.getValue().toString()); card.setYear(mYearField.getValue().toString()); // Calculate the basic card payment type, obfuscated number, and the icon for this card. // All of these depend on the card number. The type is sent to the merchant website. The // obfuscated number and the icon are displayed in the user interface. CreditCard displayableCard = pdm.getCreditCardForNumber(card.getNumber()); card.setBasicCardPaymentType(displayableCard.getBasicCardPaymentType()); card.setObfuscatedNumber(displayableCard.getObfuscatedNumber()); card.setIssuerIconDrawableId(displayableCard.getIssuerIconDrawableId()); if (!isNewCard) { pdm.setCreditCard(card); return; } if (mSaveCardCheckbox != null && mSaveCardCheckbox.isChecked()) { card.setGUID(pdm.setCreditCard(card)); } }
Example 6
Source File: AutofillPaymentApp.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void getInstruments( Map<String, PaymentMethodData> unusedMethodData, final InstrumentsCallback callback) { PersonalDataManager pdm = PersonalDataManager.getInstance(); List<CreditCard> cards = pdm.getCreditCardsToSuggest(); final List<PaymentInstrument> instruments = new ArrayList<>(cards.size()); for (int i = 0; i < cards.size(); i++) { CreditCard card = cards.get(i); AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId()) ? null : pdm.getProfile(card.getBillingAddressId()); if (billingAddress != null && AutofillAddress.checkAddressCompletionStatus(billingAddress) != AutofillAddress.COMPLETE) { billingAddress = null; } instruments.add(new AutofillPaymentInstrument(mContext, mWebContents, card, billingAddress)); } new Handler().post(new Runnable() { @Override public void run() { callback.onInstrumentsReady(AutofillPaymentApp.this, instruments); } }); }
Example 7
Source File: AddressEditor.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** Saves the edited profile on disk. */ private void commitChanges(AutofillProfile profile) { // Country code and phone number are always required and are always collected from the // editor model. profile.setCountryCode(mCountryField.getValue().toString()); profile.setPhoneNumber(mPhoneField.getValue().toString()); // Autofill profile bridge normalizes the language code for the autofill profile. profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode()); // Collect data from all visible fields and store it in the autofill profile. Set<Integer> visibleFields = new HashSet<>(); for (int i = 0; i < mAddressUiComponents.size(); i++) { AddressUiComponent component = mAddressUiComponents.get(i); visibleFields.add(component.id); if (component.id != AddressField.COUNTRY) { setProfileField(profile, component.id, mAddressFields.get(component.id).getValue()); } } // Clear the fields that are hidden from the user interface, so // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings. for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) { if (!visibleFields.contains(entry.getKey())) { setProfileField(profile, entry.getKey(), ""); } } // Calculate the label for this profile. The label's format depends on the country and // language code for the profile. PersonalDataManager pdm = PersonalDataManager.getInstance(); // TODO(crbug.com/666048): New billing address label is wrong. profile.setLabel(pdm.getAddressLabelForPaymentRequest(profile)); // Save the edited autofill profile locally. profile.setGUID(pdm.setProfileToLocal(profile)); profile.setIsLocal(true); }
Example 8
Source File: CardEditor.java From 365browser with Apache License 2.0 | 5 votes |
/** * Saves the edited credit card. * * If this is a server card, then only its billing address identifier is updated. * * If this is a new local card, then it's saved on this device only if the user has checked the * "save this card" checkbox. */ private void commitChanges(CreditCard card, boolean isNewCard) { card.setBillingAddressId(mBillingAddressField.getValue().toString()); PersonalDataManager pdm = PersonalDataManager.getInstance(); if (!card.getIsLocal()) { pdm.updateServerCardBillingAddress(card); return; } card.setNumber(removeSpaceAndBar(mNumberField.getValue())); card.setName(mNameField.getValue().toString()); card.setMonth(mMonthField.getValue().toString()); card.setYear(mYearField.getValue().toString()); // Calculate the basic card issuer network, obfuscated number, and the icon for this card. // All of these depend on the card number. The issuer network is sent to the merchant // website. The obfuscated number and the icon are displayed in the user interface. CreditCard displayableCard = pdm.getCreditCardForNumber(card.getNumber()); card.setBasicCardIssuerNetwork(displayableCard.getBasicCardIssuerNetwork()); card.setObfuscatedNumber(displayableCard.getObfuscatedNumber()); card.setIssuerIconDrawableId(displayableCard.getIssuerIconDrawableId()); if (!isNewCard) { pdm.setCreditCard(card); return; } if (mSaveCardCheckbox != null && mSaveCardCheckbox.isChecked()) { card.setGUID(pdm.setCreditCard(card)); } }
Example 9
Source File: AutofillPaymentApp.java From 365browser with Apache License 2.0 | 4 votes |
@Override public void getInstruments(Map<String, PaymentMethodData> methodDataMap, String unusedOrigin, String unusedIFRameOrigin, byte[][] unusedCertificateChain, PaymentItem unusedTotal, final InstrumentsCallback callback) { PersonalDataManager pdm = PersonalDataManager.getInstance(); List<CreditCard> cards = pdm.getCreditCardsToSuggest(); final List<PaymentInstrument> instruments = new ArrayList<>(cards.size()); Set<String> basicCardSupportedNetworks = convertBasicCardToNetworks(methodDataMap.get(BASIC_CARD_METHOD_NAME)); for (int i = 0; i < cards.size(); i++) { CreditCard card = cards.get(i); AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId()) ? null : pdm.getProfile(card.getBillingAddressId()); if (billingAddress != null && AutofillAddress.checkAddressCompletionStatus( billingAddress, AutofillAddress.IGNORE_PHONE_COMPLETENESS_CHECK) != AutofillAddress.COMPLETE) { billingAddress = null; } if (billingAddress == null) card.setBillingAddressId(null); String methodName = null; if (basicCardSupportedNetworks != null && basicCardSupportedNetworks.contains(card.getBasicCardIssuerNetwork())) { methodName = BASIC_CARD_METHOD_NAME; } else if (methodDataMap.containsKey(card.getBasicCardIssuerNetwork())) { methodName = card.getBasicCardIssuerNetwork(); } if (methodName != null) { instruments.add(new AutofillPaymentInstrument( mWebContents, card, billingAddress, methodName)); } } new Handler().post(new Runnable() { @Override public void run() { callback.onInstrumentsReady(AutofillPaymentApp.this, instruments); } }); }