22
33import android .content .Context ;
44import android .content .SharedPreferences ;
5+ import android .graphics .Bitmap ;
6+ import android .graphics .BitmapFactory ;
7+ import android .graphics .drawable .BitmapDrawable ;
58import android .graphics .drawable .Drawable ;
69import android .preference .PreferenceManager ;
710import android .text .Spannable ;
1215import com .google .thoughtcrimegson .Gson ;
1316import com .google .thoughtcrimegson .reflect .TypeToken ;
1417
18+ import org .thoughtcrime .securesms .R ;
19+
1520import java .io .File ;
1621import java .io .IOException ;
1722import java .lang .reflect .Type ;
@@ -42,14 +47,16 @@ public synchronized static Emoji getInstance(Context context) {
4247 public static final double EMOJI_LARGE = 1 ;
4348 public static final double EMOJI_SMALL = 0.7 ;
4449
45- private final Context context ;
46- private final String [] emojiAssets ;
47- private final Set <String > emojiAssetsSet ;
50+ private final Context context ;
51+ private final String [] emojiAssets ;
52+ private final Set <String > emojiAssetsSet ;
53+ private final BitmapFactory .Options bitmapOptions ;
4854
4955 private Emoji (Context context ) {
5056 this .context = context .getApplicationContext ();
5157 this .emojiAssets = initializeEmojiAssets ();
5258 this .emojiAssetsSet = new HashSet <String >();
59+ this .bitmapOptions = initializeBitmapOptions ();
5360
5461 Collections .addAll (this .emojiAssetsSet , emojiAssets );
5562 }
@@ -119,7 +126,12 @@ private String getEmojiUnicodeFromAssetName(String assetName) {
119126
120127 private Drawable getEmojiDrawable (String assetName ) {
121128 try {
122- return Drawable .createFromStream (context .getAssets ().open ("emoji" + File .separator + assetName ), null );
129+ Bitmap bitmap = BitmapFactory .decodeStream (context .getAssets ().open ("emoji" + File .separator + assetName ),
130+ null , bitmapOptions );
131+
132+ bitmap = Bitmap .createScaledBitmap (bitmap , 40 , 40 , true );
133+
134+ return new BitmapDrawable (context .getResources (), bitmap );
123135 } catch (IOException e ) {
124136 throw new AssertionError (e );
125137 }
@@ -134,6 +146,18 @@ private String[] initializeEmojiAssets() {
134146 }
135147 }
136148
149+ private BitmapFactory .Options initializeBitmapOptions () {
150+ BitmapFactory .Options options = new BitmapFactory .Options ();
151+
152+ options .inScaled = true ;
153+ // options.inDensity = 64;
154+ options .inTargetDensity = context .getResources ().getDimensionPixelSize (R .dimen .emoji_size );
155+ options .inSampleSize = 1 ;
156+ options .inJustDecodeBounds = false ;
157+
158+ return options ;
159+ }
160+
137161 private static class EmojiLRU {
138162
139163 private static final String EMOJI_LRU_PREFERENCE = "pref_popular_emoji" ;
0 commit comments