Skip to content

Commit

Permalink
[AF Android] Creating Dropdown Refresh Impl
Browse files Browse the repository at this point in the history
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/1171558
Reviewed-by: Tao Bai <michaelbai@chromium.org>
Reviewed-by: Theresa <twellington@chromium.org>
Reviewed-by: Fabio Tirelo <ftirelo@chromium.org>
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584749}
  • Loading branch information
Tommy Martino authored and Commit Bot committed Aug 21, 2018
1 parent 80099d5 commit 9f6e9ab
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void accessibilityFocusCleared() {}
return;
}
}
mAutofillPopup.filterAndShow(suggestions, isRtl);
mAutofillPopup.filterAndShow(suggestions, isRtl, false);
}

@CalledByNative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public static boolean getFieldTrialParamByFeatureAsBoolean(
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -104,7 +105,7 @@ private void dismiss() {
@CalledByNative
private void show(AutofillSuggestion[] suggestions, boolean isRtl) {
if (mAutofillPopup != null) {
mAutofillPopup.filterAndShow(suggestions, isRtl);
mAutofillPopup.filterAndShow(suggestions, isRtl, shouldUseRefreshStyle());
mWebContentsAccessibility.onAutofillPopupDisplayed(mAutofillPopup.getListView());
}
}
Expand All @@ -120,6 +121,10 @@ private void confirmDeletion(String title, String body) {
mDeletionDialog.show();
}

private static boolean shouldUseRefreshStyle() {
return ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_EXPANDED_POPUP_VIEWS);
}

// Helper methods for AutofillSuggestion

@CalledByNative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public void setUp() throws Exception {

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);
});
}

Expand Down Expand Up @@ -133,7 +134,9 @@ private AutofillSuggestion[] createFiveAutofillSuggestionArray() {

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() {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/android/chrome_feature_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/autofill/android/java/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,25 @@ 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);
mSeparators = separators;
mAreAllItemsEnabled = checkAreAllItemsEnabled();
mLabelMargin = context.getResources().getDimensionPixelSize(
R.dimen.autofill_dropdown_item_label_margin);
mIsRefresh = isRefresh;
}

private boolean checkAreAllItemsEnabled() {
Expand All @@ -72,26 +75,27 @@ public View getView(int position, View convertView, ViewGroup parent) {
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 (position == 0) {
divider.setDividerColor(Color.TRANSPARENT);
} else {
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);
if (!mIsRefresh) {
DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBackground();
if (position == 0) {
divider.setDividerColor(Color.TRANSPARENT);
} else {
dividerColor = ApiCompatibilityUtils.getColor(
mContext.getResources(), R.color.dropdown_divider_color);
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 {
dividerColor = ApiCompatibilityUtils.getColor(
mContext.getResources(), R.color.dropdown_divider_color);
}
divider.setDividerColor(dividerColor);
}
divider.setDividerColor(dividerColor);
}

DropdownItem item = getItem(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public AutofillPopup(Context context, View anchorView, AutofillDelegate autofill
* 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>();
Expand All @@ -85,7 +86,7 @@ public void filterAndShow(AutofillSuggestion[] suggestions, boolean isRtl) {
}
}

setAdapter(new AutofillDropdownAdapter(mContext, cleanedData, separators));
setAdapter(new AutofillDropdownAdapter(mContext, cleanedData, separators, isRefresh));
setRtl(isRtl);
show();
getListView().setOnItemLongClickListener(this);
Expand Down

0 comments on commit 9f6e9ab

Please sign in to comment.