Force Autofill in FloatingToolbar overflow menu
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest bit CtsWidgetTestCases:android.widget.cts.EditTextTest Bug: 62271937 Change-Id: Ib3447281f3bd1abc811a25fc55ad55e34e155bbb
This commit is contained in:
@@ -70,7 +70,12 @@ public interface MenuItem {
|
||||
* a larger segment of its container.
|
||||
*/
|
||||
public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8;
|
||||
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
int SHOW_AS_OVERFLOW_ALWAYS = 1 << 31;
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when a menu item is
|
||||
* clicked.
|
||||
@@ -799,4 +804,14 @@ public interface MenuItem {
|
||||
default CharSequence getTooltipText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if {@link #setShowAsAction(int)} was set to {@link #SHOW_AS_OVERFLOW_ALWAYS}.
|
||||
* Default value if {@code false}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
default boolean requiresOverflow() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3846,7 +3846,7 @@ public class Editor {
|
||||
if (selected == null || selected.isEmpty()) {
|
||||
menu.add(Menu.NONE, TextView.ID_AUTOFILL, MENU_ITEM_ORDER_AUTOFILL,
|
||||
com.android.internal.R.string.autofill)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
.setShowAsAction(MenuItem.SHOW_AS_OVERFLOW_ALWAYS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -656,6 +656,11 @@ public final class MenuItemImpl implements MenuItem {
|
||||
return (mShowAsAction & SHOW_AS_ACTION_ALWAYS) == SHOW_AS_ACTION_ALWAYS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresOverflow() {
|
||||
return (mShowAsAction & SHOW_AS_OVERFLOW_ALWAYS) == SHOW_AS_OVERFLOW_ALWAYS;
|
||||
}
|
||||
|
||||
public void setIsActionButton(boolean isActionButton) {
|
||||
if (isActionButton) {
|
||||
mFlags |= IS_ACTION;
|
||||
|
||||
@@ -49,9 +49,9 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.Transformation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.view.animation.Transformation;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
@@ -60,12 +60,12 @@ import android.widget.ListView;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -1141,7 +1141,18 @@ public final class FloatingToolbar {
|
||||
Preconditions.checkNotNull(menuItems);
|
||||
|
||||
int availableWidth = toolbarWidth;
|
||||
final LinkedList<MenuItem> remainingMenuItems = new LinkedList<MenuItem>(menuItems);
|
||||
|
||||
final LinkedList<MenuItem> remainingMenuItems = new LinkedList<>();
|
||||
// add the overflow menu items to the end of the remainingMenuItems list.
|
||||
final LinkedList<MenuItem> overflowMenuItems = new LinkedList();
|
||||
for (MenuItem menuItem : menuItems) {
|
||||
if (menuItem.requiresOverflow()) {
|
||||
overflowMenuItems.add(menuItem);
|
||||
} else {
|
||||
remainingMenuItems.add(menuItem);
|
||||
}
|
||||
}
|
||||
remainingMenuItems.addAll(overflowMenuItems);
|
||||
|
||||
mMainPanel.removeAllViews();
|
||||
mMainPanel.setPaddingRelative(0, 0, 0, 0);
|
||||
@@ -1150,6 +1161,14 @@ public final class FloatingToolbar {
|
||||
boolean isFirstItem = true;
|
||||
while (!remainingMenuItems.isEmpty()) {
|
||||
final MenuItem menuItem = remainingMenuItems.peek();
|
||||
|
||||
// if this is the first item, regardless of requiresOverflow(), it should be
|
||||
// displayed on the main panel. Otherwise all items including this one will be
|
||||
// overflow items, and should be displayed in overflow panel.
|
||||
if(!isFirstItem && menuItem.requiresOverflow()) {
|
||||
break;
|
||||
}
|
||||
|
||||
View menuItemButton = createMenuItemButton(mContext, menuItem, mIconTextSpacing);
|
||||
|
||||
// Adding additional start padding for the first button to even out button spacing.
|
||||
@@ -1226,13 +1245,17 @@ public final class FloatingToolbar {
|
||||
availableWidth -= menuItemButtonWidth + extraPadding;
|
||||
remainingMenuItems.pop();
|
||||
} else {
|
||||
// Reserve space for overflowButton.
|
||||
mMainPanel.setPaddingRelative(0, 0, mOverflowButtonSize.getWidth(), 0);
|
||||
break;
|
||||
}
|
||||
lastGroupId = menuItem.getGroupId();
|
||||
isFirstItem = false;
|
||||
}
|
||||
|
||||
if (!remainingMenuItems.isEmpty()) {
|
||||
// Reserve space for overflowButton.
|
||||
mMainPanel.setPaddingRelative(0, 0, mOverflowButtonSize.getWidth(), 0);
|
||||
}
|
||||
|
||||
mMainPanelSize = measure(mMainPanel);
|
||||
return remainingMenuItems;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user