public class

ContextualToolbarMenuItem

extends AppCompatImageButton
implements View.OnLayoutChangeListener View.OnLongClickListener
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ android.widget.ImageButton
         ↳ android.support.v7.widget.AppCompatImageButton
           ↳ com.pspdfkit.ui.toolbar.ContextualToolbarMenuItem

Class Overview

Represents a single menu item in the ContextualToolbar.

Summary

Nested Classes
enum ContextualToolbarMenuItem.Position Possible positions for toolbar menu items. 
enum ContextualToolbarMenuItem.SubmenuIndicatorPosition Possible positions for submenu indicator (in those views that have it). 
[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Methods
void adaptSubmenuIndicatorToParentPosition(ToolbarCoordinatorLayout.LayoutParams.Position position)
Used to allow parent to notify child items of it's new position so the submenu indicator arrow can be placed correctly.
static ContextualToolbarMenuItem createGroupItem(int id, ContextualToolbarMenuItem.Position position, boolean isSelectable, List<ContextualToolbarMenuItem> subMenuItems, ContextualToolbarMenuItem defaultSelectedItem)
Creates a contextual toolbar menu group item with the provided properties.
static ContextualToolbarMenuItem createSingleItem(Context context, int id, Drawable icon, String title, int iconColor, int iconColorActivated, ContextualToolbarMenuItem.Position position, boolean isSelectable)
Creates a contextual toolbar menu single item with the provided properties.
ContextualToolbarMenuItem getDefaultSelectedMenuItem()
Gets an item that will be selected by default when this item is pressed.
Drawable getIcon()
Gets the icon used for the menu item.
int getIconColor()
Gets the default color of the menu icon.
int getIconColorActivated()
Gets the color for the icon when activated (if the item is selectable).
ContextualToolbarMenuItem.Position getPosition()
Gets the position of menu item in the toolbar.
List<ContextualToolbarMenuItem> getSubMenuItems()
Gets the list of submenu items (if any).
String getTitle()
Gets the title assigned to the menu item.
boolean hasSubmenu()
Returns true if the menu item has a submenu.
boolean isSelectable()
Indicates whether the item is selectable, or just clickable.
boolean isSelected()
void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
boolean onLongClick(View v)
Called when a view has been clicked and held.
void setCloseSubmenuOnItemClick(boolean shouldCloseSubmenuOnItemClick)
Set if the submenu should be hidden when any item in the submenu is clicked.
void setDefaultSelectedMenuItem(ContextualToolbarMenuItem defaultSelectedMenuItem)
Sets an item that will be selected by default when this item is pressed.
void setDisplayOutsideOfSubmenuIfPossible(boolean displayOutsideOfSubmenuIfPossible)
Sets to display menu item as separate item outside of submenu if there's room in the toolbar.
void setEnabled(boolean enabled)
Set the enabled state of this view.
void setIcon(Drawable icon)
Sets the icon to be used for the menu item.
void setIconColor(int iconColor)
Sets the default color for the menu icon.
void setIconColorActivated(int iconColorActivated)
Sets the color for the icon when activated (if the item is selectable).
void setOpenSubmenuOnClick(boolean openSubmenuOnClick)
Set if the submenu should be opened after clicking on the menu item.
void setPosition(ContextualToolbarMenuItem.Position position)
Sets the position of menu item in the toolbar, END by default.
void setSelectable(boolean selectable)
Set if item is selectable or not.
void setSelected(boolean selected)
Set selected state to the item.
void setSubMenuItems(List<ContextualToolbarMenuItem> subMenuItems, ContextualToolbarMenuItem defaultSelectedMenuItem)
Sets the submenu items to the menu item and a default selected item.
void setTintingEnabled(boolean useTint)
Sets whether the icon should be tinted in ContextualToolbarMenuItem#iconColor or left as originally provided.
void setTitle(String title)
Sets the title for the menu item.
boolean shouldCloseSubmenuOnItemClick(ContextualToolbarMenuItem clickedSubmenuItem)
Indicates whether the submenu should be closed after clicking on its items.
boolean shouldDisplayOutsideOfSubmenuIfPossible()
Check whether this item can be expanded from submenu if there's room in the toolbar.
boolean shouldOpenSubmenuOnClick()
Indicates whether the submenu should be opened after clicking on the menu item.
Protected Methods
void onDraw(Canvas canvas)
[Expand]
Inherited Methods
From class android.support.v7.widget.AppCompatImageButton
From class android.widget.ImageButton
From class android.widget.ImageView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.support.v4.view.TintableBackgroundView
From interface android.support.v4.widget.TintableImageSourceView
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnLayoutChangeListener
From interface android.view.View.OnLongClickListener
From interface android.view.accessibility.AccessibilityEventSource

Public Methods

public void adaptSubmenuIndicatorToParentPosition (ToolbarCoordinatorLayout.LayoutParams.Position position)

Used to allow parent to notify child items of it's new position so the submenu indicator arrow can be placed correctly.

Parameters
position Position of the parent toolbar, null to avoid showing any indicators.

public static ContextualToolbarMenuItem createGroupItem (int id, ContextualToolbarMenuItem.Position position, boolean isSelectable, List<ContextualToolbarMenuItem> subMenuItems, ContextualToolbarMenuItem defaultSelectedItem)

Creates a contextual toolbar menu group item with the provided properties.

Parameters
id Menu item id.
position Position of the menu item in the toolbar.
isSelectable true if menu item can be selected, false if it can only be clicked.
subMenuItems Items contained in the submenu.
defaultSelectedItem Item to be selected by default.

public static ContextualToolbarMenuItem createSingleItem (Context context, int id, Drawable icon, String title, int iconColor, int iconColorActivated, ContextualToolbarMenuItem.Position position, boolean isSelectable)

Creates a contextual toolbar menu single item with the provided properties.

Parameters
context Context of the component creating the button.
id Menu item id.
icon Icon for the menu item.
title Menu item title.
iconColor Menu item color for default selected state (not selected).
iconColorActivated Menu item color for selected state (if possible).
position Position of the menu item in the toolbar.
isSelectable true if menu item can be selected, false if it can only be clicked.

public ContextualToolbarMenuItem getDefaultSelectedMenuItem ()

Gets an item that will be selected by default when this item is pressed. If there's not submenu, this method returns null.

Returns
  • Item to be selected by default.

public Drawable getIcon ()

Gets the icon used for the menu item.

Returns
  • Menu item drawable.

public int getIconColor ()

Gets the default color of the menu icon.

Returns
  • Menu item color (tint).

public int getIconColorActivated ()

Gets the color for the icon when activated (if the item is selectable).

Returns
  • Menu item color (tint) when activated.

public ContextualToolbarMenuItem.Position getPosition ()

Gets the position of menu item in the toolbar.

Returns
  • Item's toolbar position, END by default.

public List<ContextualToolbarMenuItem> getSubMenuItems ()

Gets the list of submenu items (if any).

Returns
  • List of submenu items, or null if there aren't any.

public String getTitle ()

Gets the title assigned to the menu item.

Returns
  • Menu item title.

public boolean hasSubmenu ()

Returns true if the menu item has a submenu.

public boolean isSelectable ()

Indicates whether the item is selectable, or just clickable.

Returns
  • true is menu item is selectable, false if it's only clickable.

public boolean isSelected ()

public void onLayoutChange (View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)

public 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.

public void setCloseSubmenuOnItemClick (boolean shouldCloseSubmenuOnItemClick)

Set if the submenu should be hidden when any item in the submenu is clicked.

Parameters
shouldCloseSubmenuOnItemClick If true, clicking on the submenu item will close the submenu, otherwise it remains open.

public void setDefaultSelectedMenuItem (ContextualToolbarMenuItem defaultSelectedMenuItem)

Sets an item that will be selected by default when this item is pressed. This method throws error if default selected menu item is not in the list of submenu items.

Parameters
defaultSelectedMenuItem Item to be selected by default, null for the owner to be selected.

public void setDisplayOutsideOfSubmenuIfPossible (boolean displayOutsideOfSubmenuIfPossible)

Sets to display menu item as separate item outside of submenu if there's room in the toolbar.

Parameters
displayOutsideOfSubmenuIfPossible true to display as separate item if possible.

public void setEnabled (boolean enabled)

Set the enabled state of this view. The interpretation of the enabled state varies by subclass.

Parameters
enabled true if this view is enabled, false otherwise.

public void setIcon (Drawable icon)

Sets the icon to be used for the menu item.

Parameters
icon Drawable used as the menu icon.

public void setIconColor (int iconColor)

Sets the default color for the menu icon.

Parameters
iconColor Default menu icon color.

public void setIconColorActivated (int iconColorActivated)

Sets the color for the icon when activated (if the item is selectable).

Parameters
iconColorActivated Background circle color when the item is activated.

public void setOpenSubmenuOnClick (boolean openSubmenuOnClick)

Set if the submenu should be opened after clicking on the menu item.

Note: This property is not used when menu item is selectable isSelectable(). Clicking toggles selection in this case.

Parameters
openSubmenuOnClick If true and menu item is not selectable, clicking on the menu item will open its submenu. Otherwise only the long click opens the submenu.

public void setPosition (ContextualToolbarMenuItem.Position position)

Sets the position of menu item in the toolbar, END by default.

Parameters
position Item's toolbar position.

public void setSelectable (boolean selectable)

Set if item is selectable or not.

Parameters
selectable If true, the item can be selected/activated, otherwise it's just clickable.

public void setSelected (boolean selected)

Set selected state to the item. Not applied if the item is not selectable.

Parameters
selected If true the item is selected, otherwise it's de-selected.

public void setSubMenuItems (List<ContextualToolbarMenuItem> subMenuItems, ContextualToolbarMenuItem defaultSelectedMenuItem)

Sets the submenu items to the menu item and a default selected item.

Parameters
subMenuItems Menu items to be displayed once this item is clicked, null if no owners.
defaultSelectedMenuItem Item to be selected by default, null for the owner to be selected.

public void setTintingEnabled (boolean useTint)

Sets whether the icon should be tinted in ContextualToolbarMenuItem#iconColor or left as originally provided.

Parameters
useTint If the tint should be used on the icon.

public void setTitle (String title)

Sets the title for the menu item.

Parameters
title Title to assign to the menu item.

public boolean shouldCloseSubmenuOnItemClick (ContextualToolbarMenuItem clickedSubmenuItem)

Indicates whether the submenu should be closed after clicking on its items.

Returns
  • true if the submenu should be closed after clicking on its items.

public boolean shouldDisplayOutsideOfSubmenuIfPossible ()

Check whether this item can be expanded from submenu if there's room in the toolbar.

Returns
  • true to enable showing action outside of it's group when toolbar has enough room to expand some items from submenu.

public boolean shouldOpenSubmenuOnClick ()

Indicates whether the submenu should be opened after clicking on the menu item.

Returns
  • true if the submenu should be opened after clicking on the menu item, false when the submenu should be opened only when long clicking on this menu item.

Protected Methods

protected void onDraw (Canvas canvas)