Commit 8273a338 authored by siashah's avatar siashah Committed by Commit Bot

Add item tag to autofill dropdrown item

This change is no-op as we are always creating the autofill suggestion
setting the itemTag to an empty string which'd result in the itemTag
text view's visibility to be set to GONE.

In a follow-up CL, we'll add the itemTag parameter to the
AutofillPopupBridge and populate the autofill suggestion with it. This
will be used to display the offer text in the autofill dropdown.

Bug: 1112095
Change-Id: Idbbc08565a4911d76264f3fc33e688228601e5b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2350147Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Commit-Queue: Siddharth Shah <siashah@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798306}
parent 77c5e475
...@@ -99,7 +99,7 @@ public class AwAutofillClient { ...@@ -99,7 +99,7 @@ public class AwAutofillClient {
@CalledByNative @CalledByNative
private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index, private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
String name, String label, int uniqueId) { String name, String label, int uniqueId) {
array[index] = new AutofillSuggestion(name, label, DropdownItem.NO_ICON, array[index] = new AutofillSuggestion(name, label, /* itemTag= */ "", DropdownItem.NO_ICON,
false /* isIconAtLeft */, uniqueId, false /* isDeletable */, false /* isIconAtLeft */, uniqueId, false /* isDeletable */,
false /* isMultilineLabel */, false /* isBoldLabel */); false /* isMultilineLabel */, false /* isBoldLabel */);
} }
......
...@@ -154,7 +154,7 @@ public class AutofillKeyboardAccessoryViewBridge ...@@ -154,7 +154,7 @@ public class AutofillKeyboardAccessoryViewBridge
private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index, private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
String label, String sublabel, int iconId, int suggestionId, boolean isDeletable) { String label, String sublabel, int iconId, int suggestionId, boolean isDeletable) {
int drawableId = iconId == 0 ? DropdownItem.NO_ICON : iconId; int drawableId = iconId == 0 ? DropdownItem.NO_ICON : iconId;
array[index] = new AutofillSuggestion(label, sublabel, drawableId, array[index] = new AutofillSuggestion(label, sublabel, /* itemTag= */ "", drawableId,
false /* isIconAtStart */, suggestionId, isDeletable, false /* isMultilineLabel */, false /* isIconAtStart */, suggestionId, isDeletable, false /* isMultilineLabel */,
false /* isBoldLabel */); false /* isBoldLabel */);
} }
......
...@@ -248,7 +248,7 @@ public class KeyboardAccessoryModernViewTest { ...@@ -248,7 +248,7 @@ public class KeyboardAccessoryModernViewTest {
@MediumTest @MediumTest
public void testDismissesPasswordEducationBubbleOnFilling() { public void testDismissesPasswordEducationBubbleOnFilling() {
AutofillBarItem itemWithIPH = AutofillBarItem itemWithIPH =
new AutofillBarItem(new AutofillSuggestion("Johnathan", "Smith", new AutofillBarItem(new AutofillSuggestion("Johnathan", "Smith", /*itemTag=*/"",
DropdownItem.NO_ICON, false, -2, false, false, false), DropdownItem.NO_ICON, false, -2, false, false, false),
new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {})); new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {}));
itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_PASSWORD_FILLING_FEATURE); itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_PASSWORD_FILLING_FEATURE);
...@@ -276,7 +276,7 @@ public class KeyboardAccessoryModernViewTest { ...@@ -276,7 +276,7 @@ public class KeyboardAccessoryModernViewTest {
@MediumTest @MediumTest
public void testDismissesAddressEducationBubbleOnFilling() { public void testDismissesAddressEducationBubbleOnFilling() {
AutofillBarItem itemWithIPH = AutofillBarItem itemWithIPH =
new AutofillBarItem(new AutofillSuggestion("Johnathan", "Smith", new AutofillBarItem(new AutofillSuggestion("Johnathan", "Smith", /*itemTag=*/"",
DropdownItem.NO_ICON, false, 1, false, false, false), DropdownItem.NO_ICON, false, 1, false, false, false),
new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {})); new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {}));
itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_ADDRESS_FILL_FEATURE); itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_ADDRESS_FILL_FEATURE);
...@@ -302,8 +302,8 @@ public class KeyboardAccessoryModernViewTest { ...@@ -302,8 +302,8 @@ public class KeyboardAccessoryModernViewTest {
@MediumTest @MediumTest
public void testDismissesPaymentEducationBubbleOnFilling() { public void testDismissesPaymentEducationBubbleOnFilling() {
AutofillBarItem itemWithIPH = new AutofillBarItem( AutofillBarItem itemWithIPH = new AutofillBarItem(
new AutofillSuggestion("Johnathan", "Smith", DropdownItem.NO_ICON, false, 70000, new AutofillSuggestion("Johnathan", "Smith", /*itemTag=*/"", DropdownItem.NO_ICON,
false, false, false), false, 70000, false, false, false),
new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {})); new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {}));
itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_PAYMENT_FILLING_FEATURE); itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_PAYMENT_FILLING_FEATURE);
...@@ -358,8 +358,8 @@ public class KeyboardAccessoryModernViewTest { ...@@ -358,8 +358,8 @@ public class KeyboardAccessoryModernViewTest {
private BarItem[] createAutofillChipAndTab(String label, Callback<Action> chipCallback) { private BarItem[] createAutofillChipAndTab(String label, Callback<Action> chipCallback) {
return new BarItem[] { return new BarItem[] {
new AutofillBarItem(new AutofillSuggestion(label, "Smith", DropdownItem.NO_ICON, new AutofillBarItem(new AutofillSuggestion(label, "Smith", /*itemTag=*/"",
false, 1, false, false, false), DropdownItem.NO_ICON, false, 1, false, false, false),
new KeyboardAccessoryData.Action( new KeyboardAccessoryData.Action(
"Unused", AUTOFILL_SUGGESTION, chipCallback)), "Unused", AUTOFILL_SUGGESTION, chipCallback)),
createTabs()}; createTabs()};
......
...@@ -246,10 +246,10 @@ public class KeyboardAccessoryControllerTest { ...@@ -246,10 +246,10 @@ public class KeyboardAccessoryControllerTest {
mCoordinator.registerActionProvider(generationProvider); mCoordinator.registerActionProvider(generationProvider);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate); mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
AutofillSuggestion suggestion1 = AutofillSuggestion suggestion1 = new AutofillSuggestion(
new AutofillSuggestion("FirstSuggestion", "", 0, false, 0, false, false, false); "FirstSuggestion", "", /* itemTag= */ "", 0, false, 0, false, false, false);
AutofillSuggestion suggestion2 = AutofillSuggestion suggestion2 = new AutofillSuggestion(
new AutofillSuggestion("SecondSuggestion", "", 0, false, 0, false, false, false); "SecondSuggestion", "", /* itemTag= */ "", 0, false, 0, false, false, false);
Action generationAction = new Action("Generate", GENERATE_PASSWORD_AUTOMATIC, (a) -> {}); Action generationAction = new Action("Generate", GENERATE_PASSWORD_AUTOMATIC, (a) -> {});
autofillSuggestionProvider.notifyObservers( autofillSuggestionProvider.notifyObservers(
new AutofillSuggestion[] {suggestion1, suggestion2}); new AutofillSuggestion[] {suggestion1, suggestion2});
...@@ -301,8 +301,8 @@ public class KeyboardAccessoryControllerTest { ...@@ -301,8 +301,8 @@ public class KeyboardAccessoryControllerTest {
mCoordinator.registerActionProvider(generationProvider); mCoordinator.registerActionProvider(generationProvider);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate); mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
AutofillSuggestion suggestion = AutofillSuggestion suggestion = new AutofillSuggestion(
new AutofillSuggestion("Suggestion", "", 0, false, 0, false, false, false); "Suggestion", "", /* itemTag= */ "", 0, false, 0, false, false, false);
Action generationAction = new Action("Generate", GENERATE_PASSWORD_AUTOMATIC, (a) -> {}); Action generationAction = new Action("Generate", GENERATE_PASSWORD_AUTOMATIC, (a) -> {});
autofillSuggestionProvider.notifyObservers( autofillSuggestionProvider.notifyObservers(
new AutofillSuggestion[] {suggestion, suggestion}); new AutofillSuggestion[] {suggestion, suggestion});
...@@ -355,7 +355,7 @@ public class KeyboardAccessoryControllerTest { ...@@ -355,7 +355,7 @@ public class KeyboardAccessoryControllerTest {
new PropertyProvider<>(AUTOFILL_SUGGESTION); new PropertyProvider<>(AUTOFILL_SUGGESTION);
int suggestionId = 0x1; // The address ID is located in the least 16 bit. int suggestionId = 0x1; // The address ID is located in the least 16 bit.
AutofillSuggestion addressSuggestion = new AutofillSuggestion( AutofillSuggestion addressSuggestion = new AutofillSuggestion(
"John", "Main Str", 0, false, suggestionId, false, false, false); "John", "Main Str", /* itemTag= */ "", 0, false, suggestionId, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate); mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers( autofillSuggestionProvider.notifyObservers(
new AutofillSuggestion[] {addressSuggestion, addressSuggestion, addressSuggestion}); new AutofillSuggestion[] {addressSuggestion, addressSuggestion, addressSuggestion});
...@@ -373,8 +373,8 @@ public class KeyboardAccessoryControllerTest { ...@@ -373,8 +373,8 @@ public class KeyboardAccessoryControllerTest {
PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider = PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider =
new PropertyProvider<>(AUTOFILL_SUGGESTION); new PropertyProvider<>(AUTOFILL_SUGGESTION);
int suggestionId = 0x10000; // The payment ID is located in the higher 16 bit. int suggestionId = 0x10000; // The payment ID is located in the higher 16 bit.
AutofillSuggestion paymentSuggestion = new AutofillSuggestion( AutofillSuggestion paymentSuggestion = new AutofillSuggestion("John", "4828 ****",
"John", "4828 ****", 0, false, suggestionId, false, false, false); /* itemTag= */ "", 0, false, suggestionId, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate); mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers( autofillSuggestionProvider.notifyObservers(
new AutofillSuggestion[] {paymentSuggestion, paymentSuggestion, paymentSuggestion}); new AutofillSuggestion[] {paymentSuggestion, paymentSuggestion, paymentSuggestion});
...@@ -391,10 +391,12 @@ public class KeyboardAccessoryControllerTest { ...@@ -391,10 +391,12 @@ public class KeyboardAccessoryControllerTest {
public void testCreatesIPHForSecondPasswordItem() { public void testCreatesIPHForSecondPasswordItem() {
PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider = PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider =
new PropertyProvider<>(AUTOFILL_SUGGESTION); new PropertyProvider<>(AUTOFILL_SUGGESTION);
AutofillSuggestion passwordSuggestion1 = new AutofillSuggestion( AutofillSuggestion passwordSuggestion1 =
"John", "****", 0, false, PopupItemId.ITEM_ID_USERNAME_ENTRY, false, false, false); new AutofillSuggestion("John", "****", /* itemTg= */ "", 0, false,
AutofillSuggestion passwordSuggestion2 = new AutofillSuggestion("Eva", "*******", 0, false, PopupItemId.ITEM_ID_USERNAME_ENTRY, false, false, false);
PopupItemId.ITEM_ID_PASSWORD_ENTRY, false, false, false); AutofillSuggestion passwordSuggestion2 =
new AutofillSuggestion("Eva", "*******", /* itemTag= */ "", 0, false,
PopupItemId.ITEM_ID_PASSWORD_ENTRY, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate); mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] { autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] {
passwordSuggestion1, passwordSuggestion2, passwordSuggestion2}); passwordSuggestion1, passwordSuggestion2, passwordSuggestion2});
...@@ -443,8 +445,8 @@ public class KeyboardAccessoryControllerTest { ...@@ -443,8 +445,8 @@ public class KeyboardAccessoryControllerTest {
mCoordinator.dismiss(); // Hide, so it's brought up again. mCoordinator.dismiss(); // Hide, so it's brought up again.
PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider = PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider =
new PropertyProvider<>(AUTOFILL_SUGGESTION); new PropertyProvider<>(AUTOFILL_SUGGESTION);
AutofillSuggestion suggestion = AutofillSuggestion suggestion = new AutofillSuggestion(
new AutofillSuggestion("Label", "sublabel", 0, false, 0, false, false, false); "Label", "sublabel", /* itemTag= */ "", 0, false, 0, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate); mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] {suggestion}); autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] {suggestion});
mCoordinator.show(); mCoordinator.show();
...@@ -487,8 +489,8 @@ public class KeyboardAccessoryControllerTest { ...@@ -487,8 +489,8 @@ public class KeyboardAccessoryControllerTest {
PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider = PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider =
new PropertyProvider<>(AUTOFILL_SUGGESTION); new PropertyProvider<>(AUTOFILL_SUGGESTION);
AutofillSuggestion suggestion = AutofillSuggestion suggestion = new AutofillSuggestion(
new AutofillSuggestion("Label", "sublabel", 0, false, 0, false, false, false); "Label", "sublabel", /* itemTag= */ "", 0, false, 0, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate); mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] {suggestion}); autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] {suggestion});
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_AUTOFILL_SUGGESTIONS), is(1)); assertThat(getShownMetricsCount(AccessoryBarContents.WITH_AUTOFILL_SUGGESTIONS), is(1));
......
...@@ -173,8 +173,8 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On ...@@ -173,8 +173,8 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On
String label, String sublabel, int iconId, boolean isIconAtStart, String label, String sublabel, int iconId, boolean isIconAtStart,
int suggestionId, boolean isDeletable, boolean isLabelMultiline, boolean isLabelBold) { int suggestionId, boolean isDeletable, boolean isLabelMultiline, boolean isLabelBold) {
int drawableId = iconId == 0 ? DropdownItem.NO_ICON : iconId; int drawableId = iconId == 0 ? DropdownItem.NO_ICON : iconId;
array[index] = new AutofillSuggestion(label, sublabel, drawableId, isIconAtStart, array[index] = new AutofillSuggestion(label, sublabel, /*itemTag= */ "", drawableId,
suggestionId, isDeletable, isLabelMultiline, isLabelBold); isIconAtStart, suggestionId, isDeletable, isLabelMultiline, isLabelBold);
} }
@NativeMethods @NativeMethods
......
...@@ -103,24 +103,24 @@ public class AutofillTest { ...@@ -103,24 +103,24 @@ public class AutofillTest {
private AutofillSuggestion[] createTwoAutofillSuggestionArray() { private AutofillSuggestion[] createTwoAutofillSuggestionArray() {
return new AutofillSuggestion[] { return new AutofillSuggestion[] {
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", DropdownItem.NO_ICON, new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", /*itemTag=*/"",
false, 42, false, false, false), DropdownItem.NO_ICON, false, 42, false, false, false),
new AutofillSuggestion("Arthur Dent", "West Country", DropdownItem.NO_ICON, new AutofillSuggestion("Arthur Dent", "West Country", /*itemTag=*/"",
false, 43, false, false, false), DropdownItem.NO_ICON, false, 43, false, false, false),
}; };
} }
private AutofillSuggestion[] createFiveAutofillSuggestionArray() { private AutofillSuggestion[] createFiveAutofillSuggestionArray() {
return new AutofillSuggestion[] { return new AutofillSuggestion[] {
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", DropdownItem.NO_ICON, new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", /*itemTag=*/"",
false, 42, false, false, false), DropdownItem.NO_ICON, false, 42, false, false, false),
new AutofillSuggestion("Arthur Dent", "West Country", DropdownItem.NO_ICON, new AutofillSuggestion("Arthur Dent", "West Country", /*itemTag=*/"",
false, 43, false, false, false), DropdownItem.NO_ICON, false, 43, false, false, false),
new AutofillSuggestion("Arthos", "France", DropdownItem.NO_ICON, new AutofillSuggestion("Arthos", "France", /*itemTag=*/"", DropdownItem.NO_ICON,
false, 44, false, false, false), false, 44, false, false, false),
new AutofillSuggestion("Porthos", "France", DropdownItem.NO_ICON, new AutofillSuggestion("Porthos", "France", /*itemTag=*/"", DropdownItem.NO_ICON,
false, 45, false, false, false), false, 45, false, false, false),
new AutofillSuggestion("Aramis", "France", DropdownItem.NO_ICON, new AutofillSuggestion("Aramis", "France", /*itemTag=*/"", DropdownItem.NO_ICON,
false, 46, false, false, false), false, 46, false, false, false),
}; };
} }
......
...@@ -52,6 +52,18 @@ ...@@ -52,6 +52,18 @@
android:singleLine="true" android:singleLine="true"
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary" /> android:textAppearance="@style/TextAppearance.TextSmall.Secondary" />
<TextView
android:id="@+id/dropdown_item_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/autofill_dropdown_item_label_margin"
android:layout_marginStart="@dimen/autofill_dropdown_item_label_margin"
android:ellipsize="end"
android:includeFontPadding="false"
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary" />
</LinearLayout> </LinearLayout>
<ImageView <ImageView
......
...@@ -45,6 +45,16 @@ ...@@ -45,6 +45,16 @@
android:singleLine="true" android:singleLine="true"
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary" /> android:textAppearance="@style/TextAppearance.TextSmall.Secondary" />
<TextView
android:id="@+id/dropdown_item_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:includeFontPadding="false"
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary" />
</LinearLayout> </LinearLayout>
<ImageView <ImageView
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<!-- Dimens for legacy UI <!-- Dimens for legacy UI
TODO(crbug.com/874077): Remove once refresh UI is fully rolled out. --> TODO(crbug.com/874077): Remove once refresh UI is fully rolled out. -->
<dimen name="autofill_dropdown_item_height">50dp</dimen> <dimen name="autofill_dropdown_item_height">50dp</dimen>
<dimen name="autofill_dropdown_item_tag_height">16dp</dimen>
<dimen name="autofill_dropdown_item_divider_height">1dp</dimen> <dimen name="autofill_dropdown_item_divider_height">1dp</dimen>
<dimen name="autofill_dropdown_item_label_margin">10dp</dimen> <dimen name="autofill_dropdown_item_label_margin">10dp</dimen>
<dimen name="autofill_dropdown_icon_margin">8dp</dimen> <dimen name="autofill_dropdown_icon_margin">8dp</dimen>
......
...@@ -86,6 +86,9 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> { ...@@ -86,6 +86,9 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
if (mIsRefresh) { if (mIsRefresh) {
TextView labelView = populateLabelView(item, layout); TextView labelView = populateLabelView(item, layout);
populateSublabelView(item, layout); populateSublabelView(item, layout);
// For refreshed layout, ignore the return value as we don't need to adjust the height
// of the view.
populateItemTagView(item, layout);
ImageView iconView = ImageView iconView =
populateIconView((ImageView) layout.findViewById(R.id.end_dropdown_icon), item); populateIconView((ImageView) layout.findViewById(R.id.end_dropdown_icon), item);
if (iconView != null) { if (iconView != null) {
...@@ -133,6 +136,16 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> { ...@@ -133,6 +136,16 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
divider.setDividerColor(dividerColor); divider.setDividerColor(dividerColor);
} }
// Layout of the item tag view, which has a smaller font and sits below the sub
// label.
TextView itemTagView = populateItemTagView(item, layout);
if (itemTagView != null) {
itemTagView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
mContext.getResources().getDimension(item.getSublabelFontSizeResId()));
height += mContext.getResources().getDimensionPixelSize(
R.dimen.autofill_dropdown_item_tag_height);
}
// Note: trying to set the height of the root LinearLayout breaks accessibility, // Note: trying to set the height of the root LinearLayout breaks accessibility,
// so we have to adjust the height of this LinearLayout that wraps the TextViews // so we have to adjust the height of this LinearLayout that wraps the TextViews
// instead. If you need to modify this layout, don't forget to test it with TalkBack and // instead. If you need to modify this layout, don't forget to test it with TalkBack and
...@@ -234,6 +247,26 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> { ...@@ -234,6 +247,26 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
return sublabelView; return sublabelView;
} }
/**
* Sets the text of the itemTag's View if such text exists; otherwise, sets the View's
* visibility to GONE.
* @param item the DropdownItem for this row.
* @param layout the View in which the label can be found.
* @return the View if it has been set to be visible; null otherwise. This view is already part
* of the view hierarchy, thus no need to explicitly add it.
*/
private TextView populateItemTagView(DropdownItem item, View layout) {
TextView itemTagView = (TextView) layout.findViewById(R.id.dropdown_item_tag);
CharSequence itemTag = item.getItemTag();
if (TextUtils.isEmpty(itemTag)) {
itemTagView.setVisibility(View.GONE);
return null;
}
itemTagView.setText(itemTag);
itemTagView.setVisibility(View.VISIBLE);
return itemTagView;
}
/** /**
* Sets the drawable in the given ImageView to the resource identified in the item, or sets * Sets the drawable in the given ImageView to the resource identified in the item, or sets
* iconView to visibility GONE if no icon is given. * iconView to visibility GONE if no icon is given.
......
...@@ -12,6 +12,7 @@ import org.chromium.ui.DropdownItemBase; ...@@ -12,6 +12,7 @@ import org.chromium.ui.DropdownItemBase;
public class AutofillSuggestion extends DropdownItemBase { public class AutofillSuggestion extends DropdownItemBase {
private final String mLabel; private final String mLabel;
private final String mSublabel; private final String mSublabel;
private final String mItemTag;
private final int mIconId; private final int mIconId;
private final boolean mIsIconAtStart; private final boolean mIsIconAtStart;
private final int mSuggestionId; private final int mSuggestionId;
...@@ -24,6 +25,7 @@ public class AutofillSuggestion extends DropdownItemBase { ...@@ -24,6 +25,7 @@ public class AutofillSuggestion extends DropdownItemBase {
* *
* @param label The main label of the Autofill suggestion. * @param label The main label of the Autofill suggestion.
* @param sublabel The describing sublabel of the Autofill suggestion. * @param sublabel The describing sublabel of the Autofill suggestion.
* @param itemTag The tag for the autofill suggestion.
* @param iconId The resource ID for the icon associated with the suggestion, or * @param iconId The resource ID for the icon associated with the suggestion, or
* {@code DropdownItem.NO_ICON} for no icon. * {@code DropdownItem.NO_ICON} for no icon.
* @param isIconAtStart {@code true} if {@code iconId} is displayed before {@code label}. * @param isIconAtStart {@code true} if {@code iconId} is displayed before {@code label}.
...@@ -32,10 +34,12 @@ public class AutofillSuggestion extends DropdownItemBase { ...@@ -32,10 +34,12 @@ public class AutofillSuggestion extends DropdownItemBase {
* @param isMultilineLabel Whether the label is displayed over multiple lines. * @param isMultilineLabel Whether the label is displayed over multiple lines.
* @param isBoldLabel Whether the label is displayed in {@code Typeface.BOLD}. * @param isBoldLabel Whether the label is displayed in {@code Typeface.BOLD}.
*/ */
public AutofillSuggestion(String label, String sublabel, int iconId, boolean isIconAtStart, public AutofillSuggestion(String label, String sublabel, String itemTag, int iconId,
int suggestionId, boolean isDeletable, boolean isMultilineLabel, boolean isBoldLabel) { boolean isIconAtStart, int suggestionId, boolean isDeletable, boolean isMultilineLabel,
boolean isBoldLabel) {
mLabel = label; mLabel = label;
mSublabel = sublabel; mSublabel = sublabel;
mItemTag = itemTag;
mIconId = iconId; mIconId = iconId;
mIsIconAtStart = isIconAtStart; mIsIconAtStart = isIconAtStart;
mSuggestionId = suggestionId; mSuggestionId = suggestionId;
...@@ -54,6 +58,11 @@ public class AutofillSuggestion extends DropdownItemBase { ...@@ -54,6 +58,11 @@ public class AutofillSuggestion extends DropdownItemBase {
return mSublabel; return mSublabel;
} }
@Override
public String getItemTag() {
return mItemTag;
}
@Override @Override
public int getIconId() { public int getIconId() {
return mIconId; return mIconId;
......
...@@ -603,8 +603,8 @@ public class AutofillProvider { ...@@ -603,8 +603,8 @@ public class AutofillProvider {
final AutofillSuggestion[] suggestions = new AutofillSuggestion[datalistValues.length]; final AutofillSuggestion[] suggestions = new AutofillSuggestion[datalistValues.length];
for (int i = 0; i < suggestions.length; i++) { for (int i = 0; i < suggestions.length; i++) {
suggestions[i] = new AutofillSuggestion(datalistValues[i], datalistLabels[i], suggestions[i] = new AutofillSuggestion(datalistValues[i], datalistLabels[i],
DropdownItem.NO_ICON, false /* isIconAtLeft */, i, false /* isDeletable */, /* itemTag= */ "", DropdownItem.NO_ICON, false /* isIconAtLeft */, i,
false /* isMultilineLabel */, false /* isBoldLabel */); false /* isDeletable */, false /* isMultilineLabel */, false /* isBoldLabel */);
} }
if (mWebContentsAccessibility == null) { if (mWebContentsAccessibility == null) {
mWebContentsAccessibility = WebContentsAccessibility.fromWebContents(mWebContents); mWebContentsAccessibility = WebContentsAccessibility.fromWebContents(mWebContents);
......
...@@ -19,6 +19,10 @@ public interface DropdownItem { ...@@ -19,6 +19,10 @@ public interface DropdownItem {
* Returns the sublabel that should be shown in the dropdown. * Returns the sublabel that should be shown in the dropdown.
*/ */
String getSublabel(); String getSublabel();
/**
* Returns the item tag that should be shown in the dropdown.
*/
String getItemTag();
/** /**
* Returns the drawable id of the icon that should be shown in the dropdown, or NO_ICON. * Returns the drawable id of the icon that should be shown in the dropdown, or NO_ICON.
*/ */
......
...@@ -19,6 +19,11 @@ public class DropdownItemBase implements DropdownItem { ...@@ -19,6 +19,11 @@ public class DropdownItemBase implements DropdownItem {
return null; return null;
} }
@Override
public String getItemTag() {
return null;
}
@Override @Override
public int getIconId() { public int getIconId() {
return NO_ICON; return NO_ICON;
......
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