com.actionbarsherlock.internal.view.menu
Class BaseMenuPresenter

java.lang.Object
  extended by com.actionbarsherlock.internal.view.menu.BaseMenuPresenter
All Implemented Interfaces:
MenuPresenter
Direct Known Subclasses:
ActionMenuPresenter

public abstract class BaseMenuPresenter
extends Object
implements MenuPresenter

Base class for MenuPresenters that have a consistent container view and item views. Behaves similarly to an AdapterView in that existing item views will be reused if possible when items change.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.actionbarsherlock.internal.view.menu.MenuPresenter
MenuPresenter.Callback
 
Field Summary
protected  android.content.Context mContext
           
protected  android.view.LayoutInflater mInflater
           
protected  MenuBuilder mMenu
           
protected  MenuView mMenuView
           
protected  android.content.Context mSystemContext
           
protected  android.view.LayoutInflater mSystemInflater
           
 
Constructor Summary
BaseMenuPresenter(android.content.Context context, int menuLayoutRes, int itemLayoutRes)
          Construct a new BaseMenuPresenter.
 
Method Summary
protected  void addItemView(android.view.View itemView, int childIndex)
          Add an item view at the given index.
abstract  void bindItemView(MenuItemImpl item, MenuView.ItemView itemView)
          Bind item data to an existing item view.
 boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item)
          Called when a menu item with a collapsable action view should collapse its action view.
 MenuView.ItemView createItemView(android.view.ViewGroup parent)
          Create a new item view that can be re-bound to other item data later.
 boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item)
          Called when a menu item with a collapsable action view should expand its action view.
protected  boolean filterLeftoverView(android.view.ViewGroup parent, int childIndex)
          Filter the child view at index and remove it if appropriate.
 boolean flagActionItems()
          Called by Menu implementations to flag items that will be shown as actions.
 int getId()
          Returns an ID for determining how to save/restore instance state.
 android.view.View getItemView(MenuItemImpl item, android.view.View convertView, android.view.ViewGroup parent)
          Prepare an item view for use.
 MenuView getMenuView(android.view.ViewGroup root)
          Retrieve a MenuView to display the menu specified in #initForMenu(Context, Menu).
 void initForMenu(android.content.Context context, MenuBuilder menu)
          Initialize this presenter for the given context and menu.
 void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing)
          Called by Menu implementations to indicate that a menu or submenu is closing.
 boolean onSubMenuSelected(SubMenuBuilder menu)
          Called by Menu implementations to indicate that a submenu item has been selected.
 void setCallback(MenuPresenter.Callback cb)
          Set a callback object that will be notified of menu events related to this specific presentation.
 void setId(int id)
           
 boolean shouldIncludeItem(int childIndex, MenuItemImpl item)
          Filter item by child index and item data.
 void updateMenuView(boolean cleared)
          Reuses item views when it can
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.actionbarsherlock.internal.view.menu.MenuPresenter
onRestoreInstanceState, onSaveInstanceState
 

Field Detail

mSystemContext

protected android.content.Context mSystemContext

mContext

protected android.content.Context mContext

mMenu

protected MenuBuilder mMenu

mSystemInflater

protected android.view.LayoutInflater mSystemInflater

mInflater

protected android.view.LayoutInflater mInflater

mMenuView

protected MenuView mMenuView
Constructor Detail

BaseMenuPresenter

public BaseMenuPresenter(android.content.Context context,
                         int menuLayoutRes,
                         int itemLayoutRes)
Construct a new BaseMenuPresenter.

Parameters:
context - Context for generating system-supplied views
menuLayoutRes - Layout resource ID for the menu container view
itemLayoutRes - Layout resource ID for a single item view
Method Detail

initForMenu

public void initForMenu(android.content.Context context,
                        MenuBuilder menu)
Description copied from interface: MenuPresenter
Initialize this presenter for the given context and menu. This method is called by MenuBuilder when a presenter is added. See MenuBuilder.addMenuPresenter(MenuPresenter)

Specified by:
initForMenu in interface MenuPresenter
Parameters:
context - Context for this presenter; used for view creation and resource management
menu - Menu to host

getMenuView

public MenuView getMenuView(android.view.ViewGroup root)
Description copied from interface: MenuPresenter
Retrieve a MenuView to display the menu specified in #initForMenu(Context, Menu).

