diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/MyCanvas.kt b/app/src/main/kotlin/com/simplemobiletools/draw/MyCanvas.kt index bff7f71..bd2e81f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/MyCanvas.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/MyCanvas.kt @@ -3,7 +3,6 @@ package com.simplemobiletools.draw import android.app.Activity import android.content.Context import android.graphics.* -import android.os.Parcel import android.os.Parcelable import android.util.AttributeSet import android.view.MotionEvent @@ -13,6 +12,7 @@ import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.request.RequestOptions import com.simplemobiletools.commons.extensions.getContrastColor import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.draw.models.MyParcelable import com.simplemobiletools.draw.models.MyPath import com.simplemobiletools.draw.models.PaintOptions import java.util.* @@ -260,38 +260,4 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) { mPaths = state.paths pathsUpdated() } - - internal class MyParcelable : View.BaseSavedState { - var paths = LinkedHashMap() - - constructor(superState: Parcelable) : super(superState) - - constructor(parcel: Parcel) : super(parcel) { - val size = parcel.readInt() - for (i in 0 until size) { - val key = parcel.readSerializable() as MyPath - val paintOptions = PaintOptions(parcel.readInt(), parcel.readFloat(), parcel.readInt() == 1) - paths.put(key, paintOptions) - } - } - - override fun writeToParcel(out: Parcel, flags: Int) { - super.writeToParcel(out, flags) - out.writeInt(paths.size) - for ((path, paintOptions) in paths) { - out.writeSerializable(path) - out.writeInt(paintOptions.color) - out.writeFloat(paintOptions.strokeWidth) - out.writeInt(if (paintOptions.isEraser) 1 else 0) - } - } - - companion object { - val CREATOR: Parcelable.Creator = object : Parcelable.Creator { - override fun createFromParcel(source: Parcel) = MyParcelable(source) - - override fun newArray(size: Int) = arrayOf() - } - } - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt index 22c0764..a690152 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt @@ -21,12 +21,12 @@ import com.simplemobiletools.commons.models.Release import com.simplemobiletools.draw.BuildConfig import com.simplemobiletools.draw.MyCanvas import com.simplemobiletools.draw.R -import com.simplemobiletools.draw.models.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 com.simplemobiletools.draw.models.Svg import kotlinx.android.synthetic.main.activity_main.* import java.io.ByteArrayOutputStream import java.io.File diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/models/MyParcelable.kt b/app/src/main/kotlin/com/simplemobiletools/draw/models/MyParcelable.kt new file mode 100644 index 0000000..5af7d9a --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/draw/models/MyParcelable.kt @@ -0,0 +1,40 @@ +package com.simplemobiletools.draw.models + +import android.os.Parcel +import android.os.Parcelable +import android.view.View +import java.util.* + +internal class MyParcelable : View.BaseSavedState { + var paths = LinkedHashMap() + + constructor(superState: Parcelable) : super(superState) + + constructor(parcel: Parcel) : super(parcel) { + val size = parcel.readInt() + for (i in 0 until size) { + val key = parcel.readSerializable() as MyPath + val paintOptions = PaintOptions(parcel.readInt(), parcel.readFloat(), parcel.readInt() == 1) + paths.put(key, paintOptions) + } + } + + override fun writeToParcel(out: Parcel, flags: Int) { + super.writeToParcel(out, flags) + out.writeInt(paths.size) + for ((path, paintOptions) in paths) { + out.writeSerializable(path) + out.writeInt(paintOptions.color) + out.writeFloat(paintOptions.strokeWidth) + out.writeInt(if (paintOptions.isEraser) 1 else 0) + } + } + + companion object { + val CREATOR: Parcelable.Creator = object : Parcelable.Creator { + override fun createFromParcel(source: Parcel) = MyParcelable(source) + + override fun newArray(size: Int) = arrayOf() + } + } +}