mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
fix #2309, allow setting both portrait and landscape wallpapers
This commit is contained in:
parent
a9d5604843
commit
09bea7d508
2 changed files with 17 additions and 12 deletions
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,12 +13,12 @@
|
||||||
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"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/bottom_set_wallpaper_rotate"
|
android:id="@+id/bottom_set_wallpaper_rotate"
|
||||||
|
@ -33,6 +32,6 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.5"
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
app:layout_constraintStart_toEndOf="@+id/bottom_set_wallpaper_aspect_ratio"
|
app:layout_constraintStart_toEndOf="@+id/bottom_set_wallpaper_aspect_ratio"
|
||||||
app:layout_constraintTop_toTopOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
Loading…
Reference in a new issue