Specified by:
getMenuView in interface MenuPresenter
Parameters:
root - Intended parent of the MenuView.
Returns:
A freshly created MenuView.

updateMenuView

public void updateMenuView(boolean cleared)
Reuses item views when it can

Specified by:
updateMenuView in interface MenuPresenter
Parameters:
cleared - true if the menu was entirely cleared

addItemView

protected void addItemView(android.view.View itemView,
                           int childIndex)
Add an item view at the given index.

Parameters:
itemView - View to add
childIndex - Index within the parent to insert at

filterLeftoverView

protected boolean filterLeftoverView(android.view.ViewGroup parent,
                                     int childIndex)
Filter the child view at index and remove it if appropriate.

Parameters:
parent - Parent to filter from
childIndex - Index to filter
Returns:
true if the child view at index was removed

setCallback

public void setCallback(MenuPresenter.Callback cb)
Description copied from interface: MenuPresenter
Set a callback object that will be notified of menu events related to this specific presentation.

Specified by:
setCallback in interface MenuPresenter
Parameters:
cb - Callback that will be notified of future events

createItemView

public MenuView.ItemView createItemView(android.view.ViewGroup parent)
Create a new item view that can be re-bound to other item data later.

Returns:
The new item view

getItemView

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.

Parameters:
item - Item to present
convertView - Existing view to reuse
parent - Intended parent view - use for inflation.
Returns:
View that presents the requested menu item

bindItemView

public abstract void bindItemView(MenuItemImpl item,
                                  MenuView.ItemView itemView)
Bind item data to an existing item view.

Parameters:
item - Item to bind
itemView - View to populate with item data

shouldIncludeItem

public boolean shouldIncludeItem(int childIndex,
                                 MenuItemImpl item)
Filter item by child index and item data.

Parameters:
childIndex - Indended presentation index of this item
item - Item to present
Returns:
true if this item should be included in this menu presentation; false otherwise

onCloseMenu

public void onCloseMenu(MenuBuilder menu,
                        boolean allMenusAreClosing)
Description copied from interface: MenuPresenter
Called by Menu implementations to indicate that a menu or submenu is closing. Presenter implementations should close the representation of the menu indicated as necessary and notify a registered callback.

Specified by:
onCloseMenu in interface MenuPresenter
Parameters:
menu - Menu or submenu that is closing.
allMenusAreClosing - True if all associated menus are closing.

onSubMenuSelected

public boolean onSubMenuSelected(SubMenuBuilder menu)
Description copied from interface: MenuPresenter
Called by Menu implementations to indicate that a submenu item has been selected. An active Callback should be notified, and if applicable the presenter should present the submenu.

Specified by:
onSubMenuSelected in interface MenuPresenter
Parameters:
menu - SubMenu being opened
Returns:
true if the the event was handled, false otherwise.

flagActionItems

public boolean flagActionItems()
Description copied from interface: MenuPresenter
Called by Menu implementations to flag items that will be shown as actions.

Specified by:
flagActionItems in interface MenuPresenter
Returns:
true if this presenter changed the action status of any items.

expandItemActionView

public boolean expandItemActionView(MenuBuilder menu,
                                    MenuItemImpl item)
Description copied from interface: MenuPresenter
Called when a menu item with a collapsable action view should expand its action view.

Specified by:
expandItemActionView in interface MenuPresenter
Parameters:
menu - Menu containing the item to be expanded
item - Item to be expanded
Returns:
true if this presenter expanded the action view, false otherwise.

collapseItemActionView

public boolean collapseItemActionView(MenuBuilder menu,
                                      MenuItemImpl item)
Description copied from interface: MenuPresenter
Called when a menu item with a collapsable action view should collapse its action view.

Specified by:
collapseItemActionView in interface MenuPresenter
Parameters:
menu - Menu containing the item to be collapsed
item - Item to be collapsed
Returns:
true if this presenter collapsed the action view, false otherwise.

getId

public int getId()
Description copied from interface: MenuPresenter
Returns an ID for determining how to save/restore instance state.

Specified by:
getId in interface MenuPresenter
Returns:
a valid ID value.

setId

public void setId(int id)


Copyright © 2012-2013. All Rights Reserved.