This project is an android port of the emoji4j which is a java library to convert short codes, html entities to emojis and vice-versa. Also supports parsing emoticons, surrogate html entities.
Inspired by vdurmont/emoji-java, emoji4j adds more goodies and helpers to deal with emojis. The emoji data is based on the database from github/gemoji and ASCII emoticons data from wooorm/emoticon.
This project is already being used in AniTrend
- Converting of html entities to emojies may not always display the emoji on a given android device if the target device does not have the suggested emoticons e.g. android 4.3 does not have some emoticons available in android 5.0+
- Depending on the complexity of the string passed the conversion may take a second or two which may make your application jitter, I strongly suggest doing conversions in a background thread. This could be between sending a network request or recieving it.
- If you are using a markdown library like txtmark or using just
Html.fromHtml()
you can skip convertion of HexHtml & HtmlCodes to emoji and just pass the returned Spanned from theHtml.fromHtml
to your text view. (See sample in project)
Got a social application but you need someway of having emoji support? Then this library is for you, all your backend stores is the html entities. Your client application would have to convert all emoji objects in a given string and transmit that to your server. When the client request status or blog text it has to convert the html entities to emoji objects which your android operating system will resolve. See examples below!
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.wax911:android-emojify:{latest_version}'
}
Don't know how to do that?? Take a look at the application class example
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
EmojiManager.initEmojiData(getApplicationContext());
}
}
Get emoji by unicode, short code, decimal or hexadecimal html entity
Emoji emoji = EmojiUtils.getEmoji("π"); //get emoji by unicode character
EmojiUtils.getEmoji("blue_car").getEmoji(); //returns π
EmojiUtils.getEmoji(":blue_car:").getEmoji(); //also returns π
EmojiUtils.getEmoji("🐭").getEmoji(); //returns π
EmojiUtils.getEmoji("🐭").getEmoji(); //also returns π
EmojiUtils.getEmoji("��").getEmoji(); //returns π
Conversion from unicode, short code, hexadecimal and decimal html entities is pretty easy.
Emoji emoji = EmojiUtils.getEmoji("π");
emoji.getEmoji(); //returns π
emoji.getDecimalHtml(); //returns 🐭
emoji.getHexHtml(); //return 🐭
emoji.getAliases(); //returns a collection of aliases. ["mouse"]
Verifies if the passed string is an emoji character
EmojiUtils.isEmoji("π"); //returns true
EmojiUtils.isEmoji("blue_car"); //returns true
EmojiUtils.isEmoji(":coyote:"); //returns false
EmojiUtils.isEmoji("🐭"); //returns true
EmojiUtils.isEmoji("🐭"); //returns true
Emojifies the passed string
String text = "A :cat:, :dog: and a :mouse: became friends<3. For :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.";
EmojiUtils.emojify(text); //returns A π±, πΆ and a π became friendsβ€οΈ. For πΆ's birthday party, they all had πs, πs, πͺs and π°.
String text = "A 🐱, 🐶 and a :mouse: became friends. For the :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:."
EmojiUtils.emojify(text); //returns A π±, πΆ and a π became friends. For the πΆ's birthday party, they all had πs, πs, πͺs and π°.
Converts unicode characters in text to corresponding decimal html entities
String text = "A :cat:, :dog: and a :mouse: became friends. For the :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.";
EmojiUtils.htmlify(text); //returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
String text = "A π±, πΆ and a π became friends. For the πΆ's birthday party, they all had πs, πs, πͺs and π°."
EmojiUtils.htmlify(text); //also returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
Converts unicode characters in text to corresponding decimal hexadecimal html entities
String text = "A :cat:, :dog: and a :mouse: became friends. For the :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.";
EmojiUtils.hexHtmlify(text); //returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
String text = "A π±, πΆ and a π became friends. For the πΆ's birthday party, they all had πs, πs, πͺs and π°."
EmojiUtils.hexHtmlify(text); //returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
Converts unicode characters in text to corresponding decimal surrogate html entities
String text = "π";
EmojiUtils.htmlify(text, true); //returns ��
String text = "A π±, πΆ and a π became friendsβ€οΈ. For πΆ's birthday party, they all had πs, πs, πͺs and π°.";
EmojiUtils.shortCodify(text); //returns A :cat:, :dog: and a :mouse: became friends:heart:. For :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.
Removes unicode emoji characters from the passed string
String emojiText = "A π±, π± and a π became friendsβ€οΈ. For πΆ's birthday party, they all had πs, πs, πͺs and π°.";
EmojiUtils.removeAllEmojis(emojiText);//"A , and a became friends. For 's birthday party, they all had s, s, s and .
Counts emojis in a String
String text = "A 🐱, 🐶, :coyote: and a :mouse: became friends. For :dog:'s birthday party, they all had πs, :fries:s, :cookie:s and :cake:.";
EmojiUtils.countEmojis(text); //returns 8
MIT License
Copyright (c) 2018 Maxwell Mapako
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.