diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-11-21 15:25:57 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-11-21 15:25:57 +0100 |
commit | 888475d4fef98503c16e89b8796c9b18440ceb30 (patch) | |
tree | aec72acb260b74b07e82f7a795a9e97e867388f8 /src/main | |
parent | de0b36fc7866324a48f94f3e22ac89e4f43b9ff5 (diff) |
additional null pointer saftey checks
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 7bac3fd0..f7defcdf 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -358,11 +358,13 @@ public class FileBackend { } public Bitmap cropCenterSquare(Uri image, int size) { + if (image == null) { + return null; + } try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = calcSampleSize(image, size); - InputStream is = mXmppConnectionService.getContentResolver() - .openInputStream(image); + InputStream is = mXmppConnectionService.getContentResolver().openInputStream(image); Bitmap input = BitmapFactory.decodeStream(is, null, options); if (input == null) { return null; @@ -379,12 +381,13 @@ public class FileBackend { } public Bitmap cropCenter(Uri image, int newHeight, int newWidth) { + if (image == null) { + return null; + } try { BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = calcSampleSize(image, - Math.max(newHeight, newWidth)); - InputStream is = mXmppConnectionService.getContentResolver() - .openInputStream(image); + options.inSampleSize = calcSampleSize(image,Math.max(newHeight, newWidth)); + InputStream is = mXmppConnectionService.getContentResolver().openInputStream(image); Bitmap source = BitmapFactory.decodeStream(is, null, options); int sourceWidth = source.getWidth(); @@ -397,13 +400,10 @@ public class FileBackend { float left = (newWidth - scaledWidth) / 2; float top = (newHeight - scaledHeight) / 2; - RectF targetRect = new RectF(left, top, left + scaledWidth, top - + scaledHeight); - Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, - source.getConfig()); + RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight); + Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig()); Canvas canvas = new Canvas(dest); canvas.drawBitmap(source, null, targetRect, null); - return dest; } catch (FileNotFoundException e) { return null; @@ -429,12 +429,10 @@ public class FileBackend { return output; } - private int calcSampleSize(Uri image, int size) - throws FileNotFoundException { + private int calcSampleSize(Uri image, int size) throws FileNotFoundException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver() - .openInputStream(image), null, options); + BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver().openInputStream(image), null, options); return calcSampleSize(options, size); } |