From 2e68bb431a9f34639a08f2b7b740ab31ed30d7dd Mon Sep 17 00:00:00 2001 From: Olga Miller Date: Sat, 7 Jan 2017 14:59:12 +0100 Subject: [PATCH] Show error instead of send it, if image size is invalid (e.g. -1 x -1) --- app/src/main/java/om/sstvencoder/CropView.java | 10 +++++++--- app/src/main/java/om/sstvencoder/MainActivity.java | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/om/sstvencoder/CropView.java b/app/src/main/java/om/sstvencoder/CropView.java index 6a9e364..1e9c4b8 100644 --- a/app/src/main/java/om/sstvencoder/CropView.java +++ b/app/src/main/java/om/sstvencoder/CropView.java @@ -180,7 +180,7 @@ public class CropView extends ImageView { invalidate(); } - public void setBitmap(@NonNull InputStream stream) throws IOException { + public void setBitmap(@NonNull InputStream stream) throws IOException, IllegalArgumentException { mImageOK = false; mOrientation = 0; recycle(); @@ -188,7 +188,7 @@ public class CropView extends ImageView { invalidate(); } - private void loadImage(InputStream stream) throws IOException { + private void loadImage(InputStream stream) throws IOException, IllegalArgumentException { // app6 + exif int bufferBytes = 1048576; if (!stream.markSupported()) @@ -212,7 +212,11 @@ public class CropView extends ImageView { if (mCacheBitmap == null && mRegionDecoder == null) { String size = options.outWidth + "x" + options.outHeight; - throw new IOException("Stream could not be decoded. Image size: " + size); + String message = "Stream could not be decoded. Image size: " + size; + if (mImageWidth <= 0 || mImageHeight <= 0) + throw new IllegalArgumentException(message); + else + throw new IOException(message); } mImageOK = true; diff --git a/app/src/main/java/om/sstvencoder/MainActivity.java b/app/src/main/java/om/sstvencoder/MainActivity.java index 1b3bc23..8f414ac 100644 --- a/app/src/main/java/om/sstvencoder/MainActivity.java +++ b/app/src/main/java/om/sstvencoder/MainActivity.java @@ -130,6 +130,9 @@ public class MainActivity extends AppCompatActivity { private boolean loadImage(InputStream stream, ContentResolver resolver, Uri uri) { try { mCropView.setBitmap(stream); + } catch (IllegalArgumentException ex) { + Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show(); + return false; } catch (Exception ex) { String s = Utility.createMessage(ex) + "\n\n" + uri; showErrorMessage(getString(R.string.load_img_err_title), ex.getMessage(), s);