try suggesting a proper file extension at saving
This commit is contained in:
parent
f4e30de755
commit
32fcf70976
3 changed files with 27 additions and 7 deletions
|
@ -23,6 +23,9 @@ import com.simplemobiletools.draw.R
|
|||
import com.simplemobiletools.draw.Svg
|
||||
import com.simplemobiletools.draw.dialogs.SaveImageDialog
|
||||
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 java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
|
@ -37,6 +40,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
private var curPath = ""
|
||||
private var color = 0
|
||||
private var strokeWidth = 0f
|
||||
private var suggestedFileExtension = PNG
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -78,7 +82,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
when (item.itemId) {
|
||||
R.id.menu_save -> trySaveImage()
|
||||
R.id.menu_share -> shareImage()
|
||||
R.id.clear -> my_canvas.clearCanvas()
|
||||
R.id.clear -> clearCanvas()
|
||||
R.id.open_file -> tryOpenFile()
|
||||
R.id.change_background -> changeBackgroundClicked()
|
||||
R.id.settings -> launchSettings()
|
||||
|
@ -128,8 +132,10 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
if (path.endsWith(".svg")) {
|
||||
my_canvas.mBackgroundBitmap = null
|
||||
Svg.loadSvg(this, File(path), my_canvas)
|
||||
suggestedFileExtension = SVG
|
||||
} else if (File(path).isImageSlow()) {
|
||||
my_canvas.drawBitmap(this, path)
|
||||
suggestedFileExtension = JPG
|
||||
} else {
|
||||
toast(R.string.invalid_file_format)
|
||||
}
|
||||
|
@ -152,7 +158,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
}
|
||||
|
||||
private fun saveImage() {
|
||||
SaveImageDialog(this, curPath, my_canvas) {
|
||||
SaveImageDialog(this, suggestedFileExtension, curPath, my_canvas) {
|
||||
curPath = it
|
||||
}
|
||||
}
|
||||
|
@ -197,6 +203,11 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
return FileProvider.getUriForFile(this, "com.simplemobiletools.draw.fileprovider", file)
|
||||
}
|
||||
|
||||
private fun clearCanvas() {
|
||||
my_canvas.clearCanvas()
|
||||
suggestedFileExtension = PNG
|
||||
}
|
||||
|
||||
fun pickColor() {
|
||||
ColorPickerDialog(this, color) {
|
||||
setColor(it)
|
||||
|
@ -207,6 +218,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||
undo.setColorFilter(pickedColor.getContrastColor(), PorterDuff.Mode.SRC_IN)
|
||||
my_canvas.setBackgroundColor(pickedColor)
|
||||
my_canvas.mBackgroundBitmap = null
|
||||
suggestedFileExtension = PNG
|
||||
}
|
||||
|
||||
private fun setColor(pickedColor: Int) {
|
||||
|
|
|
@ -8,14 +8,14 @@ import com.simplemobiletools.draw.MyCanvas
|
|||
import com.simplemobiletools.draw.R
|
||||
import com.simplemobiletools.draw.Svg
|
||||
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 java.io.File
|
||||
import java.io.OutputStream
|
||||
|
||||
class SaveImageDialog(val activity: SimpleActivity, val curPath: String, val canvas: MyCanvas, callback: (path: String) -> Unit) {
|
||||
private val PNG = "png"
|
||||
private val SVG = "svg"
|
||||
private val JPG = "jpg"
|
||||
class SaveImageDialog(val activity: SimpleActivity, val suggestedExtension: String, val curPath: String, val canvas: MyCanvas, callback: (path: String) -> Unit) {
|
||||
private val SIMPLE_DRAW = "Simple Draw"
|
||||
|
||||
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('/')
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_save_image, null).apply {
|
||||
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.setOnClickListener {
|
||||
|
|
|
@ -4,3 +4,7 @@ val BRUSH_COLOR = "brush_color"
|
|||
val CANVAS_BACKGROUND_COLOR = "canvas_background_color"
|
||||
val SHOW_BRUSH_SIZE = "show_brush_size"
|
||||
val BRUSH_SIZE = "brush_size"
|
||||
|
||||
val PNG = "png"
|
||||
val SVG = "svg"
|
||||
val JPG = "jpg"
|
||||
|
|
Loading…
Reference in a new issue