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 {
return;
}
}
mAutofillPopup.filterAndShow(suggestions, isRtl);
mAutofillPopup.filterAndShow(suggestions, isRtl, false);
}
@CalledByNative
......
......@@ -153,6 +153,7 @@ public abstract class ChromeFeatureList {
public static final String ANDROID_PAYMENT_APPS = "AndroidPaymentApps";
public static final String APP_NOTIFICATION_STATUS_MESSAGING = "AppNotificationStatusMessaging";
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_SCAN_CARDHOLDER_NAME = "AutofillScanCardholderName";
public static final String CAF_MEDIA_ROUTER_IMPL = "CafMediaRouterImpl";
......
......@@ -15,6 +15,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.components.autofill.AutofillDelegate;
import org.chromium.components.autofill.AutofillPopup;
......@@ -104,7 +105,7 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On
@CalledByNative
private void show(AutofillSuggestion[] suggestions, boolean isRtl) {
if (mAutofillPopup != null) {
mAutofillPopup.filterAndShow(suggestions, isRtl);
mAutofillPopup.filterAndShow(suggestions, isRtl, shouldUseRefreshStyle());
mWebContentsAccessibility.onAutofillPopupDisplayed(mAutofillPopup.getListView());
}
}
......@@ -120,6 +121,10 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On
mDeletionDialog.show();
}
private static boolean shouldUseRefreshStyle() {
return ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_EXPANDED_POPUP_VIEWS);
}
// Helper methods for AutofillSuggestion
@CalledByNative
......
......@@ -67,7 +67,8 @@ public class AutofillTest {
mWindowAndroid = new ActivityWindowAndroid(activity);
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 {
public void openAutofillPopupAndWaitUntilReady(final AutofillSuggestion[] suggestions) {
ThreadUtils.runOnUiThreadBlocking(
() -> mAutofillPopup.filterAndShow(suggestions, false /* isRtl */));
()
-> mAutofillPopup.filterAndShow(
suggestions, /* isRtl= */ false, /* isRefresh= */ false));
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
......
......@@ -3102,8 +3102,8 @@ const FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(autofill::kAutofillUpstreamUpdatePromptExplanation)},
{"enable-autofill-native-dropdown-views",
flag_descriptions::kEnableAutofillNativeDropdownViewsName,
flag_descriptions::kEnableAutofillNativeDropdownViewsDescription,
kOsDesktop, FEATURE_VALUE_TYPE(autofill::kAutofillExpandedPopupViews)},
flag_descriptions::kEnableAutofillNativeDropdownViewsDescription, kOsAll,
FEATURE_VALUE_TYPE(autofill::kAutofillExpandedPopupViews)},
{"enable-autofill-save-card-dialog-unlabeled-expiration-date",
flag_descriptions::
kEnableAutofillSaveCardDialogUnlabeledExpirationDateName,
......
......@@ -46,6 +46,7 @@ namespace {
// 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).
const base::Feature* kFeaturesExposedToJava[] = {
&autofill::kAutofillExpandedPopupViews,
&autofill::kAutofillScanCardholderName,
&contextual_suggestions::kContextualSuggestionsBottomSheet,
&contextual_suggestions::kContextualSuggestionsButton,
......
......@@ -6,7 +6,7 @@
-->
<resources>
<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_icon_margin">8dp</dimen>
</resources>
......@@ -36,15 +36,17 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
private final Set<Integer> mSeparators;
private final boolean mAreAllItemsEnabled;
private final int mLabelMargin;
private final boolean mIsRefresh;
/**
* Creates an {@code ArrayAdapter} with specified parameters.
* @param context Application context.
* @param items List of labels and icons to display.
* @param separators Set of positions that separate {@code items}.
* @param isRefresh Whether or not the dropdown should be presented using refreshed styling.
*/
public AutofillDropdownAdapter(
Context context, List<? extends DropdownItem> items, Set<Integer> separators) {
public AutofillDropdownAdapter(Context context, List<? extends DropdownItem> items,
Set<Integer> separators, boolean isRefresh) {
super(context, R.layout.autofill_dropdown_item);
mContext = context;
addAll(items);
......@@ -52,6 +54,7 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
mAreAllItemsEnabled = checkAreAllItemsEnabled();
mLabelMargin = context.getResources().getDimensionPixelSize(
R.dimen.autofill_dropdown_item_label_margin);
mIsRefresh = isRefresh;
}
private boolean checkAreAllItemsEnabled() {
......@@ -72,10 +75,10 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
layout = inflater.inflate(R.layout.autofill_dropdown_item, null);
layout.setBackground(new DropdownDividerDrawable(/*backgroundColor=*/null));
}
DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBackground();
int height = mContext.getResources().getDimensionPixelSize(
R.dimen.autofill_dropdown_item_height);
if (!mIsRefresh) {
DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBackground();
if (position == 0) {
divider.setDividerColor(Color.TRANSPARENT);
} else {
......@@ -93,6 +96,7 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
}
divider.setDividerColor(dividerColor);
}
}
DropdownItem item = getItem(position);
......
......@@ -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.
* @param suggestions Autofill suggestion data.
* @param isRtl @code true if right-to-left text.
* @param isRefresh Whether or not refreshed visual style should be used.
*/
@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));
// Remove the AutofillSuggestions with IDs that are not supported by Android
ArrayList<DropdownItem> cleanedData = new ArrayList<DropdownItem>();
......@@ -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);
show();
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