removing some redundant drawing related files
This commit is contained in:
parent
1776ab592d
commit
d8e19762fc
7 changed files with 6 additions and 226 deletions
|
@ -1,11 +0,0 @@
|
||||||
package com.simplemobiletools.gallery.pro.actions
|
|
||||||
|
|
||||||
import android.graphics.Path
|
|
||||||
import java.io.Serializable
|
|
||||||
import java.io.Writer
|
|
||||||
|
|
||||||
interface Action : Serializable {
|
|
||||||
fun perform(path: Path)
|
|
||||||
|
|
||||||
fun perform(writer: Writer)
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.simplemobiletools.gallery.pro.actions
|
|
||||||
|
|
||||||
import android.graphics.Path
|
|
||||||
import java.io.Writer
|
|
||||||
import java.security.InvalidParameterException
|
|
||||||
|
|
||||||
class Line : Action {
|
|
||||||
|
|
||||||
val x: Float
|
|
||||||
val y: Float
|
|
||||||
|
|
||||||
constructor(data: String) {
|
|
||||||
if (!data.startsWith("L"))
|
|
||||||
throw InvalidParameterException("The Line data should start with 'L'.")
|
|
||||||
|
|
||||||
try {
|
|
||||||
val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
|
||||||
x = xy[0].trim().toFloat()
|
|
||||||
y = xy[1].trim().toFloat()
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
throw InvalidParameterException("Error parsing the given Line data.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(x: Float, y: Float) {
|
|
||||||
this.x = x
|
|
||||||
this.y = y
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun perform(path: Path) {
|
|
||||||
path.lineTo(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun perform(writer: Writer) {
|
|
||||||
writer.write("L$x,$y")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.simplemobiletools.gallery.pro.actions
|
|
||||||
|
|
||||||
import android.graphics.Path
|
|
||||||
import java.io.Writer
|
|
||||||
import java.security.InvalidParameterException
|
|
||||||
|
|
||||||
class Move : Action {
|
|
||||||
|
|
||||||
val x: Float
|
|
||||||
val y: Float
|
|
||||||
|
|
||||||
constructor(data: String) {
|
|
||||||
if (!data.startsWith("M"))
|
|
||||||
throw InvalidParameterException("The Move data should start with 'M'.")
|
|
||||||
|
|
||||||
try {
|
|
||||||
val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
|
||||||
x = xy[0].trim().toFloat()
|
|
||||||
y = xy[1].trim().toFloat()
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
throw InvalidParameterException("Error parsing the given Move data.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(x: Float, y: Float) {
|
|
||||||
this.x = x
|
|
||||||
this.y = y
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun perform(path: Path) {
|
|
||||||
path.moveTo(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun perform(writer: Writer) {
|
|
||||||
writer.write("M$x,$y")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package com.simplemobiletools.gallery.pro.actions
|
|
||||||
|
|
||||||
import android.graphics.Path
|
|
||||||
import java.io.Writer
|
|
||||||
import java.security.InvalidParameterException
|
|
||||||
|
|
||||||
class Quad : Action {
|
|
||||||
|
|
||||||
val x1: Float
|
|
||||||
val y1: Float
|
|
||||||
val x2: Float
|
|
||||||
val y2: Float
|
|
||||||
|
|
||||||
constructor(data: String) {
|
|
||||||
if (!data.startsWith("Q"))
|
|
||||||
throw InvalidParameterException("The Quad data should start with 'Q'.")
|
|
||||||
|
|
||||||
try {
|
|
||||||
val parts = data.split("\\s+".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
|
||||||
val xy1 = parts[0].substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
|
||||||
val xy2 = parts[1].split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
|
||||||
|
|
||||||
x1 = xy1[0].trim().toFloat()
|
|
||||||
y1 = xy1[1].trim().toFloat()
|
|
||||||
x2 = xy2[0].trim().toFloat()
|
|
||||||
y2 = xy2[1].trim().toFloat()
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
throw InvalidParameterException("Error parsing the given Quad data.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(x1: Float, y1: Float, x2: Float, y2: Float) {
|
|
||||||
this.x1 = x1
|
|
||||||
this.y1 = y1
|
|
||||||
this.x2 = x2
|
|
||||||
this.y2 = y2
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun perform(path: Path) {
|
|
||||||
path.quadTo(x1, y1, x2, y2)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun perform(writer: Writer) {
|
|
||||||
writer.write("Q$x1,$y1 $x2,$y2")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
package com.simplemobiletools.gallery.pro.models
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.graphics.Path
|
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
|
||||||
import com.simplemobiletools.gallery.pro.R
|
|
||||||
import com.simplemobiletools.gallery.pro.actions.Action
|
|
||||||
import com.simplemobiletools.gallery.pro.actions.Line
|
|
||||||
import com.simplemobiletools.gallery.pro.actions.Move
|
|
||||||
import com.simplemobiletools.gallery.pro.actions.Quad
|
|
||||||
import java.io.ObjectInputStream
|
|
||||||
import java.io.Serializable
|
|
||||||
import java.security.InvalidParameterException
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
// https://stackoverflow.com/a/8127953
|
|
||||||
class MyPath : Path(), Serializable {
|
|
||||||
val actions = LinkedList<Action>()
|
|
||||||
|
|
||||||
private fun readObject(inputStream: ObjectInputStream) {
|
|
||||||
inputStream.defaultReadObject()
|
|
||||||
|
|
||||||
val copiedActions = actions.map { it }
|
|
||||||
copiedActions.forEach {
|
|
||||||
it.perform(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readObject(pathData: String, activity: Activity) {
|
|
||||||
val tokens = pathData.split("\\s+".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
|
||||||
var i = 0
|
|
||||||
try {
|
|
||||||
while (i < tokens.size) {
|
|
||||||
when (tokens[i][0]) {
|
|
||||||
'M' -> addAction(Move(tokens[i]))
|
|
||||||
'L' -> addAction(Line(tokens[i]))
|
|
||||||
'Q' -> {
|
|
||||||
// Quad actions are of the following form:
|
|
||||||
// "Qx1,y1 x2,y2"
|
|
||||||
// Since we split the tokens by whitespace, we need to join them again
|
|
||||||
if (i + 1 >= tokens.size)
|
|
||||||
throw InvalidParameterException("Error parsing the data for a Quad.")
|
|
||||||
|
|
||||||
addAction(Quad(tokens[i] + " " + tokens[i + 1]))
|
|
||||||
++i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++i
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
activity.toast(R.string.unknown_error_occurred)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun reset() {
|
|
||||||
actions.clear()
|
|
||||||
super.reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addAction(action: Action) {
|
|
||||||
when (action) {
|
|
||||||
is Move -> moveTo(action.x, action.y)
|
|
||||||
is Line -> lineTo(action.x, action.y)
|
|
||||||
is Quad -> quadTo(action.x1, action.y1, action.x2, action.y2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun moveTo(x: Float, y: Float) {
|
|
||||||
actions.add(Move(x, y))
|
|
||||||
super.moveTo(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun lineTo(x: Float, y: Float) {
|
|
||||||
actions.add(Line(x, y))
|
|
||||||
super.lineTo(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun quadTo(x1: Float, y1: Float, x2: Float, y2: Float) {
|
|
||||||
actions.add(Quad(x1, y1, x2, y2))
|
|
||||||
super.quadTo(x1, y1, x2, y2)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,6 +2,4 @@ package com.simplemobiletools.gallery.pro.models
|
||||||
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
|
||||||
data class PaintOptions(var color: Int = Color.BLACK, var strokeWidth: Float = 5f, var isEraser: Boolean = false) {
|
data class PaintOptions(var color: Int = Color.BLACK, var strokeWidth: Float = 5f)
|
||||||
fun getColorToExport() = if (isEraser) "none" else "#${Integer.toHexString(color).substring(2)}"
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
package com.simplemobiletools.gallery.pro.views
|
package com.simplemobiletools.gallery.pro.views
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.*
|
||||||
import android.graphics.Canvas
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.Paint
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.simplemobiletools.gallery.pro.R
|
import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.extensions.config
|
import com.simplemobiletools.gallery.pro.extensions.config
|
||||||
import com.simplemobiletools.gallery.pro.models.MyPath
|
|
||||||
import com.simplemobiletools.gallery.pro.models.PaintOptions
|
import com.simplemobiletools.gallery.pro.models.PaintOptions
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -22,9 +18,9 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at
|
||||||
private var mColor = 0
|
private var mColor = 0
|
||||||
private var mWasMultitouch = false
|
private var mWasMultitouch = false
|
||||||
|
|
||||||
private var mPaths = LinkedHashMap<MyPath, PaintOptions>()
|
private var mPaths = LinkedHashMap<Path, PaintOptions>()
|
||||||
private var mPaint = Paint()
|
private var mPaint = Paint()
|
||||||
private var mPath = MyPath()
|
private var mPath = Path()
|
||||||
private var mPaintOptions = PaintOptions()
|
private var mPaintOptions = PaintOptions()
|
||||||
|
|
||||||
private var backgroundBitmap: Bitmap? = null
|
private var backgroundBitmap: Bitmap? = null
|
||||||
|
@ -56,7 +52,6 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at
|
||||||
|
|
||||||
changePaint(mPaintOptions)
|
changePaint(mPaintOptions)
|
||||||
canvas.drawPath(mPath, mPaint)
|
canvas.drawPath(mPath, mPaint)
|
||||||
|
|
||||||
canvas.restore()
|
canvas.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +105,8 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at
|
||||||
}
|
}
|
||||||
|
|
||||||
mPaths[mPath] = mPaintOptions
|
mPaths[mPath] = mPaintOptions
|
||||||
mPath = MyPath()
|
mPath = Path()
|
||||||
mPaintOptions = PaintOptions(mPaintOptions.color, mPaintOptions.strokeWidth, mPaintOptions.isEraser)
|
mPaintOptions = PaintOptions(mPaintOptions.color, mPaintOptions.strokeWidth)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun changePaint(paintOptions: PaintOptions) {
|
private fun changePaint(paintOptions: PaintOptions) {
|
||||||
|
|
Loading…
Reference in a new issue