allow toggling between portrait and landscape aspect ratio at wallpaper picker

This commit is contained in:
tibbi 2017-04-10 20:35:56 +02:00
parent 3221d30bef
commit da67107b83
19 changed files with 70 additions and 8 deletions

View file

@ -16,6 +16,7 @@ import kotlinx.android.synthetic.main.view_crop_image.*
class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
private val PICK_IMAGE = 1
private var isLandscapeRatio = true
lateinit var uri: Uri
lateinit var wallpaperManager: WallpaperManager
@ -47,13 +48,22 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
crop_image_view.apply {
guidelines = CropImageView.Guidelines.OFF
setOnCropImageCompleteListener(this@SetWallpaperActivity)
setImageUriAsync(intent.data)
setAspectRatio(wallpaperManager.desiredMinimumWidth, wallpaperManager.desiredMinimumHeight)
setImageUriAsync(uri)
}
setupAspectRatio()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
private fun setupAspectRatio() {
val wallpaperWidth = if (isLandscapeRatio) wallpaperManager.desiredMinimumWidth else wallpaperManager.desiredMinimumWidth / 2
crop_image_view.setAspectRatio(wallpaperWidth, wallpaperManager.desiredMinimumHeight)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_set_wallpaper, menu)
menu.findItem(R.id.portrait_aspect_ratio).isVisible = isLandscapeRatio
menu.findItem(R.id.landscape_aspect_ratio).isVisible = !isLandscapeRatio
return true
}
@ -61,11 +71,19 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
when (item.itemId) {
R.id.save -> crop_image_view.getCroppedImageAsync()
R.id.rotate -> crop_image_view.rotateImage(90)
R.id.portrait_aspect_ratio -> changeAspectRatio(false)
R.id.landscape_aspect_ratio -> changeAspectRatio(true)
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun changeAspectRatio(isLandscape: Boolean) {
isLandscapeRatio = isLandscape
setupAspectRatio()
invalidateOptionsMenu()
}
override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && isDestroyed)
return

View file

@ -1,14 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/rotate"
android:icon="@drawable/ic_rotate_right"
android:title="@string/rotate"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/save"
android:icon="@drawable/ic_check"
android:title="@string/save"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/portrait_aspect_ratio"
android:icon="@drawable/ic_minimize"
android:title="@string/portrait_aspect_ratio"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/landscape_aspect_ratio"
android:icon="@drawable/ic_maximize"
android:title="@string/landscape_aspect_ratio"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/rotate"
android:icon="@drawable/ic_rotate_right"
android:title="@string/rotate"
app:showAsAction="ifRoom"/>
</menu>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Nebyla nalezena žádná vhodná aplikace</string>
<string name="setting_wallpaper">Nastavuje se tapeta&#8230;</string>
<string name="wallpaper_set_successfully">Tapeta byla úspěšně změněna</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Zobrazit skryté složky</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Keine passende App gefunden</string>
<string name="setting_wallpaper">Setze Hintergrundbild&#8230;</string>
<string name="wallpaper_set_successfully">Hintergrundbild erfolgreich festgelegt</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Zeige versteckte Ordner</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">No se encontró aplicación para ello</string>
<string name="setting_wallpaper">Estableciendo fondo de pantalla&#8230;</string>
<string name="wallpaper_set_successfully">Fondo de pantalla establecido correctamente</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Mostrar carpetas ocultas</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Aucune application trouvée pour continuer cette action</string>
<string name="setting_wallpaper">Paramètre de fond d\'écran…</string>
<string name="wallpaper_set_successfully">Fond d\'écran défini avec succès.</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Afficher les dossiers cachés</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="setting_wallpaper">Setting wallpaper&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Show hidden folders</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Non sono disponibili app compatibili</string>
<string name="setting_wallpaper">Impostazione sfondo&#8230;</string>
<string name="wallpaper_set_successfully">Sfondo impostato correttamente</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Mostra cartelle nascoste</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">対応できるアプリが見つかりません</string>
<string name="setting_wallpaper">壁紙の設定&#8230;</string>
<string name="wallpaper_set_successfully">壁紙を正常に設定しました</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">非表示フォルダーを表示</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Brak odpowiednich ustawień</string>
<string name="setting_wallpaper">Ustawianie tapety&#8230;</string>
<string name="wallpaper_set_successfully">Tapeta ustawiona</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Pokaż ukryte foldery</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Aplicativo não encontrado</string>
<string name="setting_wallpaper">A definir como fundo de tela;</string>
<string name="wallpaper_set_successfully">Fundo de tela definido com sucesso</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Mostrar pastas ocultas</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Aplicação não encontrada</string>
<string name="setting_wallpaper">A definir como fundo de ecrã&#8230;</string>
<string name="wallpaper_set_successfully">Fundo definido com sucesso</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Mostrar pastas ocultas</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Приложение не найдено</string>
<string name="setting_wallpaper">Установка обоев&#8230;</string>
<string name="wallpaper_set_successfully">Обои успешно установлены</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Показать скрытые папки</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Nenašla sa žiadna vhodná aplikácia No app capable of it has been found</string>
<string name="setting_wallpaper">Nastavuje sa tapeta&#8230;</string>
<string name="wallpaper_set_successfully">Tapeta bola úspešne zmenená</string>
<string name="portrait_aspect_ratio">Orientácia nastojato</string>
<string name="landscape_aspect_ratio">Orientácia naležato</string>
<!-- Settings -->
<string name="show_hidden_folders">Zobraziť skryté priečinky</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Hittade ingen app som klarar av detta</string>
<string name="setting_wallpaper">Inställningar för bakgrundsbild&#8230;</string>
<string name="wallpaper_set_successfully">Bakgrundsbilden är ändrad</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Visa dolda mappar</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">Mümkün olan herhangi bir uygulama bulunamadı</string>
<string name="setting_wallpaper">Duvar kağıdını ayarlama&#8230;</string>
<string name="wallpaper_set_successfully">Duvar kağıdı başarıyla ayarlandı</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Gizli klasörleri göster</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">没有可用的软件</string>
<string name="setting_wallpaper">壁纸应用中&#8230;</string>
<string name="wallpaper_set_successfully">壁纸应用成功</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">显示所有</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">沒有可用的應用軟體</string>
<string name="setting_wallpaper">正在應用軟體桌布&#8230;</string>
<string name="wallpaper_set_successfully">成功應用軟體桌布</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">秀出隱藏資料夾</string>

View file

@ -75,6 +75,8 @@
<string name="no_wallpaper_setter_found">No app capable of it has been found</string>
<string name="setting_wallpaper">Setting wallpaper&#8230;</string>
<string name="wallpaper_set_successfully">Wallpaper set successfully</string>
<string name="portrait_aspect_ratio">Portrait aspect ratio</string>
<string name="landscape_aspect_ratio">Landscape aspect ratio</string>
<!-- Settings -->
<string name="show_hidden_folders">Show hidden folders</string>