Commit 3c6126d9 authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

[AF Android] Rendering footer

This CL introduces a new class, AutofillDropdownFooter, to represent the
footer in the UI Refresh of the Autofill dropdown. This class is backed
by a new XML layout.

In addition, the AutofillPopup receives new logic separating out the
footer items from the rest of the suggestions, and passing them along
to an instance of the new class, if and only if the UI refresh is in
use.

Bug: 874077
Change-Id: Ia6b28633afabc3c418908efcdde77a52af6fdb0a
Reviewed-on: https://chromium-review.googlesource.com/c/1255886
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595959}
parent c30292f9
......@@ -80,6 +80,7 @@ android_library("autofill_java") {
java_files = [
"java/src/org/chromium/components/autofill/AutofillDelegate.java",
"java/src/org/chromium/components/autofill/AutofillDropdownAdapter.java",
"java/src/org/chromium/components/autofill/AutofillDropdownFooter.java",
"java/src/org/chromium/components/autofill/AutofillPopup.java",
"java/src/org/chromium/components/autofill/AutofillSuggestion.java",
]
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/autofill_dropdown_refresh_footer_item_height"
android:paddingEnd="@dimen/autofill_dropdown_refresh_horizontal_padding"
android:paddingStart="@dimen/autofill_dropdown_refresh_horizontal_padding"
android:gravity="center_vertical"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables" >
<TextView
android:id="@+id/dropdown_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:includeFontPadding="false"
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="@style/BlackHint2" />
<ImageView
android:id="@+id/dropdown_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/autofill_dropdown_refresh_icon_margin"
android:layout_marginEnd="0dp"
tools:ignore="ContentDescription" />
</LinearLayout>
......@@ -14,6 +14,7 @@
<!-- Dimens for refresh UI -->
<dimen name="autofill_dropdown_refresh_item_height">48dp</dimen>
<dimen name="autofill_dropdown_refresh_footer_item_height">40dp</dimen>
<dimen name="autofill_dropdown_refresh_horizontal_padding">16dp</dimen>
<dimen name="autofill_dropdown_refresh_icon_margin">24dp</dimen>
</resources>
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.autofill;
import android.content.Context;
import android.support.v7.content.res.AppCompatResources;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.chromium.ui.DropdownItem;
import java.util.List;
/**
* Renders the footer items in the Autofill dropdown, as provided by a List of DropdownItem objects.
*/
public class AutofillDropdownFooter extends LinearLayout {
/**
* Interface for handling selection events within the footer.
*/
public interface Observer {
/**
* Invoked when an item in the footer is selected.
* @param item The data represented by this row.
*/
void onFooterSelection(DropdownItem item);
}
/**
* View representing a single row in the footer.
*/
private class FooterRow extends FrameLayout implements OnClickListener {
private DropdownItem mItem;
private Observer mObserver;
/**
* @param context Application context.
* @param item The DropdownItem representing the Autofill suggestion for this footer option.
* @param observer An object capable of responding to a selection of this row.
*/
public FooterRow(Context context, DropdownItem item, Observer observer) {
super(context);
mItem = item;
mObserver = observer;
inflate(context, R.layout.autofill_dropdown_footer_item_refresh, this);
TextView label = findViewById(R.id.dropdown_label);
label.setText(item.getLabel());
ImageView icon = findViewById(R.id.dropdown_icon);
if (item.getIconId() == DropdownItem.NO_ICON) {
icon.setVisibility(View.GONE);
} else {
icon.setImageDrawable(AppCompatResources.getDrawable(context, item.getIconId()));
}
setOnClickListener(this);
}
@Override
public void onClick(View v) {
mObserver.onFooterSelection(mItem);
}
}
private Context mContext;
/**
* @param context Application context.
* @param items The item or items representing the content to be displayed in the footer. Each
* item will be rendered as a row.
* @param observer An object capable of responding to a selection of a row in the footer.
*/
public AutofillDropdownFooter(Context context, List<DropdownItem> items, Observer observer) {
super(context);
mContext = context;
setOrientation(LinearLayout.VERTICAL);
for (DropdownItem item : items) {
addView(new FooterRow(context, item, observer));
}
}
}
......@@ -24,9 +24,9 @@ import java.util.List;
/**
* The Autofill suggestion popup that lists relevant suggestions.
*/
public class AutofillPopup extends DropdownPopupWindow implements AdapterView.OnItemClickListener,
AdapterView.OnItemLongClickListener, PopupWindow.OnDismissListener {
public class AutofillPopup extends DropdownPopupWindow
implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener,
PopupWindow.OnDismissListener, AutofillDropdownFooter.Observer {
/**
* We post a delayed runnable to clear accessibility focus from the autofill popup's list view
* when we receive a {@code TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED} event because we receive a
......@@ -75,17 +75,24 @@ public class AutofillPopup extends DropdownPopupWindow implements AdapterView.On
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>();
List<DropdownItem> cleanedData = new ArrayList<>();
List<DropdownItem> footerRows = new ArrayList<>();
HashSet<Integer> separators = new HashSet<Integer>();
for (int i = 0; i < suggestions.length; i++) {
int itemId = suggestions[i].getSuggestionId();
if (itemId == PopupItemId.ITEM_ID_SEPARATOR) {
separators.add(cleanedData.size());
} else if (isFooter(itemId, isRefresh)) {
footerRows.add(suggestions[i]);
} else {
cleanedData.add(suggestions[i]);
}
}
if (!footerRows.isEmpty()) {
setFooterView(new AutofillDropdownFooter(mContext, footerRows, this));
}
setAdapter(new AutofillDropdownAdapter(mContext, cleanedData, separators, isRefresh));
setRtl(isRtl);
show();
......@@ -129,4 +136,29 @@ public class AutofillPopup extends DropdownPopupWindow implements AdapterView.On
public void onDismiss() {
mAutofillDelegate.dismissed();
}
@Override
public void onFooterSelection(DropdownItem item) {
int index = mSuggestions.indexOf(item);
assert index > -1;
mAutofillDelegate.suggestionSelected(index);
}
private boolean isFooter(int row, boolean isRefresh) {
// Footer items are only handled as a special case in the refreshed UI.
if (!isRefresh) {
return false;
}
switch (row) {
case PopupItemId.ITEM_ID_CLEAR_FORM:
case PopupItemId.ITEM_ID_AUTOFILL_OPTIONS:
case PopupItemId.ITEM_ID_SCAN_CREDIT_CARD:
case PopupItemId.ITEM_ID_CREDIT_CARD_SIGNIN_PROMO:
case PopupItemId.ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY:
return true;
default:
return false;
}
}
}
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