use glide for encoding and resizing outgoing media

Closes #3915
// FREEBIE
This commit is contained in:
Jake McGinty
2015-07-24 17:07:33 -07:00
committed by Moxie Marlinspike
parent 1641fd91cf
commit 0c9d9e8dcf
14 changed files with 357 additions and 298 deletions

View File

@@ -21,16 +21,15 @@ import android.util.SparseArray;
import android.widget.TextView;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.BitmapDecodingException;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.thoughtcrime.securesms.util.FutureTaskListener;
import org.thoughtcrime.securesms.util.ListenableFutureTask;
import org.thoughtcrime.securesms.util.Util;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -222,7 +221,7 @@ public class EmojiProvider {
try {
Log.w(TAG, "loading page " + model.getSprite());
return loadPage();
} catch (IOException ioe) {
} catch (IOException | ExecutionException ioe) {
Log.w(TAG, ioe);
}
return null;
@@ -243,23 +242,19 @@ public class EmojiProvider {
return task;
}
private Bitmap loadPage() throws IOException {
private Bitmap loadPage() throws IOException, ExecutionException {
if (bitmapReference != null && bitmapReference.get() != null) return bitmapReference.get();
try {
final InputStream measureStream = context.getAssets().open(model.getSprite());
final InputStream bitmapStream = context.getAssets().open(model.getSprite());
final Bitmap bitmap = BitmapUtil.createScaledBitmap(measureStream, bitmapStream, decodeScale);
final Bitmap bitmap = BitmapUtil.createScaledBitmap(context,
"file:///android_asset/" + model.getSprite(),
decodeScale);
bitmapReference = new SoftReference<>(bitmap);
Log.w(TAG, "onPageLoaded(" + model.getSprite() + ")");
return bitmap;
} catch (IOException ioe) {
Log.w(TAG, ioe);
throw ioe;
} catch (BitmapDecodingException bde) {
Log.w(TAG, "page " + model + " failed.");
Log.w(TAG, bde);
throw new AssertionError("emoji sprite asset is corrupted or android decoding is broken");
} catch (ExecutionException e) {
Log.w(TAG, e);
throw e;
}
}