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