rename SavedState to MyParcelable

This commit is contained in:
tibbi 2017-06-23 21:50:28 +02:00
parent 5386ea8ffa
commit 0e111015bd
1 changed files with 15 additions and 15 deletions

View File

@ -216,13 +216,13 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
public override fun onSaveInstanceState(): Parcelable {
val superState = super.onSaveInstanceState()
val savedState = SavedState(superState)
val savedState = MyParcelable(superState)
savedState.paths = mPaths
return savedState
}
public override fun onRestoreInstanceState(state: Parcelable) {
if (state !is SavedState) {
if (state !is MyParcelable) {
super.onRestoreInstanceState(state)
return
}
@ -232,19 +232,20 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
pathsUpdated()
}
internal class SavedState : View.BaseSavedState {
internal class MyParcelable : View.BaseSavedState {
var paths = LinkedHashMap<MyPath, PaintOptions>()
companion object {
val CREATOR: Parcelable.Creator<SavedState> = object : Parcelable.Creator<SavedState> {
override fun newArray(size: Int) = arrayOf<SavedState>()
constructor(superState: Parcelable) : super(superState)
override fun createFromParcel(source: Parcel) = SavedState(source)
constructor(parcel: Parcel) : super(parcel) {
val size = parcel.readInt()
for (i in 0..size - 1) {
val key = parcel.readSerializable() as MyPath
val paintOptions = PaintOptions(parcel.readInt(), parcel.readFloat())
paths.put(key, paintOptions)
}
}
constructor(superState: Parcelable) : super(superState)
override fun writeToParcel(out: Parcel, flags: Int) {
super.writeToParcel(out, flags)
out.writeInt(paths.size)
@ -255,12 +256,11 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
}
}
private constructor(parcel: Parcel) : super(parcel) {
val size = parcel.readInt()
for (i in 0..size - 1) {
val key = parcel.readSerializable() as MyPath
val paintOptions = PaintOptions(parcel.readInt(), parcel.readFloat())
paths.put(key, paintOptions)
companion object {
val CREATOR: Parcelable.Creator<MyParcelable> = object : Parcelable.Creator<MyParcelable> {
override fun createFromParcel(source: Parcel) = MyParcelable(source)
override fun newArray(size: Int) = arrayOf<MyParcelable>()
}
}
}