Methods Summary |
---|
protected void | addItemView(android.view.View itemView, int childIndex)Add an item view at the given index.
final ViewGroup currentParent = (ViewGroup) itemView.getParent();
if (currentParent != null) {
currentParent.removeView(itemView);
}
((ViewGroup) mMenuView).addView(itemView, childIndex);
|
public abstract void | bindItemView(MenuItemImpl item, MenuView.ItemView itemView)Bind item data to an existing item view.
|
public boolean | collapseItemActionView(MenuBuilder menu, MenuItemImpl item)
return false;
|
public MenuView.ItemView | createItemView(android.view.ViewGroup parent)Create a new item view that can be re-bound to other item data later.
return (MenuView.ItemView) mSystemInflater.inflate(mItemLayoutRes, parent, false);
|
public boolean | expandItemActionView(MenuBuilder menu, MenuItemImpl item)
return false;
|
protected boolean | filterLeftoverView(android.view.ViewGroup parent, int childIndex)Filter the child view at index and remove it if appropriate.
parent.removeViewAt(childIndex);
return true;
|
public boolean | flagActionItems()
return false;
|
public Callback | getCallback()
return mCallback;
|
public int | getId()
return mId;
|
public android.view.View | getItemView(MenuItemImpl item, android.view.View convertView, android.view.ViewGroup parent)Prepare an item view for use. See AdapterView for the basic idea at work here.
This may require creating a new item view, but well-behaved implementations will
re-use the view passed as convertView if present. The returned view will be populated
with data from the item parameter.
MenuView.ItemView itemView;
if (convertView instanceof MenuView.ItemView) {
itemView = (MenuView.ItemView) convertView;
} else {
itemView = createItemView(parent);
}
bindItemView(item, itemView);
return (View) itemView;
|
public MenuView | getMenuView(android.view.ViewGroup root)
if (mMenuView == null) {
mMenuView = (MenuView) mSystemInflater.inflate(mMenuLayoutRes, root, false);
mMenuView.initialize(mMenu);
updateMenuView(true);
}
return mMenuView;
|
public void | initForMenu(android.content.Context context, MenuBuilder menu)
mContext = context;
mInflater = LayoutInflater.from(mContext);
mMenu = menu;
|
public void | onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing)
if (mCallback != null) {
mCallback.onCloseMenu(menu, allMenusAreClosing);
}
|
public boolean | onSubMenuSelected(SubMenuBuilder menu)
if (mCallback != null) {
return mCallback.onOpenSubMenu(menu);
}
return false;
|
public void | setCallback(Callback cb)
mCallback = cb;
|
public void | setId(int id)
mId = id;
|
public boolean | shouldIncludeItem(int childIndex, MenuItemImpl item)Filter item by child index and item data.
return true;
|
public void | updateMenuView(boolean cleared)Reuses item views when it can
final ViewGroup parent = (ViewGroup) mMenuView;
if (parent == null) return;
int childIndex = 0;
if (mMenu != null) {
mMenu.flagActionItems();
ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
final int itemCount = visibleItems.size();
for (int i = 0; i < itemCount; i++) {
MenuItemImpl item = visibleItems.get(i);
if (shouldIncludeItem(childIndex, item)) {
final View convertView = parent.getChildAt(childIndex);
final MenuItemImpl oldItem = convertView instanceof MenuView.ItemView ?
((MenuView.ItemView) convertView).getItemData() : null;
final View itemView = getItemView(item, convertView, parent);
if (item != oldItem) {
// Don't let old states linger with new data.
itemView.setPressed(false);
itemView.jumpDrawablesToCurrentState();
}
if (itemView != convertView) {
addItemView(itemView, childIndex);
}
childIndex++;
}
}
}
// Remove leftover views.
while (childIndex < parent.getChildCount()) {
if (!filterLeftoverView(parent, childIndex)) {
childIndex++;
}
}
|