mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
fix #303, allow defining custom crop aspect ratio
This commit is contained in:
parent
f865af04a1
commit
2920dea288
5 changed files with 126 additions and 1 deletions
|
@ -0,0 +1,39 @@
|
||||||
|
package com.simplemobiletools.gallery.pro.dialogs
|
||||||
|
|
||||||
|
import android.widget.EditText
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
|
import com.simplemobiletools.commons.extensions.showKeyboard
|
||||||
|
import com.simplemobiletools.commons.extensions.value
|
||||||
|
import com.simplemobiletools.gallery.pro.R
|
||||||
|
import kotlinx.android.synthetic.main.dialog_custom_aspect_ratio.view.*
|
||||||
|
|
||||||
|
class CustomAspectRatioDialog(val activity: BaseSimpleActivity, val defaultCustomAspectRatio: Pair<Int, Int>?, val callback: (aspectRatio: Pair<Int, Int>) -> Unit) {
|
||||||
|
init {
|
||||||
|
val view = activity.layoutInflater.inflate(R.layout.dialog_custom_aspect_ratio, null).apply {
|
||||||
|
aspect_ratio_width.setText(defaultCustomAspectRatio?.first?.toString() ?: "")
|
||||||
|
aspect_ratio_height.setText(defaultCustomAspectRatio?.second?.toString() ?: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog.Builder(activity)
|
||||||
|
.setPositiveButton(R.string.ok, null)
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.create().apply {
|
||||||
|
activity.setupDialogStuff(view, this) {
|
||||||
|
showKeyboard(view.aspect_ratio_width)
|
||||||
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||||
|
val width = getViewValue(view.aspect_ratio_width)
|
||||||
|
val height = getViewValue(view.aspect_ratio_height)
|
||||||
|
callback(Pair(width, height))
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getViewValue(view: EditText): Int {
|
||||||
|
val textValue = view.value
|
||||||
|
return if (textValue.isEmpty()) 0 else textValue.toInt()
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspe
|
||||||
other_aspect_ratio_5_3.setOnClickListener { ratioPicked(Pair(5, 3)) }
|
other_aspect_ratio_5_3.setOnClickListener { ratioPicked(Pair(5, 3)) }
|
||||||
other_aspect_ratio_16_9.setOnClickListener { ratioPicked(Pair(16, 9)) }
|
other_aspect_ratio_16_9.setOnClickListener { ratioPicked(Pair(16, 9)) }
|
||||||
other_aspect_ratio_19_9.setOnClickListener { ratioPicked(Pair(19, 9)) }
|
other_aspect_ratio_19_9.setOnClickListener { ratioPicked(Pair(19, 9)) }
|
||||||
|
other_aspect_ratio_custom.setOnClickListener { customRatioPicked() }
|
||||||
|
|
||||||
other_aspect_ratio_1_2.setOnClickListener { ratioPicked(Pair(1, 2)) }
|
other_aspect_ratio_1_2.setOnClickListener { ratioPicked(Pair(1, 2)) }
|
||||||
other_aspect_ratio_2_3.setOnClickListener { ratioPicked(Pair(2, 3)) }
|
other_aspect_ratio_2_3.setOnClickListener { ratioPicked(Pair(2, 3)) }
|
||||||
|
@ -46,6 +47,10 @@ class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspe
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
other_aspect_ratio_dialog_radio_2.check(radio2SelectedItemId)
|
other_aspect_ratio_dialog_radio_2.check(radio2SelectedItemId)
|
||||||
|
|
||||||
|
if (radio1SelectedItemId == 0 && radio2SelectedItemId == 0) {
|
||||||
|
other_aspect_ratio_dialog_radio_1.check(other_aspect_ratio_custom.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
|
@ -55,6 +60,13 @@ class OtherAspectRatioDialog(val activity: BaseSimpleActivity, val lastOtherAspe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun customRatioPicked() {
|
||||||
|
CustomAspectRatioDialog(activity, lastOtherAspectRatio) {
|
||||||
|
callback(it)
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun ratioPicked(pair: Pair<Int, Int>) {
|
private fun ratioPicked(pair: Pair<Int, Int>) {
|
||||||
callback(pair)
|
callback(pair)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
|
|
|
@ -69,7 +69,7 @@ class ResizeDialog(val activity: BaseSimpleActivity, val size: Point, val callba
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getViewValue(view: EditText): Int {
|
private fun getViewValue(view: EditText): Int {
|
||||||
val textValue = view.value
|
val textValue = view.value
|
||||||
return if (textValue.isEmpty()) 0 else textValue.toInt()
|
return if (textValue.isEmpty()) 0 else textValue.toInt()
|
||||||
}
|
}
|
||||||
|
|
64
app/src/main/res/layout/dialog_custom_aspect_ratio.xml
Normal file
64
app/src/main/res/layout/dialog_custom_aspect_ratio.xml
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/aspect_ratio_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingRight="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/aspect_ratio_width_label"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/width"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyEditText
|
||||||
|
android:id="@+id/aspect_ratio_width"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/aspect_ratio_width_label"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:inputType="number"
|
||||||
|
android:maxLength="6"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textCursorDrawable="@null"
|
||||||
|
android:textSize="@dimen/normal_text_size"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/aspect_ratio_colon_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignTop="@+id/aspect_ratio_width"
|
||||||
|
android:layout_alignBottom="@+id/aspect_ratio_width"
|
||||||
|
android:layout_toLeftOf="@+id/aspect_ratio_height"
|
||||||
|
android:layout_toRightOf="@+id/aspect_ratio_width"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text=":"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/aspect_ratio_height_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="50dp"
|
||||||
|
android:layout_marginLeft="50dp"
|
||||||
|
android:layout_toRightOf="@+id/aspect_ratio_width_label"
|
||||||
|
android:text="@string/height"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyEditText
|
||||||
|
android:id="@+id/aspect_ratio_height"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/aspect_ratio_width_label"
|
||||||
|
android:layout_alignStart="@+id/aspect_ratio_height_label"
|
||||||
|
android:layout_alignLeft="@+id/aspect_ratio_height_label"
|
||||||
|
android:inputType="number"
|
||||||
|
android:maxLength="6"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textCursorDrawable="@null"
|
||||||
|
android:textSize="@dimen/normal_text_size"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
|
@ -84,6 +84,16 @@
|
||||||
android:text="19:9"
|
android:text="19:9"
|
||||||
android:textSize="@dimen/bigger_text_size"/>
|
android:textSize="@dimen/bigger_text_size"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/other_aspect_ratio_custom"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="@dimen/small_margin"
|
||||||
|
android:paddingTop="@dimen/normal_margin"
|
||||||
|
android:paddingBottom="@dimen/normal_margin"
|
||||||
|
android:text="@string/custom"
|
||||||
|
android:textSize="@dimen/bigger_text_size"/>
|
||||||
|
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
|
|
Loading…
Reference in a new issue