fix #2309, allow setting both portrait and landscape wallpapers

This commit is contained in:
tibbi 2022-04-20 10:42:12 +02:00
parent a9d5604843
commit 09bea7d508
2 changed files with 17 additions and 12 deletions

View file

@ -20,8 +20,12 @@ import kotlinx.android.synthetic.main.activity_set_wallpaper.*
import kotlinx.android.synthetic.main.bottom_set_wallpaper_actions.* import kotlinx.android.synthetic.main.bottom_set_wallpaper_actions.*
class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener { class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
private val RATIO_PORTRAIT = 0
private val RATIO_LANDSCAPE = 1
private val RATIO_SQUARE = 2
private val PICK_IMAGE = 1 private val PICK_IMAGE = 1
private var isLandscapeRatio = true private var aspectRatio = RATIO_PORTRAIT
private var wallpaperFlag = -1 private var wallpaperFlag = -1
lateinit var uri: Uri lateinit var uri: Uri
@ -80,7 +84,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
private fun setupBottomActions() { private fun setupBottomActions() {
bottom_set_wallpaper_aspect_ratio.setOnClickListener { bottom_set_wallpaper_aspect_ratio.setOnClickListener {
changeAspectRatio(!isLandscapeRatio) changeAspectRatio()
} }
bottom_set_wallpaper_rotate.setOnClickListener { bottom_set_wallpaper_rotate.setOnClickListener {
@ -89,13 +93,15 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
} }
private fun setupAspectRatio() { private fun setupAspectRatio() {
val wallpaperWidth = if (isLandscapeRatio) wallpaperManager.desiredMinimumWidth else wallpaperManager.desiredMinimumWidth / 2 when (aspectRatio) {
crop_image_view.setAspectRatio(wallpaperWidth, wallpaperManager.desiredMinimumHeight) RATIO_LANDSCAPE -> crop_image_view.setAspectRatio(wallpaperManager.desiredMinimumWidth, wallpaperManager.desiredMinimumHeight / 2)
bottom_set_wallpaper_aspect_ratio.setImageResource(if (isLandscapeRatio) R.drawable.ic_minimize_vector else R.drawable.ic_maximize_vector) RATIO_PORTRAIT -> crop_image_view.setAspectRatio(wallpaperManager.desiredMinimumWidth / 2, wallpaperManager.desiredMinimumHeight)
else -> crop_image_view.setAspectRatio(wallpaperManager.desiredMinimumWidth, wallpaperManager.desiredMinimumWidth)
}
} }
private fun changeAspectRatio(isLandscape: Boolean) { private fun changeAspectRatio() {
isLandscapeRatio = isLandscape aspectRatio = ++aspectRatio % (RATIO_SQUARE + 1)
setupAspectRatio() setupAspectRatio()
} }

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_set_wallpaper_actions_wrapper" android:id="@+id/bottom_set_wallpaper_actions_wrapper"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -14,7 +13,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/normal_margin" android:padding="@dimen/normal_margin"
android:src="@drawable/ic_minimize_vector" android:src="@drawable/ic_maximize_vector"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/bottom_set_wallpaper_rotate" app:layout_constraintEnd_toStartOf="@+id/bottom_set_wallpaper_rotate"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_bias="0.5"