Workaround for Samsung failure

pull/184/head
M66B 4 years ago
parent fe11860638
commit d7dc9aac5c

@ -270,7 +270,7 @@ class ImageHelper {
int scaleToPixels = res.getDisplayMetrics().widthPixels; int scaleToPixels = res.getDisplayMetrics().widthPixels;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
try { try {
Drawable d = getScaledDrawable(attachment.getFile(context), scaleToPixels); Drawable d = getScaledDrawable(context, attachment.getFile(context), scaleToPixels);
if (view != null) if (view != null)
fitDrawable(d, a, scale, view); fitDrawable(d, a, scale, view);
return d; return d;
@ -556,7 +556,7 @@ class ImageHelper {
DisplayMetrics dm = context.getResources().getDisplayMetrics(); DisplayMetrics dm = context.getResources().getDisplayMetrics();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
return getScaledDrawable(file, dm.widthPixels); return getScaledDrawable(context, file, dm.widthPixels);
Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath()); Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath());
if (bm != null) { if (bm != null) {
@ -629,7 +629,7 @@ class ImageHelper {
try (FileOutputStream fos = new FileOutputStream(file)) { try (FileOutputStream fos = new FileOutputStream(file)) {
Helper.copy(urlConnection.getInputStream(), fos); Helper.copy(urlConnection.getInputStream(), fos);
} }
return getScaledDrawable(file, dm.widthPixels); return getScaledDrawable(context, file, dm.widthPixels);
} }
bm = getScaledBitmap( bm = getScaledBitmap(
@ -659,9 +659,12 @@ class ImageHelper {
} }
@RequiresApi(api = Build.VERSION_CODES.P) @RequiresApi(api = Build.VERSION_CODES.P)
static Drawable getScaledDrawable(File file, int scaleToPixels) throws IOException { static Drawable getScaledDrawable(Context context, File file, int scaleToPixels) throws IOException {
Drawable d;
try {
ImageDecoder.Source isource = ImageDecoder.createSource(file); ImageDecoder.Source isource = ImageDecoder.createSource(file);
Drawable d = ImageDecoder.decodeDrawable(isource, new ImageDecoder.OnHeaderDecodedListener() { d = ImageDecoder.decodeDrawable(isource, new ImageDecoder.OnHeaderDecodedListener() {
@Override @Override
public void onHeaderDecoded( public void onHeaderDecoded(
@NonNull ImageDecoder decoder, @NonNull ImageDecoder decoder,
@ -674,6 +677,21 @@ class ImageHelper {
decoder.setTargetSampleSize(factor); decoder.setTargetSampleSize(factor);
} }
}); });
} catch (Throwable ex) {
Log.w(ex);
/*
Samsung:
android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.
at android.graphics.ImageDecoder.nCreate(ImageDecoder.java:-2)
at android.graphics.ImageDecoder.createFromFile(ImageDecoder.java:311)
at android.graphics.ImageDecoder.access$600(ImageDecoder.java:173)
at android.graphics.ImageDecoder$FileSource.createImageDecoder(ImageDecoder.java:543)
at android.graphics.ImageDecoder.decodeDrawableImpl(ImageDecoder.java:1758)
at android.graphics.ImageDecoder.decodeDrawable(ImageDecoder.java:1751)
*/
d = new BitmapDrawable(context.getResources(), file.getAbsolutePath());
}
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d; return d;
} }

Loading…
Cancel
Save