Class EmojiPicker

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class EmojiPicker extends Container

An emoji keyboard: a grid of emoji by category, with a search field and a row of recently used ones.

The emoji picker with its search field and category tabs

Form form = new Form("Message", new BorderLayout());
TextField message = new TextField();
EmojiPicker emoji = new EmojiPicker();
emoji.bindTo(message);                 // inserts at the cursor
form.add(BorderLayout.NORTH, message);
form.add(BorderLayout.SOUTH, emoji);
form.show();

// or handle the choice yourself
emoji.addActionListener(e -> Log.p("Picked " + emoji.getSelectedEmoji()));

Tabs along the top switch category; the search field matches emoji names. The recent row remembers the last emoji picked across launches, in Preferences; turn it off with setRecentsEnabled(false).

The emoji themselves are drawn by the platform's emoji font, so they look like the emoji the user's keyboard shows.

UIIDs: EmojiPicker for the container, EmojiPickerItem for an emoji, EmojiPickerTab for a category tab and EmojiPickerSearch for the search field, falling back to Label, Button and TextField.

  • Constructor Details

    • EmojiPicker

      public EmojiPicker()
      A picker showing the first category.
  • Method Details

    • initUnselectedStyle

      protected void initUnselectedStyle(Style unselectedStyle)
      Description copied from class: Component

      Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

      Parameters
      • unselectedStyle: The unselected style.
      Overrides:
      initUnselectedStyle in class Component
    • getCategoryCount

      public static int getCategoryCount()

      The number of category tabs, not counting the recent one.

      Returns

      the category count

    • getEmoji

      public static String[] getEmoji(int index)

      The emoji of a category, in display order.

      Parameters
      • index: the category, 0 to getCategoryCount() - 1
      Returns

      the emoji

    • search

      public static List<String> search(String query)

      The emoji whose name contains query, ignoring case.

      Parameters
      • query: part of a name, such as "heart"
      Returns

      the matching emoji

    • showCategory

      public void showCategory(int index)

      Shows a category, clearing the search.

      Parameters
      • index: the category, or -1 for the recent emoji
    • getCategory

      public int getCategory()

      The category showing, -1 for the recent emoji.

      Returns

      the category index

    • getSearchField

      public TextField getSearchField()

      The search field.

      Returns

      the field

    • isRecentsEnabled

      public boolean isRecentsEnabled()

      Whether the picker keeps a row of recently used emoji.

      Returns

      true by default

    • setRecentsEnabled

      public void setRecentsEnabled(boolean enabled)

      Turns the recently used tab on or off.

      Parameters
      • enabled: false to hide it and stop recording picks
    • setColumns

      public void setColumns(int columns)

      Sets how many emoji a row holds.

      Parameters
      • columns: the column count, 8 by default
    • getSelectedEmoji

      public String getSelectedEmoji()

      The emoji the user picked last.

      Returns

      the emoji, or null before the first pick

    • getRecents

      public static List<String> getRecents()

      The emoji most recently picked, newest first.

      Returns

      the recent emoji

    • addActionListener

      public void addActionListener(ActionListener l)

      Adds a listener called when the user picks an emoji; read it with #getSelectedEmoji().

      Parameters
      • l: the listener
    • removeActionListener

      public void removeActionListener(ActionListener l)

      Removes a listener.

      Parameters
      • l: the listener
    • bindTo

      public void bindTo(TextArea field)

      Inserts every picked emoji into a text field at its cursor.

      Parameters
      • field: the field to type into
    • pick

      public void pick(String emoji)

      Picks an emoji as a tap would: records it as recent and fires the listeners.

      Parameters
      • emoji: the emoji