Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1801c9a authored by Siyamed Sinir's avatar Siyamed Sinir Committed by android-build-merger
Browse files

Merge "Force Autofill in FloatingToolbar overflow menu" into oc-dev

am: bc626c63

Change-Id: I8688bda33124a78d439f1cbcf23926a0672b0735
parents fa6b5ac3 bc626c63
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -71,6 +71,11 @@ public interface MenuItem {
     */
    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;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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);
                }
            }

+5 −0
Original line number Diff line number Diff line
@@ -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;
+30 −7
Original line number Diff line number Diff line
@@ -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;
        }