From d8e19762fcd5e4c52e06de11ab32bc432b1d8c4f Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 13 Jan 2019 18:12:03 +0100 Subject: [PATCH] removing some redundant drawing related files --- .../gallery/pro/actions/Action.kt | 11 --- .../gallery/pro/actions/Line.kt | 37 --------- .../gallery/pro/actions/Move.kt | 37 --------- .../gallery/pro/actions/Quad.kt | 46 ----------- .../gallery/pro/models/MyPath.kt | 82 ------------------- .../gallery/pro/models/PaintOptions.kt | 4 +- .../gallery/pro/views/EditorDrawCanvas.kt | 15 ++-- 7 files changed, 6 insertions(+), 226 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Action.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Line.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Move.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Quad.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/MyPath.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Action.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Action.kt deleted file mode 100644 index adbc82662..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Action.kt +++ /dev/null @@ -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) -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Line.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Line.kt deleted file mode 100644 index a38a70b1f..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Line.kt +++ /dev/null @@ -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") - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Move.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Move.kt deleted file mode 100644 index bf96489bb..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Move.kt +++ /dev/null @@ -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") - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Quad.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Quad.kt deleted file mode 100644 index fb281c29a..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/actions/Quad.kt +++ /dev/null @@ -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") - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/MyPath.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/MyPath.kt deleted file mode 100644 index 564eab0c8..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/MyPath.kt +++ /dev/null @@ -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() - - 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) - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/PaintOptions.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/PaintOptions.kt index 34c128dca..fc1cacb2a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/PaintOptions.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/PaintOptions.kt @@ -2,6 +2,4 @@ package com.simplemobiletools.gallery.pro.models import android.graphics.Color -data class PaintOptions(var color: Int = Color.BLACK, var strokeWidth: Float = 5f, var isEraser: Boolean = false) { - fun getColorToExport() = if (isEraser) "none" else "#${Integer.toHexString(color).substring(2)}" -} +data class PaintOptions(var color: Int = Color.BLACK, var strokeWidth: Float = 5f) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/EditorDrawCanvas.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/EditorDrawCanvas.kt index 8d1ee75b7..592320b33 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/EditorDrawCanvas.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/EditorDrawCanvas.kt @@ -1,16 +1,12 @@ package com.simplemobiletools.gallery.pro.views import android.content.Context -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.Color -import android.graphics.Paint +import android.graphics.* import android.util.AttributeSet import android.view.MotionEvent import android.view.View import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config -import com.simplemobiletools.gallery.pro.models.MyPath import com.simplemobiletools.gallery.pro.models.PaintOptions import java.util.* @@ -22,9 +18,9 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at private var mColor = 0 private var mWasMultitouch = false - private var mPaths = LinkedHashMap() + private var mPaths = LinkedHashMap() private var mPaint = Paint() - private var mPath = MyPath() + private var mPath = Path() private var mPaintOptions = PaintOptions() private var backgroundBitmap: Bitmap? = null @@ -56,7 +52,6 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at changePaint(mPaintOptions) canvas.drawPath(mPath, mPaint) - canvas.restore() } @@ -110,8 +105,8 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at } mPaths[mPath] = mPaintOptions - mPath = MyPath() - mPaintOptions = PaintOptions(mPaintOptions.color, mPaintOptions.strokeWidth, mPaintOptions.isEraser) + mPath = Path() + mPaintOptions = PaintOptions(mPaintOptions.color, mPaintOptions.strokeWidth) } private fun changePaint(paintOptions: PaintOptions) {