Skip to content

gluonhq/emoji

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gluon

Build Maven Central License javadoc

Emoji library is a Java implementation of the emoji-data project adding emoji support for JavaFX applications.

What is an Emoji?

From Wikipedia:

An emoji is a pictogram, logogram, ideogram or smiley embedded in text and used in electronic messages and web pages. The primary function of emoji is to fill in emotional cues otherwise missing from typed conversation.

Emoji support in JavaFX

JavaFX can be used to create client applications that target desktop, embedded, mobiles and even web. Given the wide variety of applications, it becomes very important to have emoji support in the platform. This project aims to bridge this gap and add emoji support to JavaFX.

Usage

As stated earlier, emojis can be represented in form of text or a picture. This library can be used to represent an Emoji as one of the following and seamlessly interchange between these types:

  • String, e.g. wave
  • Unicode, e.g. \uD83D\uDC4B
  • Hex code string, e.g. 1F44B-1F3FC
  • Image, e.g. 👋

Emoji data class is used to represent each emoji. For better understanding of the Emoji class, we suggest you to go through Using the data in emoji-data or the Emoji javadoc.

API overview

EmojiData contains the public API which can be used to create Emoji objects from String and Unicode, and vice-versa.

Fetch 👋 emoji from text:

Optional<Emoji> emoji = EmojiData.emojiFromShortName("wave");

In case the exact text for emoji is not known, search API can be used to get a list of emojis which matches the text:

List<Emoji> emojis = EmojiData.search("wav");

Fetch 👋 emoji from unicode:

Optional<Emoji> emoji = EmojiData.emojiFromUnicodeString("\uD83D\uDC4B");

Fetch 👋 emoji from hex-code point string:

Optional<Emoji> emoji = EmojiData.emojiFromCodepoints("1F44B-1F3FC");

Fetch 👋 emoji's unicode from text:

Optional<String> unicode = EmojiData.emojiForText("wave");

UTF-8 encoded text can be parsed into a list of emojis and regular text using TextUtil:

List<Object> nodes = TextUtil.convertToStringAndEmojiObjects("this is an emoji: \uD83D\uDC4B");

Projects

The GitHub repository contains 3 projects: emoji, samples, emoji-updater.

emoji

Raw emoji support with Emoji and EmojiData classes. This module is to be used as a dependency in your JavaFX application.

Use the emoji dependency in a Maven project:

<dependency>
    <groupId>com.gluonhq.emoji</groupId>
    <artifactId>emoji</artifactId>
    <version>${version}</version>
</dependency>

Manually build the emoji artifact:

mvn clean install -f emoji

Offline

Emojis are extracted from sprites which are downloaded and stored in local file system to reduce the size of the application. In cases where downloading of these sprites is not possible, the offline module can be added as a dependency.

<dependency>
    <groupId>com.gluonhq.emoji</groupId>
    <artifactId>offline</artifactId>
    <version>${version}</version>
</dependency>

Manually build the offline artifact:

mvn clean install -f offline

Samples

Nodes App

Simple JavaFX application that displays all emojis. This application can be considered as a playground to test emoji and its APIs.

emoji-sample.png

Each emoji is an ImageView and shows the description of the emoji on hover:

emoji-sample-hover.png

Run the sample nodes application:

mvn javafx:run -f samples/nodes

Run the sample introduction application:

mvn javafx:run -f samples/introduction

Updater

Utility to manually update Emoji to the latest emoji data, whenever a new version is released. Normally, this will be used by the library developers, but in case we are falling behind, you can use it too ;)

To update the emoji list, set the commit number from emoji-data and run:

mvn javafx:run -f updater

Contribution

All contributions are welcome!

There are two common ways to contribute:

Follow contributing rules for this repository.