mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
creating a dialog with resize and saving
This commit is contained in:
parent
e632740972
commit
787a672c7f
3 changed files with 201 additions and 0 deletions
|
@ -44,6 +44,7 @@ import com.simplemobiletools.gallery.pro.R
|
|||
import com.simplemobiletools.gallery.pro.adapters.MyPagerAdapter
|
||||
import com.simplemobiletools.gallery.pro.asynctasks.GetMediaAsynctask
|
||||
import com.simplemobiletools.gallery.pro.dialogs.DeleteWithRememberDialog
|
||||
import com.simplemobiletools.gallery.pro.dialogs.ResizeWithPathDialog
|
||||
import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog
|
||||
import com.simplemobiletools.gallery.pro.dialogs.SlideshowDialog
|
||||
import com.simplemobiletools.gallery.pro.extensions.*
|
||||
|
@ -918,8 +919,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
|
||||
private fun resizeImage() {
|
||||
val currentPath = getCurrentPath()
|
||||
val originalSize = currentPath.getImageResolution() ?: return
|
||||
ResizeWithPathDialog(this, originalSize, currentPath) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkDeleteConfirmation() {
|
||||
if (getCurrentMedium() == null) {
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
package com.simplemobiletools.gallery.pro.dialogs
|
||||
|
||||
import android.graphics.Point
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.gallery.pro.R
|
||||
import com.simplemobiletools.gallery.pro.extensions.config
|
||||
import kotlinx.android.synthetic.main.dialog_resize_image.view.image_height
|
||||
import kotlinx.android.synthetic.main.dialog_resize_image.view.image_width
|
||||
import kotlinx.android.synthetic.main.dialog_resize_image_with_path.view.*
|
||||
|
||||
class ResizeWithPathDialog(val activity: BaseSimpleActivity, val size: Point, val path: String, val callback: (newSize: Point) -> Unit) {
|
||||
init {
|
||||
var realPath = path.getParentPath()
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_resize_image_with_path, null).apply {
|
||||
image_path.text = "${activity.humanizePath(realPath).trimEnd('/')}/"
|
||||
|
||||
val fullName = path.getFilenameFromPath()
|
||||
val dotAt = fullName.lastIndexOf(".")
|
||||
var name = fullName
|
||||
|
||||
if (dotAt > 0) {
|
||||
name = fullName.substring(0, dotAt)
|
||||
val extension = fullName.substring(dotAt + 1)
|
||||
image_extension.setText(extension)
|
||||
}
|
||||
|
||||
image_name.setText(name)
|
||||
image_path.setOnClickListener {
|
||||
FilePickerDialog(activity, realPath, false, activity.config.shouldShowHidden, true, true) {
|
||||
image_path.text = activity.humanizePath(it)
|
||||
realPath = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val widthView = view.image_width
|
||||
val heightView = view.image_height
|
||||
|
||||
widthView.setText(size.x.toString())
|
||||
heightView.setText(size.y.toString())
|
||||
|
||||
val ratio = size.x / size.y.toFloat()
|
||||
|
||||
widthView.onTextChangeListener {
|
||||
if (widthView.hasFocus()) {
|
||||
var width = getViewValue(widthView)
|
||||
if (width > size.x) {
|
||||
widthView.setText(size.x.toString())
|
||||
width = size.x
|
||||
}
|
||||
|
||||
heightView.setText((width / ratio).toInt().toString())
|
||||
}
|
||||
}
|
||||
|
||||
heightView.onTextChangeListener {
|
||||
if (heightView.hasFocus()) {
|
||||
var height = getViewValue(heightView)
|
||||
if (height > size.y) {
|
||||
heightView.setText(size.y.toString())
|
||||
height = size.y
|
||||
}
|
||||
|
||||
widthView.setText((height * ratio).toInt().toString())
|
||||
}
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this) {
|
||||
showKeyboard(view.image_width)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val width = getViewValue(widthView)
|
||||
val height = getViewValue(heightView)
|
||||
if (width <= 0 || height <= 0) {
|
||||
activity.toast(R.string.invalid_values)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
val newSize = Point(getViewValue(widthView), getViewValue(heightView))
|
||||
callback(newSize)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getViewValue(view: EditText): Int {
|
||||
val textValue = view.value
|
||||
return if (textValue.isEmpty()) 0 else textValue.toInt()
|
||||
}
|
||||
}
|
98
app/src/main/res/layout/dialog_resize_image_with_path.xml
Normal file
98
app/src/main/res/layout/dialog_resize_image_with_path.xml
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/resize_image_with_path_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/image_width_label"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/width"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/image_width"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image_width_label"
|
||||
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/image_height_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="50dp"
|
||||
android:layout_toEndOf="@+id/image_width_label"
|
||||
android:text="@string/height"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/image_height"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image_width_label"
|
||||
android:layout_alignStart="@+id/image_height_label"
|
||||
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/image_path_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image_height"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:text="@string/path"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/image_path"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image_path_label"
|
||||
android:layout_marginStart="@dimen/activity_margin"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/small_margin"
|
||||
android:paddingEnd="@dimen/small_margin"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/image_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image_path"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:singleLine="true"
|
||||
android:textCursorDrawable="@null"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/image_extension_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image_name"
|
||||
android:text="@string/extension"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/image_extension"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image_extension_label"
|
||||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:singleLine="true"
|
||||
android:textCursorDrawable="@null"
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue