2016-12-14 10:21:14 -08:00
|
|
|
package org.thoughtcrime.securesms.components.subsampling;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder;
|
|
|
|
import com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
public class AttachmentBitmapDecoder implements ImageDecoder{
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
public AttachmentBitmapDecoder() {}
|
2017-11-27 11:13:38 -08:00
|
|
|
|
2016-12-14 10:21:14 -08:00
|
|
|
@Override
|
|
|
|
public Bitmap decode(Context context, Uri uri) throws Exception {
|
|
|
|
if (!PartAuthority.isLocalUri(uri)) {
|
|
|
|
return new SkiaImageDecoder().decode(context, uri);
|
|
|
|
}
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
InputStream inputStream = PartAuthority.getAttachmentStream(context, uri);
|
2016-12-14 10:21:14 -08:00
|
|
|
|
|
|
|
try {
|
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
|
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
|
|
|
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, options);
|
|
|
|
|
|
|
|
if (bitmap == null) {
|
|
|
|
throw new RuntimeException("Skia image region decoder returned null bitmap - image format may not be supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
} finally {
|
|
|
|
if (inputStream != null) inputStream.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|