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