Merge "Fix bug 5355889 - Search action showing up in the menu dropdown in spite of search actionview being expanded"
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1258,4 +1258,8 @@ public class MenuBuilder implements Menu {
|
||||
}
|
||||
return collapsed;
|
||||
}
|
||||
|
||||
public MenuItemImpl getExpandedItem() {
|
||||
return mExpandedItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
return items.size();
|
||||
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;
|
||||
}
|
||||
|
||||
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 int getId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
private class ExpandedIndexObserver extends DataSetObserver {
|
||||
@Override
|
||||
public void onChanged() {
|
||||
mAdapter.findExpandedIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user