mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 15:28:25 +00:00
display emoji correctly on devices of all densities
This commit is contained in:
parent
c827f0a2a7
commit
4281df7a28
4
res/values/dimens.xml
Normal file
4
res/values/dimens.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<dimen name="emoji_size">64dip</dimen>
|
||||||
|
</resources>
|
@ -2,6 +2,9 @@ package org.thoughtcrime.securesms.util;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
@ -12,6 +15,8 @@ import android.util.Log;
|
|||||||
import com.google.thoughtcrimegson.Gson;
|
import com.google.thoughtcrimegson.Gson;
|
||||||
import com.google.thoughtcrimegson.reflect.TypeToken;
|
import com.google.thoughtcrimegson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@ -45,11 +50,13 @@ public class Emoji {
|
|||||||
private final Context context;
|
private final Context context;
|
||||||
private final String[] emojiAssets;
|
private final String[] emojiAssets;
|
||||||
private final Set<String> emojiAssetsSet;
|
private final Set<String> emojiAssetsSet;
|
||||||
|
private final BitmapFactory.Options bitmapOptions;
|
||||||
|
|
||||||
private Emoji(Context context) {
|
private Emoji(Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
this.emojiAssets = initializeEmojiAssets();
|
this.emojiAssets = initializeEmojiAssets();
|
||||||
this.emojiAssetsSet = new HashSet<String>();
|
this.emojiAssetsSet = new HashSet<String>();
|
||||||
|
this.bitmapOptions = initializeBitmapOptions();
|
||||||
|
|
||||||
Collections.addAll(this.emojiAssetsSet, emojiAssets);
|
Collections.addAll(this.emojiAssetsSet, emojiAssets);
|
||||||
}
|
}
|
||||||
@ -119,7 +126,12 @@ public class Emoji {
|
|||||||
|
|
||||||
private Drawable getEmojiDrawable(String assetName) {
|
private Drawable getEmojiDrawable(String assetName) {
|
||||||
try {
|
try {
|
||||||
return Drawable.createFromStream(context.getAssets().open("emoji" + File.separator + assetName), null);
|
Bitmap bitmap = BitmapFactory.decodeStream(context.getAssets().open("emoji" + File.separator + assetName),
|
||||||
|
null, bitmapOptions);
|
||||||
|
|
||||||
|
bitmap = Bitmap.createScaledBitmap(bitmap, 40, 40, true);
|
||||||
|
|
||||||
|
return new BitmapDrawable(context.getResources(), bitmap);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
@ -134,6 +146,18 @@ public class Emoji {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BitmapFactory.Options initializeBitmapOptions() {
|
||||||
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
|
|
||||||
|
options.inScaled = true;
|
||||||
|
// options.inDensity = 64;
|
||||||
|
options.inTargetDensity = context.getResources().getDimensionPixelSize(R.dimen.emoji_size);
|
||||||
|
options.inSampleSize = 1;
|
||||||
|
options.inJustDecodeBounds = false;
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
private static class EmojiLRU {
|
private static class EmojiLRU {
|
||||||
|
|
||||||
private static final String EMOJI_LRU_PREFERENCE = "pref_popular_emoji";
|
private static final String EMOJI_LRU_PREFERENCE = "pref_popular_emoji";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user