mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 16:33:39 +00:00
parent
1c680a2c64
commit
ad6ae10a41
@ -110,11 +110,7 @@ class EmojiProvider {
|
||||
final EmojiDrawable drawable = new EmojiDrawable(drawInfo, decodeScale);
|
||||
drawInfo.getPage().get().addListener(new FutureTaskListener<Bitmap>() {
|
||||
@Override public void onSuccess(final Bitmap result) {
|
||||
Util.runOnMain(new Runnable() {
|
||||
@Override public void run() {
|
||||
drawable.setBitmap(result);
|
||||
}
|
||||
});
|
||||
Util.runOnMain(() -> drawable.setBitmap(result));
|
||||
}
|
||||
|
||||
@Override public void onFailure(ExecutionException error) {
|
||||
|
@ -7,14 +7,14 @@ import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageModel;
|
||||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class EmojiPageBitmap {
|
||||
|
||||
@ -41,16 +41,14 @@ public class EmojiPageBitmap {
|
||||
} else if (task != null) {
|
||||
return task;
|
||||
} else {
|
||||
Callable<Bitmap> callable = new Callable<Bitmap>() {
|
||||
@Override public Bitmap call() throws Exception {
|
||||
try {
|
||||
Log.w(TAG, "loading page " + model.getSprite());
|
||||
return loadPage();
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, ioe);
|
||||
}
|
||||
return null;
|
||||
Callable<Bitmap> callable = () -> {
|
||||
try {
|
||||
Log.w(TAG, "loading page " + model.getSprite());
|
||||
return loadPage();
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, ioe);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
task = new ListenableFutureTask<>(callable);
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@ -71,13 +69,21 @@ public class EmojiPageBitmap {
|
||||
if (bitmapReference != null && bitmapReference.get() != null) return bitmapReference.get();
|
||||
|
||||
try {
|
||||
final Bitmap bitmap = BitmapUtil.createScaledBitmap(context,
|
||||
"file:///android_asset/" + model.getSprite(),
|
||||
decodeScale);
|
||||
bitmapReference = new SoftReference<>(bitmap);
|
||||
Bitmap originalBitmap = GlideApp.with(context.getApplicationContext())
|
||||
.asBitmap()
|
||||
.load("file:///android_asset/" + model.getSprite())
|
||||
.submit()
|
||||
.get();
|
||||
|
||||
Bitmap scaledBitmap = Bitmap.createScaledBitmap(originalBitmap, (int)(originalBitmap.getWidth() * decodeScale), (int)(originalBitmap.getHeight() * decodeScale), false);
|
||||
|
||||
bitmapReference = new SoftReference<>(scaledBitmap);
|
||||
Log.w(TAG, "onPageLoaded(" + model.getSprite() + ")");
|
||||
return bitmap;
|
||||
} catch (BitmapDecodingException e) {
|
||||
return scaledBitmap;
|
||||
} catch (InterruptedException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new IOException(e);
|
||||
} catch (ExecutionException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import android.support.annotation.WorkerThread;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy;
|
||||
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
@ -108,22 +109,6 @@ public class BitmapUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static <T> Bitmap createScaledBitmap(Context context, T model, float scale)
|
||||
throws BitmapDecodingException
|
||||
{
|
||||
try {
|
||||
return GlideApp.with(context.getApplicationContext())
|
||||
.asBitmap()
|
||||
.load(model)
|
||||
.sizeMultiplier(scale)
|
||||
.submit()
|
||||
.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new BitmapDecodingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static BitmapFactory.Options getImageDimensions(InputStream inputStream)
|
||||
throws BitmapDecodingException
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user