Commit 1089ca59 authored by dfalcantara's avatar dfalcantara Committed by Commit bot

[Payments] Add ability to bold parts of addresses

* Add the ability to bold parts of a label.

* Add the ability to show a tertiary label in the PaymentOption, which
  will later be used for phone number display.

* The phone number is passed in to the PaymentOption using the new constructor
  via the AutofillAddress class.

See crbug.com/626833 for screenshots.

BUG=603635,626833

Committed: https://crrev.com/92f4c6ac21b2578ab3938c5bd3eb0f793621164f
Review-Url: https://codereview.chromium.org/2135573004
Cr-Original-Commit-Position: refs/heads/master@{#405900}
Cr-Commit-Position: refs/heads/master@{#406062}
parent 28070b59
......@@ -40,7 +40,8 @@ public class AutofillAddress extends PaymentOption {
* @param profile The autofill profile containing the address information.
*/
public AutofillAddress(AutofillProfile profile, boolean isComplete) {
super(profile.getGUID(), profile.getFullName(), profile.getLabel(), PaymentOption.NO_ICON);
super(profile.getGUID(), profile.getFullName(), profile.getLabel(),
profile.getPhoneNumber(), PaymentOption.NO_ICON);
mProfile = profile;
mIsComplete = isComplete;
}
......@@ -52,14 +53,15 @@ public class AutofillAddress extends PaymentOption {
/**
* Updates the address and marks it "complete." Called after the user has edited this address.
* Updates the identifier, label, and sublabel.
* Updates the identifier and labels.
*
* @param profile The new profile to use.
*/
public void completeAddress(AutofillProfile profile) {
mProfile = profile;
mIsComplete = true;
updateIdentifierAndLabels(mProfile.getGUID(), mProfile.getFullName(), mProfile.getLabel());
updateIdentifierAndLabels(mProfile.getGUID(), mProfile.getFullName(), mProfile.getLabel(),
mProfile.getPhoneNumber());
}
/** @return The country code to use, e.g., when constructing an editor for this address. */
......
......@@ -160,7 +160,7 @@ public class AutofillPaymentInstrument
mBillingAddress = billingAddress;
mIsComplete = true;
updateIdentifierLabelsAndIcon(card.getGUID(), card.getObfuscatedNumber(), card.getName(),
card.getIssuerIconDrawableId());
null, card.getIssuerIconDrawableId());
}
/** @return The credit card represented by this payment instrument. */
......
......@@ -16,24 +16,27 @@ public class PaymentOption implements Completable {
protected boolean mIsComplete;
private String mId;
@Nullable private String mLabel;
@Nullable private String mSublabel;
private int mIcon;
private String[] mLabels = {null, null, null};
private boolean mIsValid = true;
/** See {@link #PaymentOption(String, String, String, String, int)}. */
public PaymentOption(String id, @Nullable String label, @Nullable String sublabel, int icon) {
this(id, label, sublabel, null, icon);
}
/**
* Constructs a payment option.
*
* @param id The identifier.
* @param label The label.
* @param sublabel The optional sublabel.
* @param icon The drawable icon identifier or NO_ICON.
* @param id The identifier.
* @param label The label.
* @param sublabel The optional sublabel.
* @param tertiarylabel The optional tertiary label.
* @param icon The drawable icon identifier or NO_ICON.
*/
public PaymentOption(String id, @Nullable String label, @Nullable String sublabel, int icon) {
mId = id;
mLabel = label;
mSublabel = sublabel;
mIcon = icon;
public PaymentOption(String id, @Nullable String label, @Nullable String sublabel,
@Nullable String tertiarylabel, int icon) {
updateIdentifierLabelsAndIcon(id, label, sublabel, tertiarylabel, icon);
}
@Override
......@@ -53,42 +56,51 @@ public class PaymentOption implements Completable {
* The primary label of this option. For example, “Visa***1234” or "2-day shipping".
*/
@Nullable public String getLabel() {
return mLabel;
return mLabels[0];
}
/**
* The optional sublabel of this option. For example, “Expiration date: 12/2025”.
*/
@Nullable public String getSublabel() {
return mSublabel;
return mLabels[1];
}
/**
* Updates the identifier, label, and sublabel of this option. Called after the user has edited
* this option.
*
* @param id The new id to use. Should not be null.
* @param label The new label to use. Should not be null.
* @param sublabel The new sublabel to use. Can be null.
* The optional tertiary label of this option. For example, "(555) 867-5309".
*/
@Nullable public String getTertiaryLabel() {
return mLabels[2];
}
/** See {@link #updateIdentifierAndLabels(String, String, String, String)}. */
protected void updateIdentifierAndLabels(String id, String label, @Nullable String sublabel) {
updateIdentifierLabelsAndIcon(id, label, sublabel, mIcon);
updateIdentifierAndLabels(id, label, sublabel, null);
}
/** See {@link #updateIdentifierLabelsAndIcon(String, String, String, String, int)}. */
protected void updateIdentifierAndLabels(
String id, String label, @Nullable String sublabel, @Nullable String tertiarylabel) {
mId = id;
mLabels[0] = label;
mLabels[1] = sublabel;
mLabels[2] = tertiarylabel;
}
/**
* Updates the identifier, label, sublabel, and icon of this option. Called after the user has
* Updates the identifier, labels, and icon of this option. Called after the user has
* edited this option.
*
* @param id The new id to use. Should not be null.
* @param label The new label to use. Should not be null.
* @param sublabel The new sublabel to use. Can be null.
* @param icon The drawable icon identifier or NO_ICON.
* @param id The new id to use. Should not be null.
* @param label The new label to use. Should not be null.
* @param sublabel The new sublabel to use. Can be null.
* @param tertiarylabel The new tertiary label to use. Can be null.
* @param icon The drawable icon identifier or NO_ICON.
*/
protected void updateIdentifierLabelsAndIcon(
String id, String label, @Nullable String sublabel, int icon) {
mId = id;
mLabel = label;
mSublabel = sublabel;
String id, String label, @Nullable String sublabel, @Nullable String tertiarylabel,
int icon) {
updateIdentifierAndLabels(id, label, sublabel, tertiarylabel);
mIcon = icon;
}
......
......@@ -83,6 +83,9 @@ public abstract class PaymentRequestSection extends LinearLayout {
/** Called when the user requests adding a new PaymentOption to a given section. */
void onAddPaymentOption(OptionSection section);
/** Checks whether or not the text should be formatted with a bold label. */
boolean isBoldLabelNeeded(OptionSection section);
/** Checks whether or not the user should be allowed to click on controls. */
boolean isAcceptingUserInput();
......@@ -650,7 +653,8 @@ public abstract class PaymentRequestSection extends LinearLayout {
ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled
? R.style.PaymentsUiSectionDefaultText
: R.style.PaymentsUiSectionDisabledText);
labelView.setText(convertOptionToString(mOption));
labelView.setText(convertOptionToString(
mOption, mDelegate.isBoldLabelNeeded(OptionSection.this)));
labelView.setEnabled(isEnabled);
} else if (mRowType == OPTION_ROW_TYPE_ADD) {
// Shows string saying that the user can add a new option, e.g. credit card no.
......@@ -861,7 +865,7 @@ public abstract class PaymentRequestSection extends LinearLayout {
}
} else {
setLogoResource(selectedItem.getDrawableIconId());
setSummaryText(convertOptionToString(selectedItem), null);
setSummaryText(convertOptionToString(selectedItem, false), null);
}
}
......@@ -913,9 +917,24 @@ public abstract class PaymentRequestSection extends LinearLayout {
}
}
private CharSequence convertOptionToString(PaymentOption item) {
if (TextUtils.isEmpty(item.getSublabel())) return item.getLabel();
return new StringBuilder(item.getLabel()).append("\n").append(item.getSublabel());
private CharSequence convertOptionToString(PaymentOption item, boolean useBoldLabel) {
SpannableStringBuilder builder = new SpannableStringBuilder(item.getLabel());
if (useBoldLabel) {
builder.setSpan(
new StyleSpan(android.graphics.Typeface.BOLD), 0, builder.length(), 0);
}
if (!TextUtils.isEmpty(item.getSublabel())) {
if (builder.length() > 0) builder.append("\n");
builder.append(item.getSublabel());
}
if (!TextUtils.isEmpty(item.getTertiaryLabel())) {
if (builder.length() > 0) builder.append("\n");
builder.append(item.getTertiaryLabel());
}
return builder;
}
/**
......
......@@ -620,6 +620,11 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
updatePayButtonEnabled();
}
@Override
public boolean isBoldLabelNeeded(OptionSection section) {
return section == mShippingAddressSection;
}
/** @return The common editor user interface. */
public EditorView getEditorView() {
return mEditorView;
......
......@@ -383,7 +383,6 @@ PersonalDataManagerAndroid::GetAddressLabelForPaymentRequest(
label_fields.push_back(ADDRESS_HOME_ZIP);
label_fields.push_back(ADDRESS_HOME_SORTING_CODE);
label_fields.push_back(ADDRESS_HOME_COUNTRY);
label_fields.push_back(PHONE_HOME_WHOLE_NUMBER);
AutofillProfile profile;
PopulateNativeProfileFromJava(jprofile, env, &profile);
......@@ -629,7 +628,6 @@ ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileLabels(
suggested_fields->push_back(ADDRESS_HOME_ZIP);
suggested_fields->push_back(ADDRESS_HOME_SORTING_CODE);
suggested_fields->push_back(ADDRESS_HOME_COUNTRY);
suggested_fields->push_back(PHONE_HOME_WHOLE_NUMBER);
minimal_fields_shown = suggested_fields->size();
}
......
......@@ -61,8 +61,8 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
// Gets the labels for the profiles to suggest to the user. These labels are
// useful for distinguishing the profiles from one another.
//
// The labels never contain the full name or email address. All other fields
// are included in the label.
// The labels never contain the full name, email address, or phone numbers.
// All other fields are included in the label.
base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabelsToSuggest(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& unused_obj);
......@@ -221,8 +221,8 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
//
// The labels never contain the full name and include at least 2 fields.
//
// If |address_only| is true, then such fields as phone number and email
// address are also omitted, but all fields are included in the label.
// If |address_only| is true, then such fields as phone number, and email
// address are also omitted, but all other fields are included in the label.
base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels(
JNIEnv* env,
bool address_only,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment