catch out of memory errors at setting wallpaper

This commit is contained in:
tibbi 2017-06-02 22:41:01 +02:00
parent ea42c4f1aa
commit d480aab063
2 changed files with 8 additions and 3 deletions

View file

@ -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'

View file

@ -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 {