public class

ContextualToolbarMenuItem

extends AppCompatImageButton
implements View.OnLayoutChangeListener View.OnLongClickListener
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ android.widget.ImageButton
         ↳ androidx.appcompat.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.
static ContextualToolbarMenuItem createSingleTextItem(Context context, int id, ContextualToolbarMenuItem.Position position)
Creates a contextual toolbar menu single ite, 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 getUseAlternateBackground()
Returns true, if this menu item triggers a background change on the toolbar.
boolean hasSubmenu()
Returns true if the menu item has a submenu.
void hideColorIndicatorCircle()
boolean isSelectable()
Indicates whether the item is selectable, or just clickable.
boolean isSelected()
boolean isTextItemFirstFromEnd()
Gets whether the item is a text button and the first from the end
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)
Sets 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)
Sets 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)
Sets 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)
Sets if item is selectable or not.
void setSelected(boolean selected)
Sets 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 setTextItemFirstFromEnd(boolean isTextItemFirstFromEnd)
Sets whether the item is a text button and the first from the end
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.
void setUseAlternateBackground(boolean useAlternateBackground)
See #useAlternateBackground for a description.
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.
void showColorIndicatorCircle(int color, float sizeValue)
Protected Methods
void onDraw(Canvas canvas)
[Expand]
Inherited Methods
From class androidx.appcompat.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.view.KeyEvent.Callback
From interface android.view.View.OnLayoutChangeListener
From interface android.view.View.OnLongClickListener
From interface android.view.accessibility.AccessibilityEventSource
From interface androidx.core.view.TintableBackgroundView
From interface androidx.core.widget.TintableImageSourceView

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. This is an image item

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 static ContextualToolbarMenuItem createSingleTextItem (Context context, int id, ContextualToolbarMenuItem.Position position)

Creates a contextual toolbar menu single ite, with the provided properties. This is a text item

Parameters
context Context of the component creating the button.
id Menu item id.
position Position of the menu item in the toolbar.

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 getUseAlternateBackground ()

Returns true, if this menu item triggers a background change on the toolbar. Only applied for menu items with position == Position.END

public boolean hasSubmenu ()

Returns true if the menu item has a submenu.

public void hideColorIndicatorCircle ()

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 boolean isTextItemFirstFromEnd ()

Gets whether the item is a text button and the first from the end

Returns
  • boolean to check whether its the first text item or not

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)

Sets 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)

Sets 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)

Sets 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)

Sets 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)

Sets 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 setTextItemFirstFromEnd (boolean isTextItemFirstFromEnd)

Sets whether the item is a text button and the first from the end

Parameters
isTextItemFirstFromEnd boolean to check whether its the first text item or not

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 void setUseAlternateBackground (boolean useAlternateBackground)

See #useAlternateBackground for a description.

Parameters
useAlternateBackground true if this item should trigger a change of the background color in the toolbar

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.

public void showColorIndicatorCircle (int color, float sizeValue)

Protected Methods

protected void onDraw (Canvas canvas)