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

@ -206,7 +206,7 @@ public class ViewPagerActivity extends SimpleActivity
}
} else if (requestCode == SET_WALLPAPER) {
if (resultCode == RESULT_OK) {
Utils.showToast(getApplicationContext(), R.string.wallpaper_changed_successfully);
Utils.showToast(getApplicationContext(), R.string.wallpaper_set_successfully);
}
}
super.onActivityResult(requestCode, resultCode, data);

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}")
}

View file

@ -19,7 +19,6 @@
<string name="renaming_folder">Benenne Ordner um</string>
<string name="extension">Dateiendung</string>
<string name="file_deleted">Datei gelöscht</string>
<string name="setting_wallpaper">Setze Hintergrundbild</string>
<string name="open_camera">Kamera öffnen</string>
<string name="unknown_error">Ein unbekannter Fehler ist aufgetreten</string>
<string name="sort_by">Sortieren nach</string>
@ -58,7 +57,8 @@
<string name="set_as_wallpaper_failed">Setzen des Hintergrundbildes fehlgeschlagen</string>
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<string name="setting_wallpaper">Setze Hintergrundbild&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<!-- About -->
<string name="about">Über</string>

View file

@ -19,7 +19,6 @@
<string name="renaming_folder">Renombrando carpeta</string>
<string name="extension">Extensión</string>
<string name="file_deleted">Archivo eliminado</string>
<string name="setting_wallpaper">Estableciendo fondo de pantalla</string>
<string name="open_camera">Abrir cámara</string>
<string name="unknown_error">Ocurrió un error desconocido</string>
<string name="sort_by">Ordenar por</string>
@ -58,7 +57,8 @@
<string name="set_as_wallpaper_failed">Error al establecer fondo de pantalla</string>
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<string name="setting_wallpaper">Estableciendo fondo de pantalla&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<!-- About -->
<string name="about">Acerca de</string>

View file

@ -19,7 +19,6 @@
<string name="renaming_folder">Rinominazione cartella</string>
<string name="extension">Estensione</string>
<string name="file_deleted">File eliminato</string>
<string name="setting_wallpaper">Impostazione sfondo</string>
<string name="open_camera">Apri fotocamera</string>
<string name="unknown_error">Riscontrato un errore sconosciuto</string>
<string name="sort_by">Sort by</string>
@ -58,7 +57,8 @@
<string name="set_as_wallpaper_failed">Setting as Wallpaper failed</string>
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<string name="setting_wallpaper">Impostazione sfondo&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<!-- About -->
<string name="about">Informazioni</string>

View file

@ -19,7 +19,6 @@
<string name="renaming_folder">フォルダーの名前を変更中</string>
<string name="extension">拡張</string>
<string name="file_deleted">ファイルを削除しました</string>
<string name="setting_wallpaper">壁紙の設定</string>
<string name="open_camera">カメラを開く</string>
<string name="unknown_error">不明なエラーが発生しました</string>
<string name="sort_by">Sort by</string>
@ -58,7 +57,8 @@
<string name="set_as_wallpaper_failed">Setting as Wallpaper failed</string>
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<string name="setting_wallpaper">壁紙の設定&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<!-- About -->
<string name="about">アプリについて</string>

View file

@ -19,7 +19,6 @@
<string name="renaming_folder">A renomear pasta</string>
<string name="extension">Extensão</string>
<string name="file_deleted">Ficheiro eliminado</string>
<string name="setting_wallpaper">A definir como fundo de ecrã</string>
<string name="open_camera">Abrir câmara</string>
<string name="unknown_error">Ocorreu um erro desconhecido</string>
<string name="sort_by">Ordenar por</string>
@ -58,7 +57,8 @@
<string name="set_as_wallpaper_failed">Falha ao definir como fundo de ecrã</string>
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<string name="setting_wallpaper">A definir como fundo de ecrã&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<!-- About -->
<string name="about">Sobre</string>

View file

@ -19,7 +19,6 @@
<string name="renaming_folder">Döper om mappen</string>
<string name="extension">Filändelse</string>
<string name="file_deleted">Fil borttagen</string>
<string name="setting_wallpaper">Inställningar för bakgrundsbild</string>
<string name="open_camera">Starta kameran</string>
<string name="unknown_error">Ett okänt fel har uppstått</string>
<string name="sort_by">Sort by</string>
@ -58,7 +57,8 @@
<string name="set_as_wallpaper_failed">Setting as Wallpaper failed</string>
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<string name="setting_wallpaper">Inställningar för bakgrundsbild&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<!-- About -->
<string name="about">Om</string>

View file

@ -19,7 +19,6 @@
<string name="renaming_folder">Renaming folder</string>
<string name="extension">Extension</string>
<string name="file_deleted">File deleted</string>
<string name="setting_wallpaper">Setting wallpaper</string>
<string name="open_camera">Open camera</string>
<string name="unknown_error">An unknown error occurred</string>
<string name="sort_by">Sort by</string>
@ -58,7 +57,8 @@
<string name="set_as_wallpaper_failed">Setting as Wallpaper failed</string>
<string name="set_as_wallpaper_with">Set as wallpaper with:</string>
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="wallpaper_changed_successfully">Wallpaper changed successfully</string>
<string name="setting_wallpaper">Setting wallpaper&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<!-- About -->
<string name="about">About</string>