mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-02-17 12:10:47 +01:00
try suggesting a proper file extension at saving
This commit is contained in:
parent
f4e30de755
commit
32fcf70976
@ -23,6 +23,9 @@ import com.simplemobiletools.draw.R
|
|||||||
import com.simplemobiletools.draw.Svg
|
import com.simplemobiletools.draw.Svg
|
||||||
import com.simplemobiletools.draw.dialogs.SaveImageDialog
|
import com.simplemobiletools.draw.dialogs.SaveImageDialog
|
||||||
import com.simplemobiletools.draw.extensions.config
|
import com.simplemobiletools.draw.extensions.config
|
||||||
|
import com.simplemobiletools.draw.helpers.JPG
|
||||||
|
import com.simplemobiletools.draw.helpers.PNG
|
||||||
|
import com.simplemobiletools.draw.helpers.SVG
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -37,6 +40,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
private var curPath = ""
|
private var curPath = ""
|
||||||
private var color = 0
|
private var color = 0
|
||||||
private var strokeWidth = 0f
|
private var strokeWidth = 0f
|
||||||
|
private var suggestedFileExtension = PNG
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -78,7 +82,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.menu_save -> trySaveImage()
|
R.id.menu_save -> trySaveImage()
|
||||||
R.id.menu_share -> shareImage()
|
R.id.menu_share -> shareImage()
|
||||||
R.id.clear -> my_canvas.clearCanvas()
|
R.id.clear -> clearCanvas()
|
||||||
R.id.open_file -> tryOpenFile()
|
R.id.open_file -> tryOpenFile()
|
||||||
R.id.change_background -> changeBackgroundClicked()
|
R.id.change_background -> changeBackgroundClicked()
|
||||||
R.id.settings -> launchSettings()
|
R.id.settings -> launchSettings()
|
||||||
@ -128,8 +132,10 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
if (path.endsWith(".svg")) {
|
if (path.endsWith(".svg")) {
|
||||||
my_canvas.mBackgroundBitmap = null
|
my_canvas.mBackgroundBitmap = null
|
||||||
Svg.loadSvg(this, File(path), my_canvas)
|
Svg.loadSvg(this, File(path), my_canvas)
|
||||||
|
suggestedFileExtension = SVG
|
||||||
} else if (File(path).isImageSlow()) {
|
} else if (File(path).isImageSlow()) {
|
||||||
my_canvas.drawBitmap(this, path)
|
my_canvas.drawBitmap(this, path)
|
||||||
|
suggestedFileExtension = JPG
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.invalid_file_format)
|
toast(R.string.invalid_file_format)
|
||||||
}
|
}
|
||||||
@ -152,7 +158,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun saveImage() {
|
private fun saveImage() {
|
||||||
SaveImageDialog(this, curPath, my_canvas) {
|
SaveImageDialog(this, suggestedFileExtension, curPath, my_canvas) {
|
||||||
curPath = it
|
curPath = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,6 +203,11 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
return FileProvider.getUriForFile(this, "com.simplemobiletools.draw.fileprovider", file)
|
return FileProvider.getUriForFile(this, "com.simplemobiletools.draw.fileprovider", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun clearCanvas() {
|
||||||
|
my_canvas.clearCanvas()
|
||||||
|
suggestedFileExtension = PNG
|
||||||
|
}
|
||||||
|
|
||||||
fun pickColor() {
|
fun pickColor() {
|
||||||
ColorPickerDialog(this, color) {
|
ColorPickerDialog(this, color) {
|
||||||
setColor(it)
|
setColor(it)
|
||||||
@ -207,6 +218,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
undo.setColorFilter(pickedColor.getContrastColor(), PorterDuff.Mode.SRC_IN)
|
undo.setColorFilter(pickedColor.getContrastColor(), PorterDuff.Mode.SRC_IN)
|
||||||
my_canvas.setBackgroundColor(pickedColor)
|
my_canvas.setBackgroundColor(pickedColor)
|
||||||
my_canvas.mBackgroundBitmap = null
|
my_canvas.mBackgroundBitmap = null
|
||||||
|
suggestedFileExtension = PNG
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setColor(pickedColor: Int) {
|
private fun setColor(pickedColor: Int) {
|
||||||
|
@ -8,14 +8,14 @@ import com.simplemobiletools.draw.MyCanvas
|
|||||||
import com.simplemobiletools.draw.R
|
import com.simplemobiletools.draw.R
|
||||||
import com.simplemobiletools.draw.Svg
|
import com.simplemobiletools.draw.Svg
|
||||||
import com.simplemobiletools.draw.activities.SimpleActivity
|
import com.simplemobiletools.draw.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.draw.helpers.JPG
|
||||||
|
import com.simplemobiletools.draw.helpers.PNG
|
||||||
|
import com.simplemobiletools.draw.helpers.SVG
|
||||||
import kotlinx.android.synthetic.main.dialog_save_image.view.*
|
import kotlinx.android.synthetic.main.dialog_save_image.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
||||||
class SaveImageDialog(val activity: SimpleActivity, val curPath: String, val canvas: MyCanvas, callback: (path: String) -> Unit) {
|
class SaveImageDialog(val activity: SimpleActivity, val suggestedExtension: String, val curPath: String, val canvas: MyCanvas, callback: (path: String) -> Unit) {
|
||||||
private val PNG = "png"
|
|
||||||
private val SVG = "svg"
|
|
||||||
private val JPG = "jpg"
|
|
||||||
private val SIMPLE_DRAW = "Simple Draw"
|
private val SIMPLE_DRAW = "Simple Draw"
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -23,7 +23,11 @@ class SaveImageDialog(val activity: SimpleActivity, val curPath: String, val can
|
|||||||
var realPath = if (curPath.isEmpty()) "${activity.internalStoragePath}/$SIMPLE_DRAW" else File(curPath).parent.trimEnd('/')
|
var realPath = if (curPath.isEmpty()) "${activity.internalStoragePath}/$SIMPLE_DRAW" else File(curPath).parent.trimEnd('/')
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_save_image, null).apply {
|
val view = activity.layoutInflater.inflate(R.layout.dialog_save_image, null).apply {
|
||||||
save_image_filename.setText(initialFilename)
|
save_image_filename.setText(initialFilename)
|
||||||
save_image_radio_group.check(if (curPath.endsWith(SVG)) R.id.save_image_radio_svg else R.id.save_image_radio_png)
|
save_image_radio_group.check(when (suggestedExtension) {
|
||||||
|
JPG -> R.id.save_image_radio_jpg
|
||||||
|
SVG -> R.id.save_image_radio_svg
|
||||||
|
else -> R.id.save_image_radio_png
|
||||||
|
})
|
||||||
|
|
||||||
save_image_path.text = activity.humanizePath(realPath)
|
save_image_path.text = activity.humanizePath(realPath)
|
||||||
save_image_path.setOnClickListener {
|
save_image_path.setOnClickListener {
|
||||||
|
@ -4,3 +4,7 @@ val BRUSH_COLOR = "brush_color"
|
|||||||
val CANVAS_BACKGROUND_COLOR = "canvas_background_color"
|
val CANVAS_BACKGROUND_COLOR = "canvas_background_color"
|
||||||
val SHOW_BRUSH_SIZE = "show_brush_size"
|
val SHOW_BRUSH_SIZE = "show_brush_size"
|
||||||
val BRUSH_SIZE = "brush_size"
|
val BRUSH_SIZE = "brush_size"
|
||||||
|
|
||||||
|
val PNG = "png"
|
||||||
|
val SVG = "svg"
|
||||||
|
val JPG = "jpg"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user