mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-02-17 12:10:47 +01:00
add a jpg radio button to saving dialog
This commit is contained in:
parent
cca5e9d2b7
commit
ecdbeab598
@ -16,12 +16,11 @@ import java.io.FileOutputStream
|
|||||||
class SaveImageDialog(val activity: SimpleActivity, val curPath: String, val canvas: MyCanvas, callback: (path: String) -> Unit) {
|
class SaveImageDialog(val activity: SimpleActivity, val curPath: String, val canvas: MyCanvas, callback: (path: String) -> Unit) {
|
||||||
private val PNG = "png"
|
private val PNG = "png"
|
||||||
private val SVG = "svg"
|
private val SVG = "svg"
|
||||||
|
private val JPG = "jpg"
|
||||||
private val SIMPLE_DRAW = "Simple Draw"
|
private val SIMPLE_DRAW = "Simple Draw"
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val defaultFilename = "image_${System.currentTimeMillis() / 1000}"
|
val initialFilename = getInitialFilename()
|
||||||
val initialFilename = if (curPath.isEmpty()) defaultFilename else curPath.getFilenameFromPath().substring(0, curPath.getFilenameFromPath().lastIndexOf("."))
|
|
||||||
|
|
||||||
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)
|
||||||
@ -49,7 +48,12 @@ class SaveImageDialog(val activity: SimpleActivity, val curPath: String, val can
|
|||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
val extension = if (view.save_image_radio_group.checkedRadioButtonId == R.id.save_image_radio_svg) SVG else PNG
|
val extension = when (view.save_image_radio_group.checkedRadioButtonId) {
|
||||||
|
R.id.save_image_radio_png -> PNG
|
||||||
|
R.id.save_image_radio_svg -> SVG
|
||||||
|
else -> JPG
|
||||||
|
}
|
||||||
|
|
||||||
val newFile = File(realPath, "$filename.$extension")
|
val newFile = File(realPath, "$filename.$extension")
|
||||||
if (!newFile.name.isAValidFilename()) {
|
if (!newFile.name.isAValidFilename()) {
|
||||||
activity.toast(R.string.filename_invalid_characters)
|
activity.toast(R.string.filename_invalid_characters)
|
||||||
@ -80,15 +84,21 @@ class SaveImageDialog(val activity: SimpleActivity, val curPath: String, val can
|
|||||||
try {
|
try {
|
||||||
out = FileOutputStream(file)
|
out = FileOutputStream(file)
|
||||||
canvas.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, out)
|
canvas.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, out)
|
||||||
} catch (e: Exception) {
|
|
||||||
return false
|
|
||||||
} finally {
|
} finally {
|
||||||
out?.close()
|
out?.close()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
JPG -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
SVG -> Svg.saveSvg(file, canvas)
|
SVG -> Svg.saveSvg(file, canvas)
|
||||||
}
|
}
|
||||||
activity.scanFile(file) {}
|
activity.scanFile(file) {}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getInitialFilename(): String {
|
||||||
|
val defaultFilename = "image_${System.currentTimeMillis() / 1000}"
|
||||||
|
return if (curPath.isEmpty()) defaultFilename else curPath.getFilenameFromPath().substring(0, curPath.getFilenameFromPath().lastIndexOf("."))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,5 +56,11 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text=".svg"/>
|
android:text=".svg"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/save_image_radio_jpg"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text=".jpg"/>
|
||||||
|
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user