Commit 955f0598 authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

[AF Android] Adding footers on legacy Android

This CL implements footers in the Autofill dropdown on legacy
(Jellybean - Marshmallow) Android. It does so by implementing an
interface method which is currently empty. This also required
AutofillPopup to be changed slightly, as the new implementation cannot
be invoked after show()ing the popup.

Change-Id: I9387be794382a32a3abd92a267c7de9e7b04d8b1
Bug: 896693
Reviewed-on: https://chromium-review.googlesource.com/c/1281723
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600757}
parent 96aca44d
......@@ -89,7 +89,10 @@ public class AutofillPopup extends DropdownPopupWindow
}
}
if (!footerRows.isEmpty()) {
// TODO(crbug.com/896349): Ideally, we would set the footer each time, as this guard assumes
// the footer is unchanged between calls to filterAndShow. However, the JellyBean popup
// implementation will not draw footers added after the initial call to show().
if (!footerRows.isEmpty() && !isShowing()) {
setFooterView(new AutofillDropdownFooter(mContext, footerRows, this));
}
......@@ -139,7 +142,24 @@ public class AutofillPopup extends DropdownPopupWindow
@Override
public void onFooterSelection(DropdownItem item) {
int index = mSuggestions.indexOf(item);
// TODO(crbug.com/896349): Finding the suggestion index by its frontend id is a workaround
// for the fact that footer items are not redrawn on each call to filterAndShow, and so
// |item| will be identical to, but not equal to, an element in |mSuggestions|. Once this
// workaround is no longer needed, this should be changed to simply use
// mSuggestions.indexOf(item).
int index = -1;
for (int i = 0; i < mSuggestions.size(); i++) {
// Cast from DropdownItem to AutofillSuggestion is safe because filterAndShow creates
// the AutofillDropdownFooter which invokes this, and passes an AutofillSuggestion to
// the constructor.
if ((mSuggestions.get(i).getSuggestionId()
== ((AutofillSuggestion) item).getSuggestionId())) {
index = i;
break;
}
}
assert index > -1;
mAutofillDelegate.suggestionSelected(index);
}
......
......@@ -72,7 +72,8 @@ public interface DropdownPopupWindowInterface {
/**
* Adds a non-scrolling View beneath the list. This View will be separated from the main list
* by a single divider. Passing null will remove any existing footer.
* by a single divider.
* TODO(crbug.com/896349): This currently only works when called before show().
*/
void setFooterView(View footerView);
......
......@@ -7,10 +7,12 @@ package org.chromium.ui;
import android.content.Context;
import android.graphics.Rect;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListPopupWindow;
import android.widget.ListView;
......@@ -36,6 +38,7 @@ class DropdownPopupWindowJellyBean implements DropdownPopupWindowInterface {
private PopupWindow.OnDismissListener mOnDismissListener;
private CharSequence mDescription;
private ListPopupWindow mListPopupWindow;
private View mFooterView;
ListAdapter mAdapter;
/**
......@@ -102,7 +105,7 @@ class DropdownPopupWindowJellyBean implements DropdownPopupWindowInterface {
mListPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
assert mAdapter != null : "Set the adapter before showing the popup.";
final int contentWidth = UiUtils.computeMaxWidthOfListAdapterItems(mAdapter);
final int contentWidth = measureContentWidth();
final float anchorWidth = mAnchorView.getLayoutParams().width;
assert anchorWidth > 0;
Rect padding = new Rect();
......@@ -193,7 +196,13 @@ class DropdownPopupWindowJellyBean implements DropdownPopupWindowInterface {
@Override
public void setFooterView(View footerView) {
// TODO(crbug.com/874077): Implement this before using footer views.
mFooterView = footerView;
if (footerView != null) {
footerView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
mListPopupWindow.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);
mListPopupWindow.setPromptView(footerView);
}
/**
......@@ -235,6 +244,16 @@ class DropdownPopupWindowJellyBean implements DropdownPopupWindowInterface {
*/
private int measureContentWidth() {
assert mAdapter != null : "Set the adapter before showing the popup.";
return UiUtils.computeMaxWidthOfListAdapterItems(mAdapter);
int adapterWidth = UiUtils.computeMaxWidthOfListAdapterItems(mAdapter);
if (mFooterView != null) {
if (mFooterView.getLayoutParams() == null) {
mFooterView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
int measureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
mFooterView.measure(measureSpec, measureSpec);
return Math.max(mFooterView.getMeasuredWidth(), adapterWidth);
}
return adapterWidth;
}
}
\ No newline at end of file
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