Skip to content

Commit

Permalink
Update emojis and use sprite sheet instead of individual images (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees authored and vanniktech committed Feb 21, 2018
1 parent 7f7f35c commit 9991a48
Show file tree
Hide file tree
Showing 8,794 changed files with 10,050 additions and 10,074 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
20 changes: 6 additions & 14 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ This library features a NodeJS script for updating the Emoji images and the gene

## Contents of the script

The script does five things:
The script does three things:

- Downloading the required files
- Extract the images and meta info
- Optimize the images
- Copy the images to the respective locations
- Generate the Java code
- Parsing and organizing the meta data.
- Copy (and optimize) the images to the respective locations.
- Generate the Java code.

## Prerequisites

Expand Down Expand Up @@ -45,13 +43,7 @@ yarn start

## Parameters

Not all steps are always required. If the files were already downloaded for example, you would not need to re-download them. The following parameters are available:

```
--no-download
```

Skips the download.
Not all steps are always required. If you want to skip the time-consuming optimization for example, you could pass `--no-optimize`. The following parameters are available:

```
--no-optimize
Expand Down Expand Up @@ -82,5 +74,5 @@ npm start -- --no-download --no-copy
or

```
yarn start -- --no-download --no-copy
yarn start --no-download --no-copy
```
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@
MainDialog.show(this);
return true;
case R.id.variantIos:
EmojiManager.destroy();
EmojiManager.install(new IosEmojiProvider());
recreate();
return true;
case R.id.variantGoogle:
EmojiManager.destroy();
EmojiManager.install(new GoogleEmojiProvider());
recreate();
return true;
case R.id.variantTwitter:
EmojiManager.destroy();
EmojiManager.install(new TwitterEmojiProvider());
recreate();
return true;
Expand All @@ -95,10 +98,12 @@
config.setReplaceAll(true);
emojiCompat = EmojiCompat.init(config);
}
EmojiManager.destroy();
EmojiManager.install(new GoogleCompatEmojiProvider(emojiCompat));
recreate();
return true;
case R.id.variantEmojiOne:
EmojiManager.destroy();
EmojiManager.install(new EmojiOneProvider());
recreate();
return true;
Expand Down Expand Up @@ -129,7 +134,7 @@ private void setUpEmojiPopup() {
.setOnEmojiClickListener((ignore, ignore2) -> Log.d(TAG, "Clicked on emoji"))
.setOnEmojiPopupShownListener(() -> emojiButton.setImageResource(R.drawable.ic_keyboard))
.setOnSoftKeyboardOpenListener(ignore -> Log.d(TAG, "Opened soft keyboard"))
.setOnEmojiPopupDismissListener(() -> emojiButton.setImageResource(R.drawable.emoji_ios_category_people))
.setOnEmojiPopupDismissListener(() -> emojiButton.setImageResource(R.drawable.emoji_ios_category_smileysandpeople))
.setOnSoftKeyboardCloseListener(() -> Log.d(TAG, "Closed soft keyboard"))
.build(editText);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void setUpEmojiPopup() {
.setOnEmojiClickListener((ignore, ignore2) -> Log.d(TAG, "Clicked on emoji"))
.setOnEmojiPopupShownListener(() -> emojiButton.setImageResource(R.drawable.ic_keyboard))
.setOnSoftKeyboardOpenListener(ignore -> Log.d(TAG, "Opened soft keyboard"))
.setOnEmojiPopupDismissListener(() -> emojiButton.setImageResource(R.drawable.emoji_ios_category_people))
.setOnEmojiPopupDismissListener(() -> emojiButton.setImageResource(R.drawable.emoji_ios_category_smileysandpeople))
.setOnSoftKeyboardCloseListener(() -> Log.d(TAG, "Closed soft keyboard"))
.build(editText);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/emoji_ios_category_people"
app:srcCompat="@drawable/emoji_ios_category_smileysandpeople"
tools:ignore="ContentDescription"/>

<com.vanniktech.emoji.EmojiEditText
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/dialog_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/emoji_ios_category_people"
app:srcCompat="@drawable/emoji_ios_category_smileysandpeople"
tools:ignore="ContentDescription"/>

<com.vanniktech.emoji.EmojiEditText
Expand Down
10 changes: 8 additions & 2 deletions code_quality_tools/findbugs-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Ignore Kotlin for now. -->
<Match><Source name="~.*\.kt"/></Match>

<!-- Ignore UPM in lambdas from Retrolambda, FindBugs does not correctly understand them -->
<!-- Ignore UPM in lambdas from Retrolambda, FindBugs does not correctly understand them. -->
<Match><Bug code="UPM" /><Class name="~.*\$\$Lambda\$.*"/></Match>

<!-- Ignore some things that are not wanted. -->
Expand All @@ -20,4 +20,10 @@

<!-- Ignore this one since it does not quite work together with ButterKnife & Dagger. -->
<Match><Bug pattern="UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"/></Match>
</FindBugsFilter>

<!-- Ignore this since we want to do that for improved performance. -->
<Match>
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"/>
<Class name="~.*Emoji(One)?" />
</Match>
</FindBugsFilter>
1 change: 1 addition & 0 deletions code_quality_tools/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
</rule>
<rule ref="category/java/multithreading.xml">
<exclude name="DoNotUseThreads"/>
<exclude name="AvoidUsingVolatile" />
<exclude name="UseConcurrentHashMap"/>
</rule>
<rule ref="category/java/performance.xml">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.vanniktech.emoji.google;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import com.vanniktech.emoji.emoji.Emoji;

public class GoogleEmoji extends Emoji {
private static final Object LOCK = new Object();
private static volatile Bitmap sheet;

private final int x;
private final int y;

public GoogleEmoji(@NonNull final int[] codePoints, final int x, final int y) {
super(codePoints, -1);

this.x = x;
this.y = y;
}

public GoogleEmoji(final int codePoint, final int x, final int y) {
super(codePoint, -1);

this.x = x;
this.y = y;
}

public GoogleEmoji(final int codePoint, final int x, final int y, final Emoji... variants) {
super(codePoint, -1, variants);

this.x = x;
this.y = y;
}

public GoogleEmoji(@NonNull final int[] codePoints, final int x, final int y, final Emoji... variants) {
super(codePoints, -1, variants);

this.x = x;
this.y = y;
}

@NonNull @Override public Drawable getDrawable(final Context context) {
if (sheet == null) {
synchronized (LOCK) {
if (sheet == null) {
sheet = BitmapFactory.decodeResource(context.getResources(), R.drawable.emoji_google_sheet);
}
}
}

final Bitmap cut = Bitmap.createBitmap(sheet, x * 66, y * 66, 64, 64);

return new BitmapDrawable(context.getResources(), cut);
}

@Override public void destroy() {
if (sheet != null) {
synchronized (LOCK) {
if (sheet != null) {
sheet.recycle();
sheet = null;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import android.support.annotation.NonNull;
import com.vanniktech.emoji.EmojiProvider;
import com.vanniktech.emoji.emoji.EmojiCategory;
import com.vanniktech.emoji.google.category.ActivityCategory;
import com.vanniktech.emoji.google.category.ActivitiesCategory;
import com.vanniktech.emoji.google.category.AnimalsAndNatureCategory;
import com.vanniktech.emoji.google.category.FlagsCategory;
import com.vanniktech.emoji.google.category.FoodCategory;
import com.vanniktech.emoji.google.category.NatureCategory;
import com.vanniktech.emoji.google.category.FoodAndDrinkCategory;
import com.vanniktech.emoji.google.category.ObjectsCategory;
import com.vanniktech.emoji.google.category.PeopleCategory;
import com.vanniktech.emoji.google.category.SmileysAndPeopleCategory;
import com.vanniktech.emoji.google.category.SymbolsCategory;
import com.vanniktech.emoji.google.category.TravelCategory;
import com.vanniktech.emoji.google.category.TravelAndPlacesCategory;

public final class GoogleEmojiProvider implements EmojiProvider {
@Override @NonNull public EmojiCategory[] getCategories() {
return new EmojiCategory[] {
new PeopleCategory(),
new NatureCategory(),
new FoodCategory(),
new ActivityCategory(),
new TravelCategory(),
new SmileysAndPeopleCategory(),
new AnimalsAndNatureCategory(),
new FoodAndDrinkCategory(),
new ActivitiesCategory(),
new TravelAndPlacesCategory(),
new ObjectsCategory(),
new SymbolsCategory(),
new FlagsCategory()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.vanniktech.emoji.google.category;

import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import com.vanniktech.emoji.emoji.EmojiCategory;
import com.vanniktech.emoji.google.R;
import com.vanniktech.emoji.google.GoogleEmoji;

@SuppressWarnings("PMD.MethodReturnsInternalArray") public final class ActivitiesCategory implements EmojiCategory {
private static final GoogleEmoji[] DATA = new GoogleEmoji[] {
new GoogleEmoji(0x1F383, 8, 17),
new GoogleEmoji(0x1F384, 8, 18),
new GoogleEmoji(0x1F386, 8, 25),
new GoogleEmoji(0x1F387, 8, 26),
new GoogleEmoji(0x2728, 49, 48),
new GoogleEmoji(0x1F388, 8, 27),
new GoogleEmoji(0x1F389, 8, 28),
new GoogleEmoji(0x1F38A, 8, 29),
new GoogleEmoji(0x1F38B, 8, 30),
new GoogleEmoji(0x1F38D, 8, 32),
new GoogleEmoji(0x1F38E, 8, 33),
new GoogleEmoji(0x1F38F, 8, 34),
new GoogleEmoji(0x1F390, 8, 35),
new GoogleEmoji(0x1F391, 8, 36),
new GoogleEmoji(0x1F380, 8, 14),
new GoogleEmoji(0x1F381, 8, 15),
new GoogleEmoji(new int[] { 0x1F397, 0xFE0F }, 8, 40),
new GoogleEmoji(new int[] { 0x1F39F, 0xFE0F }, 8, 45),
new GoogleEmoji(0x1F3AB, 9, 5),
new GoogleEmoji(new int[] { 0x1F396, 0xFE0F }, 8, 39),
new GoogleEmoji(0x1F3C6, 10, 19),
new GoogleEmoji(0x1F3C5, 10, 18),
new GoogleEmoji(0x1F947, 41, 42),
new GoogleEmoji(0x1F948, 41, 43),
new GoogleEmoji(0x1F949, 41, 44),
new GoogleEmoji(0x26BD, 48, 26),
new GoogleEmoji(0x26BE, 48, 27),
new GoogleEmoji(0x1F3C0, 9, 26),
new GoogleEmoji(0x1F3D0, 11, 33),
new GoogleEmoji(0x1F3C8, 10, 26),
new GoogleEmoji(0x1F3C9, 10, 27),
new GoogleEmoji(0x1F3BE, 9, 24),
new GoogleEmoji(0x1F3B1, 9, 11),
new GoogleEmoji(0x1F3B3, 9, 13),
new GoogleEmoji(0x1F3CF, 11, 32),
new GoogleEmoji(0x1F3D1, 11, 34),
new GoogleEmoji(0x1F3D2, 11, 35),
new GoogleEmoji(0x1F3D3, 11, 36),
new GoogleEmoji(0x1F3F8, 12, 22),
new GoogleEmoji(0x1F94A, 41, 45),
new GoogleEmoji(0x1F94B, 41, 46),
new GoogleEmoji(0x1F945, 41, 41),
new GoogleEmoji(0x1F3AF, 9, 9),
new GoogleEmoji(0x26F3, 48, 41),
new GoogleEmoji(new int[] { 0x26F8, 0xFE0F }, 48, 45),
new GoogleEmoji(0x1F3A3, 8, 49),
new GoogleEmoji(0x1F3BD, 9, 23),
new GoogleEmoji(0x1F3BF, 9, 25),
new GoogleEmoji(0x1F6F7, 37, 22),
new GoogleEmoji(0x1F94C, 41, 47),
new GoogleEmoji(0x1F3AE, 9, 8),
new GoogleEmoji(new int[] { 0x1F579, 0xFE0F }, 29, 20),
new GoogleEmoji(0x1F3B2, 9, 12),
new GoogleEmoji(new int[] { 0x2660, 0xFE0F }, 48, 4),
new GoogleEmoji(new int[] { 0x2665, 0xFE0F }, 48, 6),
new GoogleEmoji(new int[] { 0x2666, 0xFE0F }, 48, 7),
new GoogleEmoji(new int[] { 0x2663, 0xFE0F }, 48, 5),
new GoogleEmoji(0x1F0CF, 0, 15),
new GoogleEmoji(0x1F004, 0, 14),
new GoogleEmoji(0x1F3B4, 9, 14)
};

@Override @NonNull public GoogleEmoji[] getEmojis() {
return DATA;
}

@Override @DrawableRes public int getIcon() {
return R.drawable.emoji_google_category_activities;
}
}
Loading

0 comments on commit 9991a48

Please sign in to comment.