mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-02-07 15:28:43 +01:00
couple minor code style updates
This commit is contained in:
parent
5a6b26efdf
commit
3e46a557bc
@ -250,7 +250,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
|||||||
|
|
||||||
constructor(parcel: Parcel) : super(parcel) {
|
constructor(parcel: Parcel) : super(parcel) {
|
||||||
val size = parcel.readInt()
|
val size = parcel.readInt()
|
||||||
for (i in 0..size - 1) {
|
for (i in 0 until size) {
|
||||||
val key = parcel.readSerializable() as MyPath
|
val key = parcel.readSerializable() as MyPath
|
||||||
val paintOptions = PaintOptions(parcel.readInt(), parcel.readFloat())
|
val paintOptions = PaintOptions(parcel.readInt(), parcel.readFloat())
|
||||||
paths.put(key, paintOptions)
|
paths.put(key, paintOptions)
|
||||||
|
@ -111,12 +111,10 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
|
|
||||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
if (requestCode == SAVE_IMAGE) {
|
when (requestCode) {
|
||||||
saveImage()
|
SAVE_IMAGE -> saveImage()
|
||||||
} else if (requestCode == OPEN_FILE) {
|
OPEN_FILE -> openFile()
|
||||||
openFile()
|
OPEN_FILE_INTENT -> openPath(openFileIntentPath)
|
||||||
} else if (requestCode == OPEN_FILE_INTENT) {
|
|
||||||
openPath(openFileIntentPath)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.no_storage_permissions)
|
toast(R.string.no_storage_permissions)
|
||||||
@ -146,15 +144,17 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openPath(path: String) {
|
private fun openPath(path: String) {
|
||||||
if (path.endsWith(".svg")) {
|
when {
|
||||||
my_canvas.mBackgroundBitmap = null
|
path.endsWith(".svg") -> {
|
||||||
Svg.loadSvg(this, File(path), my_canvas)
|
my_canvas.mBackgroundBitmap = null
|
||||||
suggestedFileExtension = SVG
|
Svg.loadSvg(this, File(path), my_canvas)
|
||||||
} else if (File(path).isImageSlow()) {
|
suggestedFileExtension = SVG
|
||||||
my_canvas.drawBitmap(this, path)
|
}
|
||||||
suggestedFileExtension = JPG
|
File(path).isImageSlow() -> {
|
||||||
} else {
|
my_canvas.drawBitmap(this, path)
|
||||||
toast(R.string.invalid_file_format)
|
suggestedFileExtension = JPG
|
||||||
|
}
|
||||||
|
else -> toast(R.string.invalid_file_format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,10 +211,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
fileOutputStream.write(bytes.toByteArray())
|
fileOutputStream.write(bytes.toByteArray())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
fileOutputStream?.close()
|
||||||
fileOutputStream?.close()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FileProvider.getUriForFile(this, "com.simplemobiletools.draw.fileprovider", file)
|
return FileProvider.getUriForFile(this, "com.simplemobiletools.draw.fileprovider", file)
|
||||||
@ -225,7 +222,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
suggestedFileExtension = PNG
|
suggestedFileExtension = PNG
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pickColor() {
|
private fun pickColor() {
|
||||||
ColorPickerDialog(this, color) {
|
ColorPickerDialog(this, color) {
|
||||||
setColor(it)
|
setColor(it)
|
||||||
}
|
}
|
||||||
@ -248,7 +245,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
undo.beVisibleIf(cnt > 0)
|
undo.beVisibleIf(cnt > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var onStrokeWidthBarChangeListener: SeekBar.OnSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
|
private var onStrokeWidthBarChangeListener: SeekBar.OnSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
my_canvas.setStrokeWidth(progress.toFloat())
|
my_canvas.setStrokeWidth(progress.toFloat())
|
||||||
strokeWidth = progress.toFloat()
|
strokeWidth = progress.toFloat()
|
||||||
|
@ -96,7 +96,7 @@ class SaveImageDialog(val activity: SimpleActivity, val suggestedExtension: Stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun writeToOutputStream(file: File, out: OutputStream) {
|
private fun writeToOutputStream(file: File, out: OutputStream) {
|
||||||
out.use { out ->
|
out.use {
|
||||||
canvas.getBitmap().compress(file.getCompressionFormat(), 70, out)
|
canvas.getBitmap().compress(file.getCompressionFormat(), 70, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user