Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
bit CtsWidgetTestCases:android.widget.cts.EditTextTest
Bug:
62271937
Change-Id: Ib3447281f3bd1abc811a25fc55ad55e34e155bbb
* a larger segment of its container.
*/
public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8;
* 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.
/**
* Interface definition for a callback to be invoked when a menu item is
* clicked.
default CharSequence getTooltipText() {
return null;
}
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;
+ }
if (selected == null || selected.isEmpty()) {
menu.add(Menu.NONE, TextView.ID_AUTOFILL, MENU_ITEM_ORDER_AUTOFILL,
com.android.internal.R.string.autofill)
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);
return (mShowAsAction & SHOW_AS_ACTION_ALWAYS) == SHOW_AS_ACTION_ALWAYS;
}
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;
public void setIsActionButton(boolean isActionButton) {
if (isActionButton) {
mFlags |= IS_ACTION;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
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.AnimationUtils;
import android.view.animation.Interpolator;
+import android.view.animation.Transformation;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
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 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;
/**
import java.util.Objects;
/**
Preconditions.checkNotNull(menuItems);
int availableWidth = toolbarWidth;
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);
mMainPanel.removeAllViews();
mMainPanel.setPaddingRelative(0, 0, 0, 0);
boolean isFirstItem = true;
while (!remainingMenuItems.isEmpty()) {
final MenuItem menuItem = remainingMenuItems.peek();
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.
View menuItemButton = createMenuItemButton(mContext, menuItem, mIconTextSpacing);
// Adding additional start padding for the first button to even out button spacing.
availableWidth -= menuItemButtonWidth + extraPadding;
remainingMenuItems.pop();
} else {
availableWidth -= menuItemButtonWidth + extraPadding;
remainingMenuItems.pop();
} else {
- // Reserve space for overflowButton.
- mMainPanel.setPaddingRelative(0, 0, mOverflowButtonSize.getWidth(), 0);
break;
}
lastGroupId = menuItem.getGroupId();
isFirstItem = false;
}
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;
}
mMainPanelSize = measure(mMainPanel);
return remainingMenuItems;
}