move the wallpaper handling in a background thread

This commit is contained in:
tibbi
2016-10-08 19:39:50 +02:00
parent d907e3cef5
commit c64a158a49
9 changed files with 25 additions and 22 deletions

View File

@ -63,13 +63,16 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) {
if (result.error == null) {
val bitmap = result.bitmap
val wantedHeight = wallpaperManager.desiredMinimumHeight
val ratio = wantedHeight / bitmap.height.toFloat()
val wantedWidth = (bitmap.width * ratio).toInt()
wallpaperManager.setBitmap(Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, false))
setResult(Activity.RESULT_OK)
finish()
toast(R.string.setting_wallpaper)
Thread({
val bitmap = result.bitmap
val wantedHeight = wallpaperManager.desiredMinimumHeight
val ratio = wantedHeight / bitmap.height.toFloat()
val wantedWidth = (bitmap.width * ratio).toInt()
wallpaperManager.setBitmap(Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, false))
setResult(Activity.RESULT_OK)
finish()
}).start()
} else {
toast("${getString(R.string.image_editing_failed)}: ${result.error.message}")
}