From d480aab06353020f68213ced2c7939a6d09ca283 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 2 Jun 2017 22:41:01 +0200 Subject: [PATCH] catch out of memory errors at setting wallpaper --- app/build.gradle | 2 +- .../gallery/activities/SetWallpaperActivity.kt | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4e185cebc..f88b686a3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.19.4' + compile 'com.simplemobiletools:commons:2.19.5' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt index 1dd599eff..9d2fddb3c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt @@ -94,8 +94,13 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete val wantedHeight = wallpaperManager.desiredMinimumHeight val ratio = wantedHeight / bitmap.height.toFloat() val wantedWidth = (bitmap.width * ratio).toInt() - wallpaperManager.setBitmap(Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, true)) - setResult(Activity.RESULT_OK) + try { + wallpaperManager.setBitmap(Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, true)) + setResult(Activity.RESULT_OK) + } catch (e: OutOfMemoryError) { + toast(R.string.out_of_memory_error) + setResult(Activity.RESULT_CANCELED) + } finish() }).start() } else {