Skip to content

Commit 7ff7044

Browse files
committed
fix crash
Signed-off-by: sowjanyakch <[email protected]>
1 parent 8a39147 commit 7ff7044

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

app/src/main/java/com/nextcloud/talk/activities/TakePhotoActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ private void setPreviewImage(File photoFile) {
328328
Bitmap bitmap = BitmapShrinker.shrinkBitmap(photoFile.getAbsolutePath(),
329329
doubleScreenWidth,
330330
doubleScreenHeight);
331-
331+
if (bitmap == null) {
332+
Log.e(TAG, "Preview bitmap could not be decoded from path: " + photoFile.getAbsolutePath());
333+
Snackbar.make(binding.getRoot(), R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show();
334+
return;
335+
}
332336
binding.photoPreview.setImageBitmap(bitmap);
333337
binding.photoPreview.setTag(savedUri);
334338
viewModel.disableTorchIfEnabled();

app/src/main/java/com/nextcloud/talk/fullscreenfile/FullScreenImageActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ class FullScreenImageActivity : AppCompatActivity() {
142142

143143
val bitmap = BitmapShrinker.shrinkBitmap(path, doubleScreenWidth, doubleScreenHeight)
144144

145+
if (bitmap == null) {
146+
Log.e(TAG, "bitmap could not be decoded from path: $path")
147+
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
148+
return
149+
}
150+
145151
val bitmapSize: Int = bitmap.byteCount
146152

147153
// info that 100MB is the limit comes from https://stackoverflow.com/a/53334563

app/src/main/java/com/nextcloud/talk/utils/BitmapShrinker.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,25 @@ object BitmapShrinker {
2121
private const val DEGREES_270 = 270f
2222

2323
@JvmStatic
24-
fun shrinkBitmap(path: String, reqWidth: Int, reqHeight: Int): Bitmap {
25-
val bitmap = decodeBitmap(path, reqWidth, reqHeight)
24+
fun shrinkBitmap(path: String, reqWidth: Int, reqHeight: Int): Bitmap? {
25+
val bitmap = decodeBitmap(path, reqWidth, reqHeight) ?: return null
2626
return rotateBitmap(path, bitmap)
2727
}
2828

2929
// solution inspired by https://developer.android.com/topic/performance/graphics/load-bitmap
30-
private fun decodeBitmap(path: String, requestedWidth: Int, requestedHeight: Int): Bitmap =
30+
private fun decodeBitmap(path: String, requestedWidth: Int, requestedHeight: Int): Bitmap? =
3131
BitmapFactory.Options().run {
3232
inJustDecodeBounds = true
3333
BitmapFactory.decodeFile(path, this)
3434
inSampleSize = getInSampleSize(this, requestedWidth, requestedHeight)
3535
inJustDecodeBounds = false
36-
BitmapFactory.decodeFile(path, this)
36+
BitmapFactory.decodeFile(path, this)?.also { bitmap ->
37+
Log.d(TAG, "Bitmap decoded successfully from path: $path")
38+
return@run bitmap
39+
}
40+
41+
Log.e(TAG, "Failed to decode bitmap from path: $path")
42+
null
3743
}
3844

3945
// solution inspired by https://developer.android.com/topic/performance/graphics/load-bitmap

0 commit comments

Comments
 (0)