Commit 9f6e9abc authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

[AF Android] Creating Dropdown Refresh Impl

This CL:
* Adds a boolean parameter to AutofillDropdownAdapter to allow us to
  programmatically choose between two visual styles (the existing UI,
  and the WIP visual refresh).
* Removes dividers drawn between items in the refresh case.
* Wires up the existing feature and flag which will control which style
  is used.

Change-Id: Ia7cbb79b31e8ad9d086ef1a9a69cb6090b58d533
Bug: 874077
Reviewed-on: https://chromium-review.googlesource.com/1171558Reviewed-by: default avatarTao Bai <michaelbai@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584749}
parent 80099d55
...@@ -71,7 +71,7 @@ public class AwAutofillClient { ...@@ -71,7 +71,7 @@ public class AwAutofillClient {
return; return;
} }
} }
mAutofillPopup.filterAndShow(suggestions, isRtl); mAutofillPopup.filterAndShow(suggestions, isRtl, false);
} }
@CalledByNative @CalledByNative
......
...@@ -153,6 +153,7 @@ public abstract class ChromeFeatureList { ...@@ -153,6 +153,7 @@ public abstract class ChromeFeatureList {
public static final String ANDROID_PAYMENT_APPS = "AndroidPaymentApps"; public static final String ANDROID_PAYMENT_APPS = "AndroidPaymentApps";
public static final String APP_NOTIFICATION_STATUS_MESSAGING = "AppNotificationStatusMessaging"; public static final String APP_NOTIFICATION_STATUS_MESSAGING = "AppNotificationStatusMessaging";
public static final String AUTOFILL_ASSISTANT = "AutofillAssistant"; public static final String AUTOFILL_ASSISTANT = "AutofillAssistant";
public static final String AUTOFILL_EXPANDED_POPUP_VIEWS = "AutofillExpandedPopupViews";
public static final String AUTOFILL_KEYBOARD_ACCESSORY = "AutofillKeyboardAccessory"; public static final String AUTOFILL_KEYBOARD_ACCESSORY = "AutofillKeyboardAccessory";
public static final String AUTOFILL_SCAN_CARDHOLDER_NAME = "AutofillScanCardholderName"; public static final String AUTOFILL_SCAN_CARDHOLDER_NAME = "AutofillScanCardholderName";
public static final String CAF_MEDIA_ROUTER_IMPL = "CafMediaRouterImpl"; public static final String CAF_MEDIA_ROUTER_IMPL = "CafMediaRouterImpl";
......
...@@ -15,6 +15,7 @@ import org.chromium.base.annotations.CalledByNative; ...@@ -15,6 +15,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ResourceId; import org.chromium.chrome.browser.ResourceId;
import org.chromium.components.autofill.AutofillDelegate; import org.chromium.components.autofill.AutofillDelegate;
import org.chromium.components.autofill.AutofillPopup; import org.chromium.components.autofill.AutofillPopup;
...@@ -104,7 +105,7 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On ...@@ -104,7 +105,7 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On
@CalledByNative @CalledByNative
private void show(AutofillSuggestion[] suggestions, boolean isRtl) { private void show(AutofillSuggestion[] suggestions, boolean isRtl) {
if (mAutofillPopup != null) { if (mAutofillPopup != null) {
mAutofillPopup.filterAndShow(suggestions, isRtl); mAutofillPopup.filterAndShow(suggestions, isRtl, shouldUseRefreshStyle());
mWebContentsAccessibility.onAutofillPopupDisplayed(mAutofillPopup.getListView()); mWebContentsAccessibility.onAutofillPopupDisplayed(mAutofillPopup.getListView());
} }
} }
...@@ -120,6 +121,10 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On ...@@ -120,6 +121,10 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On
mDeletionDialog.show(); mDeletionDialog.show();
} }
private static boolean shouldUseRefreshStyle() {
return ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_EXPANDED_POPUP_VIEWS);
}
// Helper methods for AutofillSuggestion // Helper methods for AutofillSuggestion
@CalledByNative @CalledByNative
......
...@@ -67,7 +67,8 @@ public class AutofillTest { ...@@ -67,7 +67,8 @@ public class AutofillTest {
mWindowAndroid = new ActivityWindowAndroid(activity); mWindowAndroid = new ActivityWindowAndroid(activity);
mAutofillPopup = new AutofillPopup(activity, anchorView, mMockAutofillCallback); mAutofillPopup = new AutofillPopup(activity, anchorView, mMockAutofillCallback);
mAutofillPopup.filterAndShow(new AutofillSuggestion[0], false /* isRtl */); mAutofillPopup.filterAndShow(
new AutofillSuggestion[0], /* isRtl= */ false, /* isRefresh= */ false);
}); });
} }
...@@ -133,7 +134,9 @@ public class AutofillTest { ...@@ -133,7 +134,9 @@ public class AutofillTest {
public void openAutofillPopupAndWaitUntilReady(final AutofillSuggestion[] suggestions) { public void openAutofillPopupAndWaitUntilReady(final AutofillSuggestion[] suggestions) {
ThreadUtils.runOnUiThreadBlocking( ThreadUtils.runOnUiThreadBlocking(
() -> mAutofillPopup.filterAndShow(suggestions, false /* isRtl */)); ()
-> mAutofillPopup.filterAndShow(
suggestions, /* isRtl= */ false, /* isRefresh= */ false));
CriteriaHelper.pollInstrumentationThread(new Criteria() { CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
......
...@@ -3102,8 +3102,8 @@ const FeatureEntry kFeatureEntries[] = { ...@@ -3102,8 +3102,8 @@ const FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(autofill::kAutofillUpstreamUpdatePromptExplanation)}, FEATURE_VALUE_TYPE(autofill::kAutofillUpstreamUpdatePromptExplanation)},
{"enable-autofill-native-dropdown-views", {"enable-autofill-native-dropdown-views",
flag_descriptions::kEnableAutofillNativeDropdownViewsName, flag_descriptions::kEnableAutofillNativeDropdownViewsName,
flag_descriptions::kEnableAutofillNativeDropdownViewsDescription, flag_descriptions::kEnableAutofillNativeDropdownViewsDescription, kOsAll,
kOsDesktop, FEATURE_VALUE_TYPE(autofill::kAutofillExpandedPopupViews)}, FEATURE_VALUE_TYPE(autofill::kAutofillExpandedPopupViews)},
{"enable-autofill-save-card-dialog-unlabeled-expiration-date", {"enable-autofill-save-card-dialog-unlabeled-expiration-date",
flag_descriptions:: flag_descriptions::
kEnableAutofillSaveCardDialogUnlabeledExpirationDateName, kEnableAutofillSaveCardDialogUnlabeledExpirationDateName,
......
...@@ -46,6 +46,7 @@ namespace { ...@@ -46,6 +46,7 @@ namespace {
// this array may either refer to features defined in the header of this file or // this array may either refer to features defined in the header of this file or
// in other locations in the code base (e.g. chrome/, components/, etc). // in other locations in the code base (e.g. chrome/, components/, etc).
const base::Feature* kFeaturesExposedToJava[] = { const base::Feature* kFeaturesExposedToJava[] = {
&autofill::kAutofillExpandedPopupViews,
&autofill::kAutofillScanCardholderName, &autofill::kAutofillScanCardholderName,
&contextual_suggestions::kContextualSuggestionsBottomSheet, &contextual_suggestions::kContextualSuggestionsBottomSheet,
&contextual_suggestions::kContextualSuggestionsButton, &contextual_suggestions::kContextualSuggestionsButton,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
--> -->
<resources> <resources>
<dimen name="autofill_dropdown_item_height">50dp</dimen> <dimen name="autofill_dropdown_item_height">50dp</dimen>
<dimen name="autofill_dropdown_item_divider_height">1px</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>
</resources> </resources>
...@@ -36,15 +36,17 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> { ...@@ -36,15 +36,17 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
private final Set<Integer> mSeparators; private final Set<Integer> mSeparators;
private final boolean mAreAllItemsEnabled; private final boolean mAreAllItemsEnabled;
private final int mLabelMargin; private final int mLabelMargin;
private final boolean mIsRefresh;
/** /**
* Creates an {@code ArrayAdapter} with specified parameters. * Creates an {@code ArrayAdapter} with specified parameters.
* @param context Application context. * @param context Application context.
* @param items List of labels and icons to display. * @param items List of labels and icons to display.
* @param separators Set of positions that separate {@code items}. * @param separators Set of positions that separate {@code items}.
* @param isRefresh Whether or not the dropdown should be presented using refreshed styling.
*/ */
public AutofillDropdownAdapter( public AutofillDropdownAdapter(Context context, List<? extends DropdownItem> items,
Context context, List<? extends DropdownItem> items, Set<Integer> separators) { Set<Integer> separators, boolean isRefresh) {
super(context, R.layout.autofill_dropdown_item); super(context, R.layout.autofill_dropdown_item);
mContext = context; mContext = context;
addAll(items); addAll(items);
...@@ -52,6 +54,7 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> { ...@@ -52,6 +54,7 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
mAreAllItemsEnabled = checkAreAllItemsEnabled(); mAreAllItemsEnabled = checkAreAllItemsEnabled();
mLabelMargin = context.getResources().getDimensionPixelSize( mLabelMargin = context.getResources().getDimensionPixelSize(
R.dimen.autofill_dropdown_item_label_margin); R.dimen.autofill_dropdown_item_label_margin);
mIsRefresh = isRefresh;
} }
private boolean checkAreAllItemsEnabled() { private boolean checkAreAllItemsEnabled() {
...@@ -72,26 +75,27 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> { ...@@ -72,26 +75,27 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
layout = inflater.inflate(R.layout.autofill_dropdown_item, null); layout = inflater.inflate(R.layout.autofill_dropdown_item, null);
layout.setBackground(new DropdownDividerDrawable(/*backgroundColor=*/null)); layout.setBackground(new DropdownDividerDrawable(/*backgroundColor=*/null));
} }
DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBackground();
int height = mContext.getResources().getDimensionPixelSize( int height = mContext.getResources().getDimensionPixelSize(
R.dimen.autofill_dropdown_item_height); R.dimen.autofill_dropdown_item_height);
if (!mIsRefresh) {
if (position == 0) { DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBackground();
divider.setDividerColor(Color.TRANSPARENT); if (position == 0) {
} else { divider.setDividerColor(Color.TRANSPARENT);
int dividerHeight = mContext.getResources().getDimensionPixelSize(
R.dimen.autofill_dropdown_item_divider_height);
height += dividerHeight;
divider.setHeight(dividerHeight);
int dividerColor;
if (mSeparators != null && mSeparators.contains(position)) {
dividerColor = ApiCompatibilityUtils.getColor(
mContext.getResources(), R.color.dropdown_dark_divider_color);
} else { } else {
dividerColor = ApiCompatibilityUtils.getColor( int dividerHeight = mContext.getResources().getDimensionPixelSize(
mContext.getResources(), R.color.dropdown_divider_color); R.dimen.autofill_dropdown_item_divider_height);
height += dividerHeight;
divider.setHeight(dividerHeight);
int dividerColor;
if (mSeparators != null && mSeparators.contains(position)) {
dividerColor = ApiCompatibilityUtils.getColor(
mContext.getResources(), R.color.dropdown_dark_divider_color);
} else {
dividerColor = ApiCompatibilityUtils.getColor(
mContext.getResources(), R.color.dropdown_divider_color);
}
divider.setDividerColor(dividerColor);
} }
divider.setDividerColor(dividerColor);
} }
DropdownItem item = getItem(position); DropdownItem item = getItem(position);
......
...@@ -69,9 +69,10 @@ public class AutofillPopup extends DropdownPopupWindow implements AdapterView.On ...@@ -69,9 +69,10 @@ public class AutofillPopup extends DropdownPopupWindow implements AdapterView.On
* Filters the Autofill suggestions to the ones that we support and shows the popup. * Filters the Autofill suggestions to the ones that we support and shows the popup.
* @param suggestions Autofill suggestion data. * @param suggestions Autofill suggestion data.
* @param isRtl @code true if right-to-left text. * @param isRtl @code true if right-to-left text.
* @param isRefresh Whether or not refreshed visual style should be used.
*/ */
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
public void filterAndShow(AutofillSuggestion[] suggestions, boolean isRtl) { public void filterAndShow(AutofillSuggestion[] suggestions, boolean isRtl, boolean isRefresh) {
mSuggestions = new ArrayList<AutofillSuggestion>(Arrays.asList(suggestions)); mSuggestions = new ArrayList<AutofillSuggestion>(Arrays.asList(suggestions));
// Remove the AutofillSuggestions with IDs that are not supported by Android // Remove the AutofillSuggestions with IDs that are not supported by Android
ArrayList<DropdownItem> cleanedData = new ArrayList<DropdownItem>(); ArrayList<DropdownItem> cleanedData = new ArrayList<DropdownItem>();
...@@ -85,7 +86,7 @@ public class AutofillPopup extends DropdownPopupWindow implements AdapterView.On ...@@ -85,7 +86,7 @@ public class AutofillPopup extends DropdownPopupWindow implements AdapterView.On
} }
} }
setAdapter(new AutofillDropdownAdapter(mContext, cleanedData, separators)); setAdapter(new AutofillDropdownAdapter(mContext, cleanedData, separators, isRefresh));
setRtl(isRtl); setRtl(isRtl);
show(); show();
getListView().setOnItemLongClickListener(this); getListView().setOnItemLongClickListener(this);
......
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