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

Commit 275702c2 authored by Adam Powell's avatar Adam Powell
Browse files

Fix bug 5355889 - Search action showing up in the menu dropdown in

spite of search actionview being expanded

Make sure that menu items with an expanded action view don't show up
in list menus presenting the rest of the menu.

Change-Id: I8c7b4e184a9d3ea2457543d0b8b36bc8e7068052
parent b410330b
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -200,8 +200,19 @@ public class ActionMenuPresenter extends BaseMenuPresenter
            }
        }

        final boolean hasOverflow = mReserveOverflow && mMenu != null &&
                mMenu.getNonActionItems().size() > 0;
        final ArrayList<MenuItemImpl> nonActionItems = mMenu != null ?
                mMenu.getNonActionItems() : null;

        boolean hasOverflow = false;
        if (mReserveOverflow && nonActionItems != null) {
            final int count = nonActionItems.size();
            if (count == 1) {
                hasOverflow = !nonActionItems.get(0).isActionViewExpanded();
            } else {
                hasOverflow = count > 0;
            }
        }

        if (hasOverflow) {
            if (mOverflowButton == null) {
                mOverflowButton = new OverflowMenuButton(mContext);
+42 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.view.menu;

import android.content.Context;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.SparseArray;
@@ -47,7 +48,7 @@ public class ListMenuPresenter implements MenuPresenter, AdapterView.OnItemClick
    int mItemLayoutRes;

    private Callback mCallback;
    private MenuAdapter mAdapter;
    MenuAdapter mAdapter;

    private int mId;

@@ -216,14 +217,29 @@ public class ListMenuPresenter implements MenuPresenter, AdapterView.OnItemClick
    }

    private class MenuAdapter extends BaseAdapter {
        private int mExpandedIndex = -1;

        public MenuAdapter() {
            registerDataSetObserver(new ExpandedIndexObserver());
            findExpandedIndex();
        }

        public int getCount() {
            ArrayList<MenuItemImpl> items = mMenu.getNonActionItems();
            return items.size() - mItemIndexOffset;
            int count = items.size() - mItemIndexOffset;
            if (mExpandedIndex < 0) {
                return count;
            }
            return count - 1;
        }

        public MenuItemImpl getItem(int position) {
            ArrayList<MenuItemImpl> items = mMenu.getNonActionItems();
            return items.get(position + mItemIndexOffset);
            position += mItemIndexOffset;
            if (mExpandedIndex >= 0 && position >= mExpandedIndex) {
                position++;
            }
            return items.get(position);
        }

        public long getItemId(int position) {
@@ -241,5 +257,28 @@ public class ListMenuPresenter implements MenuPresenter, AdapterView.OnItemClick
            itemView.initialize(getItem(position), 0);
            return convertView;
        }

        void findExpandedIndex() {
            final MenuItemImpl expandedItem = mMenu.getExpandedItem();
            if (expandedItem != null) {
                final ArrayList<MenuItemImpl> items = mMenu.getNonActionItems();
                final int count = items.size();
                for (int i = 0; i < count; i++) {
                    final MenuItemImpl item = items.get(i);
                    if (item == expandedItem) {
                        mExpandedIndex = i;
                        return;
                    }
                }
            }
            mExpandedIndex = -1;
        }
    }

    private class ExpandedIndexObserver extends DataSetObserver {
        @Override
        public void onChanged() {
            mAdapter.findExpandedIndex();
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -1258,4 +1258,8 @@ public class MenuBuilder implements Menu {
        }
        return collapsed;
    }

    public MenuItemImpl getExpandedItem() {
        return mExpandedItem;
    }
}
+45 −12
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.view.menu;

import android.content.Context;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.os.Parcelable;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -286,22 +287,45 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
        return false;
    }

    @Override
    public int getId() {
        return 0;
    }

    @Override
    public Parcelable onSaveInstanceState() {
        return null;
    }

    @Override
    public void onRestoreInstanceState(Parcelable state) {
    }

    private class MenuAdapter extends BaseAdapter {
        private MenuBuilder mAdapterMenu;
        private int mExpandedIndex = -1;

        public MenuAdapter(MenuBuilder menu) {
            mAdapterMenu = menu;
            registerDataSetObserver(new ExpandedIndexObserver());
            findExpandedIndex();
        }

        public int getCount() {
            ArrayList<MenuItemImpl> items = mOverflowOnly ?
                    mAdapterMenu.getNonActionItems() : mAdapterMenu.getVisibleItems();
            if (mExpandedIndex < 0) {
                return items.size();
            }
            return items.size() - 1;
        }

        public MenuItemImpl getItem(int position) {
            ArrayList<MenuItemImpl> items = mOverflowOnly ?
                    mAdapterMenu.getNonActionItems() : mAdapterMenu.getVisibleItems();
            if (mExpandedIndex >= 0 && position >= mExpandedIndex) {
                position++;
            }
            return items.get(position);
        }

@@ -323,19 +347,28 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On
            itemView.initialize(getItem(position), 0);
            return convertView;
        }
    }

    @Override
    public int getId() {
        return 0;
        void findExpandedIndex() {
            final MenuItemImpl expandedItem = mMenu.getExpandedItem();
            if (expandedItem != null) {
                final ArrayList<MenuItemImpl> items = mMenu.getNonActionItems();
                final int count = items.size();
                for (int i = 0; i < count; i++) {
                    final MenuItemImpl item = items.get(i);
                    if (item == expandedItem) {
                        mExpandedIndex = i;
                        return;
                    }
                }
            }
            mExpandedIndex = -1;
        }

    @Override
    public Parcelable onSaveInstanceState() {
        return null;
    }

    private class ExpandedIndexObserver extends DataSetObserver {
        @Override
    public void onRestoreInstanceState(Parcelable state) {
        public void onChanged() {
            mAdapter.findExpandedIndex();
        }
    }
}