diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt index b71a979e7..6a7e30885 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt @@ -27,6 +27,7 @@ import com.simplemobiletools.commons.helpers.REAL_FILE_PATH import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.adapters.FiltersAdapter +import com.simplemobiletools.gallery.pro.dialogs.OtherAspectRatioDialog import com.simplemobiletools.gallery.pro.dialogs.ResizeDialog import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog import com.simplemobiletools.gallery.pro.extensions.config @@ -58,6 +59,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener private val ASPECT_RATIO_ONE_ONE = 1 private val ASPECT_RATIO_FOUR_THREE = 2 private val ASPECT_RATIO_SIXTEEN_NINE = 3 + private val ASPECT_RATIO_OTHER = 4 // constants for bottom primary action groups private val PRIMARY_ACTION_NONE = 0 @@ -71,6 +73,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener private lateinit var saveUri: Uri private var resizeWidth = 0 private var resizeHeight = 0 + private var lastOtherAspectRatio: Pair? = null private var currPrimaryAction = PRIMARY_ACTION_NONE private var currCropRotateAction = CROP_ROTATE_NONE private var currAspectRatio = ASPECT_RATIO_FREE @@ -328,6 +331,14 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener bottom_aspect_ratio_sixteen_nine.setOnClickListener { updateAspectRatio(ASPECT_RATIO_SIXTEEN_NINE) } + + bottom_aspect_ratio_other.setOnClickListener { + OtherAspectRatioDialog(this) { + lastOtherAspectRatio = it + updateAspectRatio(ASPECT_RATIO_OTHER) + } + } + updateAspectRatioButtons() } @@ -409,7 +420,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener val newAspectRatio = when (aspectRatio) { ASPECT_RATIO_ONE_ONE -> Pair(1, 1) ASPECT_RATIO_FOUR_THREE -> Pair(4, 3) - else -> Pair(16, 9) + ASPECT_RATIO_SIXTEEN_NINE -> Pair(16, 9) + else -> Pair(lastOtherAspectRatio!!.first, lastOtherAspectRatio!!.second) } setAspectRatio(newAspectRatio.first, newAspectRatio.second) @@ -418,7 +430,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener } private fun updateAspectRatioButtons() { - arrayOf(bottom_aspect_ratio_free, bottom_aspect_ratio_one_one, bottom_aspect_ratio_four_three, bottom_aspect_ratio_sixteen_nine).forEach { + arrayOf(bottom_aspect_ratio_free, bottom_aspect_ratio_one_one, bottom_aspect_ratio_four_three, bottom_aspect_ratio_sixteen_nine, bottom_aspect_ratio_other).forEach { it.setTextColor(Color.WHITE) } @@ -426,7 +438,8 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener ASPECT_RATIO_FREE -> bottom_aspect_ratio_free ASPECT_RATIO_ONE_ONE -> bottom_aspect_ratio_one_one ASPECT_RATIO_FOUR_THREE -> bottom_aspect_ratio_four_three - else -> bottom_aspect_ratio_sixteen_nine + ASPECT_RATIO_SIXTEEN_NINE -> bottom_aspect_ratio_sixteen_nine + else -> bottom_aspect_ratio_other } currentAspectRatioButton.setTextColor(config.primaryColor) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt new file mode 100644 index 000000000..f536162d8 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/OtherAspectRatioDialog.kt @@ -0,0 +1,40 @@ +package com.simplemobiletools.gallery.pro.dialogs + +import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.gallery.pro.R +import kotlinx.android.synthetic.main.dialog_other_aspect_ratio.view.* + +class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val callback: (aspectRatio: Pair) -> Unit) { + private val dialog: AlertDialog + + init { + val view = activity.layoutInflater.inflate(R.layout.dialog_other_aspect_ratio, null).apply { + other_aspect_ratio_2_1.setOnClickListener { ratioPicked(Pair(2, 1)) } + other_aspect_ratio_3_2.setOnClickListener { ratioPicked(Pair(3, 2)) } + other_aspect_ratio_4_3.setOnClickListener { ratioPicked(Pair(4, 3)) } + other_aspect_ratio_5_3.setOnClickListener { ratioPicked(Pair(5, 3)) } + other_aspect_ratio_16_9.setOnClickListener { ratioPicked(Pair(16, 9)) } + other_aspect_ratio_19_9.setOnClickListener { ratioPicked(Pair(19, 9)) } + + other_aspect_ratio_1_2.setOnClickListener { ratioPicked(Pair(1, 2)) } + other_aspect_ratio_2_3.setOnClickListener { ratioPicked(Pair(2, 3)) } + other_aspect_ratio_3_4.setOnClickListener { ratioPicked(Pair(3, 4)) } + other_aspect_ratio_3_5.setOnClickListener { ratioPicked(Pair(3, 5)) } + other_aspect_ratio_9_16.setOnClickListener { ratioPicked(Pair(9, 16)) } + other_aspect_ratio_9_19.setOnClickListener { ratioPicked(Pair(9, 19)) } + } + + dialog = AlertDialog.Builder(activity) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this) + } + } + + private fun ratioPicked(pair: Pair) { + callback(pair) + dialog.dismiss() + } +} diff --git a/app/src/main/res/layout/bottom_actions_aspect_ratio.xml b/app/src/main/res/layout/bottom_actions_aspect_ratio.xml index c0e0ee3cd..8663bf358 100644 --- a/app/src/main/res/layout/bottom_actions_aspect_ratio.xml +++ b/app/src/main/res/layout/bottom_actions_aspect_ratio.xml @@ -56,8 +56,22 @@ android:text="16:9" android:textColor="@android:color/white" android:textSize="@dimen/big_text_size" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toStartOf="@+id/bottom_aspect_ratio_other" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toEndOf="@+id/bottom_aspect_ratio_four_three"/> + + diff --git a/app/src/main/res/layout/dialog_other_aspect_ratio.xml b/app/src/main/res/layout/dialog_other_aspect_ratio.xml new file mode 100644 index 000000000..76fbb1b4a --- /dev/null +++ b/app/src/main/res/layout/dialog_other_aspect_ratio.xml @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +