Class ContextualToolbar
-
- All Implemented Interfaces:
-
android.graphics.drawable.Drawable.Callback
,android.view.KeyEvent.Callback
,android.view.View.OnClickListener
,android.view.View.OnLongClickListener
,android.view.ViewManager
,android.view.ViewParent
,android.view.accessibility.AccessibilityEventSource
public abstract class ContextualToolbar<T extends SpecialModeController> extends ViewGroup implements View.OnClickListener, View.OnLongClickListener
Base class of all contextual toolbars.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
ContextualToolbar.OnMenuItemClickListener
Listener for menu items clicks.
public interface
ContextualToolbar.OnMenuItemLongClickListener
Listener for long clicks on menu items with submenu.
-
Field Summary
Fields Modifier and Type Field Description public final static int
MIN_TOOLBAR_CAPACITY
public final static int
DRAG_BUTTON_ALPHA
public final static int
CONTEXTUAL_TOOLBAR_PADDING_DP
public final static int
DEFAULT_TOOLBAR_HEIGHT
public ContextualToolbarMenuItem
dragButton
public List<ContextualToolbarMenuItem>
menuItems
public boolean
isDraggable
public boolean
isAttached
-
Method Summary
Modifier and Type Method Description ContextualToolbarMenuItem
getDragButton()
Returns the button used to drag the toolbar (if detachable). void
setDragButton(ContextualToolbarMenuItem dragButton)
Sets the button used to drag the toolbar (if detachable). List<ContextualToolbarMenuItem>
getMenuItems()
Gets the list of originally set menu items. void
setMenuItems(@NonNull() List<ContextualToolbarMenuItem> menuItems)
Sets contextual toolbar menu items. boolean
isDraggable()
Returns true
when toolbar is draggable.void
setDraggable(boolean draggable)
Sets whether the toolbar is draggable or not. final boolean
isAttached()
Indicates whether the toolbar is attached or detached. final void
setAttached(boolean isAttached)
Sets whether the toolbar is attached or detached from the layout. int
getParentMenuId(int childMenuId)
abstract void
bindController(T specialModeController)
Binds the special mode controller to this toolbar. abstract void
unbindController()
Unbinds the bound controller (if any). abstract boolean
isControllerBound()
Returns true
if the controller is bound.boolean
onTouchEvent(MotionEvent event)
void
setMenuItemGroupingRule(@Nullable() MenuItemGroupingRule groupingRule)
Sets the rule for grouping menu items. List<ContextualToolbarMenuItem>
onMenuItemsGrouped(@NonNull() List<ContextualToolbarMenuItem> menuItems)
A method called once the flat items provided through setMenuItems have been grouped by the MenuItemGroupingRule that can be set with setMenuItemGroupingRule and with DefaultMenuItemGroupingRule as the default one. int
getSubmenuSizePx()
Returns the submenu's size in pixels, or the amount of space needed for the submenu. int
getToolbarSizeInPx()
Returns the toolbar's size in pixels (height in horizontal mode, width in vertical mode) This method has been deprecated and will be removed in a later version. boolean
onBackPressed()
Called when onBackPressed() to wire up back press with back and close buttons. ContextualToolbarMenuItem
findItemById(@IdRes() int menuItemId)
Finds a menu item with specific ID in a list of currently displayed menu items. boolean
setMenuItemVisibility(@IdRes() int menuItemId, int visibility)
Shows or hides a menu item if that menu item currently exists. boolean
setMenuItemEnabled(@IdRes() int menuItemId, boolean enabled)
Enables or disables a menu item if that menu item currently exists. void
setToolbarCoordinatorController(@Nullable() ToolbarCoordinatorLayoutController coordinatorController)
Sets the toolbar coordinator controller for communication with . ContextualToolbarMenuItem
getCloseButton()
Returns the button used to close the toolbar. void
setCloseButton(ContextualToolbarMenuItem closeButton)
Sets the button used to close the toolbar. ToolbarCoordinatorLayout.LayoutParams.Position
getPosition()
Gets position of the toolbar. void
setPosition(ToolbarCoordinatorLayout.LayoutParams.Position position)
Sets position of the toolbar. void
onClick(View v)
boolean
onLongClick(View v)
Called when a view has been clicked and held. boolean
hasOpenedSubmenu()
Returns true if this contextual toolbar have currently opened submenu. void
setUseBackButtonForCloseWhenHorizontal(boolean useBackButtonForCloseWhenHorizontal)
Sets whether to use back button for closing the toolbar when the toolbar is placed horizontally. void
setOnMenuItemClickListener(@Nullable() ContextualToolbar.OnMenuItemClickListener listener)
Sets a listener for menu item clicks on the toolbar. void
setOnMenuItemLongClickListener(@Nullable() ContextualToolbar.OnMenuItemLongClickListener listener)
Sets a listener for menu item long clicks. -
-
Method Detail
-
getDragButton
ContextualToolbarMenuItem getDragButton()
Returns the button used to drag the toolbar (if detachable).
- Returns:
Contextual toolbar's drag button.
-
setDragButton
void setDragButton(ContextualToolbarMenuItem dragButton)
Sets the button used to drag the toolbar (if detachable).
- Parameters:
dragButton
- Button to be set as a drag button.
-
getMenuItems
@NonNull() List<ContextualToolbarMenuItem> getMenuItems()
Gets the list of originally set menu items. Note that the shown menu items in the toolbar could differ from structure because they could be altered by MenuItemGroupingRule that regroups items depending on the available space.
- Returns:
List of originally set toolbar menu items.
-
setMenuItems
void setMenuItems(@NonNull() List<ContextualToolbarMenuItem> menuItems)
Sets contextual toolbar menu items.
- Parameters:
menuItems
- Menu items to populate the toolbar.
-
isDraggable
boolean isDraggable()
Returns
true
when toolbar is draggable.
-
setDraggable
void setDraggable(boolean draggable)
Sets whether the toolbar is draggable or not.
- Parameters:
draggable
- Iftrue
, the toolbar can be dragged.
-
isAttached
final boolean isAttached()
Indicates whether the toolbar is attached or detached.
- Returns:
true
if the toolbar is attached and can't be dragged around,false
otherwise.
-
setAttached
final void setAttached(boolean isAttached)
Sets whether the toolbar is attached or detached from the layout. Being detached means that it can be moved around (used for annotation editor toolbar). In the scope of this view, what it affects is coloring of the view - the toolbar is highlighted when detached. This is usually called from the outside (toolbar coordinator layout).
- Parameters:
isAttached
-true
to set toolbar as attached,false
as detached.
-
getParentMenuId
int getParentMenuId(int childMenuId)
-
bindController
abstract void bindController(T specialModeController)
Binds the special mode controller to this toolbar.
- Parameters:
specialModeController
- Controller to bind to a toolbar.
-
unbindController
abstract void unbindController()
Unbinds the bound controller (if any).
-
isControllerBound
abstract boolean isControllerBound()
Returns
true
if the controller is bound.
-
onTouchEvent
boolean onTouchEvent(MotionEvent event)
-
setMenuItemGroupingRule
void setMenuItemGroupingRule(@Nullable() MenuItemGroupingRule groupingRule)
Sets the rule for grouping menu items. Default one is .
- Parameters:
groupingRule
- Menu items grouping rule to be set.
-
onMenuItemsGrouped
@NonNull() List<ContextualToolbarMenuItem> onMenuItemsGrouped(@NonNull() List<ContextualToolbarMenuItem> menuItems)
A method called once the flat items provided through setMenuItems have been grouped by the MenuItemGroupingRule that can be set with setMenuItemGroupingRule and with DefaultMenuItemGroupingRule as the default one.
By overriding this method you can do final editing before items are added to the toolbar.
- Parameters:
menuItems
- Grouped menu items.- Returns:
Menu items to be set on the toolbar.
-
getSubmenuSizePx
int getSubmenuSizePx()
Returns the submenu's size in pixels, or the amount of space needed for the submenu.
-
getToolbarSizeInPx
@Deprecated(forRemoval = true) int getToolbarSizeInPx()
Returns the toolbar's size in pixels (height in horizontal mode, width in vertical mode) This method has been deprecated and will be removed in a later version. Use getHeight of this class instead
-
onBackPressed
boolean onBackPressed()
Called when onBackPressed() to wire up back press with back and close buttons.
- Returns:
true
if the back press was handled,false
otherwise.
-
findItemById
@Nullable() ContextualToolbarMenuItem findItemById(@IdRes() int menuItemId)
Finds a menu item with specific ID in a list of currently displayed menu items.
- Returns:
A menu item currently displayed in the toolbar with the provided ID, or null if no menu item with the given identifier was found.
-
setMenuItemVisibility
boolean setMenuItemVisibility(@IdRes() int menuItemId, int visibility)
Shows or hides a menu item if that menu item currently exists.
-
setMenuItemEnabled
boolean setMenuItemEnabled(@IdRes() int menuItemId, boolean enabled)
Enables or disables a menu item if that menu item currently exists.
- Parameters:
menuItemId
- ID of the menu item.enabled
-true
if the item should be enabled, false otherwise.- Returns:
true
if the menu item exists and it's enabled status was applied.
-
setToolbarCoordinatorController
void setToolbarCoordinatorController(@Nullable() ToolbarCoordinatorLayoutController coordinatorController)
Sets the toolbar coordinator controller for communication with . Calling this method will replace any previously set controller. You may provide
null
to clear the controller.- Parameters:
coordinatorController
- ToolbarCoordinatorLayoutController that should be notified, ornull
to clear the controller.
-
getCloseButton
ContextualToolbarMenuItem getCloseButton()
Returns the button used to close the toolbar.
- Returns:
Contextual toolbar's close button.
-
setCloseButton
void setCloseButton(ContextualToolbarMenuItem closeButton)
Sets the button used to close the toolbar.
- Parameters:
closeButton
- Button to be set as a close button.
-
getPosition
@NonNull() ToolbarCoordinatorLayout.LayoutParams.Position getPosition()
Gets position of the toolbar.
- Returns:
Position for the toolbar in the ToolbarCoordinatorLayout.
-
setPosition
void setPosition(ToolbarCoordinatorLayout.LayoutParams.Position position)
Sets position of the toolbar.
- Parameters:
position
- Position for the toolbar in the ToolbarCoordinatorLayout.
-
onLongClick
boolean onLongClick(View v)
Called when a view has been clicked and held.
- Parameters:
v
- The view that was clicked and held.- Returns:
true if the callback consumed the long click, false otherwise.
-
hasOpenedSubmenu
boolean hasOpenedSubmenu()
Returns true if this contextual toolbar have currently opened submenu.
-
setUseBackButtonForCloseWhenHorizontal
void setUseBackButtonForCloseWhenHorizontal(boolean useBackButtonForCloseWhenHorizontal)
Sets whether to use back button for closing the toolbar when the toolbar is placed horizontally. Defaults to
true
. Iffalse
the 'X' button will be used and it will be placed on the end of the toolbar.- Parameters:
useBackButtonForCloseWhenHorizontal
-true
to use back button,false
to use 'X' button
-
setOnMenuItemClickListener
void setOnMenuItemClickListener(@Nullable() ContextualToolbar.OnMenuItemClickListener listener)
Sets a listener for menu item clicks on the toolbar. Calling this method will replace any previously set listener. You may provide
null
to clear the listener.- Parameters:
listener
- OnMenuItemClickListener that should be notified, ornull
to clear the listener.
-
setOnMenuItemLongClickListener
void setOnMenuItemLongClickListener(@Nullable() ContextualToolbar.OnMenuItemLongClickListener listener)
Sets a listener for menu item long clicks. Calling this method will replace any previously set listener. You may provide
null
to clear the listener.- Parameters:
listener
- OnMenuItemLongClickListener that should be notified, ornull
to clear the listener.
-
-
-
-