From 0d282af0e6585657f7ccb0e173db52065cac767c Mon Sep 17 00:00:00 2001 From: misaochan Date: Tue, 29 May 2018 18:30:17 +1000 Subject: [PATCH] Catch exceptions in Zoom.java --- .../main/java/fr/free/nrw/commons/upload/Zoom.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/upload/Zoom.java b/app/src/main/java/fr/free/nrw/commons/upload/Zoom.java index ebfca14f3..bda3c2ad5 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/Zoom.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/Zoom.java @@ -15,6 +15,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import timber.log.Timber; + public class Zoom { private View thumbView; @@ -23,7 +25,6 @@ public class Zoom { private ContentResolver contentResolver; private FrameLayout flContainer; - Zoom(View thumbView, FrameLayout flContainer, InputStream input, Uri imageUri, ContentResolver contentResolver) { this.thumbView = thumbView; this.input = input; @@ -36,12 +37,16 @@ public class Zoom { Bitmap scaled = null; BitmapRegionDecoder decoder = null; + Bitmap bitmap = null; + try { decoder = BitmapRegionDecoder.newInstance(input, false); + bitmap = decoder.decodeRegion(new Rect(10, 10, 50, 50), null); } catch (IOException e) { - e.printStackTrace(); + Timber.e(e); + } catch (NullPointerException e) { + Timber.e(e); } - Bitmap bitmap = decoder.decodeRegion(new Rect(10, 10, 50, 50), null); try { //Compress the Image System.gc(); @@ -55,7 +60,9 @@ public class Zoom { long calWidth = (long) ((width * maxMemory) / (bitmapByteCount * 1.1)); scaled = Bitmap.createScaledBitmap(bitmap, (int) Math.min(width, calWidth), (int) Math.min(height, calHeight), true); } catch (IOException e) { + Timber.e(e); } catch (NullPointerException e) { + Timber.e(e); scaled = bitmap; } return scaled;