@@ -5,7 +5,6 @@ import android.content.res.Configuration
55import android.graphics.*
66import android.graphics.drawable.Drawable
77import android.net.Uri
8- import android.os.Build
98import android.os.Bundle
109import android.os.Parcelable
1110import android.util.AttributeSet
@@ -20,6 +19,8 @@ import android.view.animation.AccelerateDecelerateInterpolator
2019import android.view.animation.LinearInterpolator
2120import android.widget.OverScroller
2221import androidx.appcompat.widget.AppCompatImageView
22+ import androidx.core.os.BundleCompat
23+ import androidx.core.os.bundleOf
2324import kotlin.math.abs
2425import kotlin.math.max
2526import kotlin.math.min
@@ -226,25 +227,27 @@ open class TouchImageView @JvmOverloads constructor(context: Context, attrs: Att
226227 }
227228 }
228229
229- public override fun onSaveInstanceState (): Parcelable ? {
230- super .onSaveInstanceState()
231- val bundle = Bundle ()
232- bundle.putInt(" orientation" , orientation)
233- bundle.putFloat(" saveScale" , currentZoom)
234- bundle.putFloat(" matchViewHeight" , matchViewHeight)
235- bundle.putFloat(" matchViewWidth" , matchViewWidth)
236- bundle.putInt(" viewWidth" , viewWidth)
237- bundle.putInt(" viewHeight" , viewHeight)
230+ public override fun onSaveInstanceState (): Parcelable {
238231 touchMatrix.getValues(floatMatrix)
239- bundle.putFloatArray(" matrix" , floatMatrix)
240- bundle.putBoolean(" imageRendered" , imageRenderedAtLeastOnce)
241- bundle.putSerializable(" viewSizeChangeFixedPixel" , viewSizeChangeFixedPixel)
242- bundle.putSerializable(" orientationChangeFixedPixel" , orientationChangeFixedPixel)
243- return bundle
232+
233+ return bundleOf(
234+ " parent" to super .onSaveInstanceState(),
235+ " orientation" to orientation,
236+ " saveScale" to currentZoom,
237+ " matchViewHeight" to matchViewHeight,
238+ " matchViewWidth" to matchViewWidth,
239+ " viewWidth" to viewWidth,
240+ " viewHeight" to viewHeight,
241+ " matrix" to floatMatrix,
242+ " imageRendered" to imageRenderedAtLeastOnce,
243+ " viewSizeChangeFixedPixel" to viewSizeChangeFixedPixel,
244+ " orientationChangeFixedPixel" to orientationChangeFixedPixel
245+ )
244246 }
245247
246248 public override fun onRestoreInstanceState (state : Parcelable ) {
247249 if (state is Bundle ) {
250+ super .onRestoreInstanceState(BundleCompat .getParcelable(state, " parent" , Parcelable ::class .java))
248251 currentZoom = state.getFloat(" saveScale" )
249252 floatMatrix = state.getFloatArray(" matrix" )!!
250253 prevMatrix.setValues(floatMatrix)
@@ -253,15 +256,8 @@ open class TouchImageView @JvmOverloads constructor(context: Context, attrs: Att
253256 prevViewHeight = state.getInt(" viewHeight" )
254257 prevViewWidth = state.getInt(" viewWidth" )
255258 imageRenderedAtLeastOnce = state.getBoolean(" imageRendered" )
256- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
257- viewSizeChangeFixedPixel = state.getSerializable(" viewSizeChangeFixedPixel" , FixedPixel ::class .java)
258- orientationChangeFixedPixel = state.getSerializable(" orientationChangeFixedPixel" , FixedPixel ::class .java)
259- } else {
260- @Suppress(" DEPRECATION" )
261- viewSizeChangeFixedPixel = state.getSerializable(" viewSizeChangeFixedPixel" ) as FixedPixel ?
262- @Suppress(" DEPRECATION" )
263- orientationChangeFixedPixel = state.getSerializable(" orientationChangeFixedPixel" ) as FixedPixel ?
264- }
259+ viewSizeChangeFixedPixel = BundleCompat .getSerializable(state, " viewSizeChangeFixedPixel" , FixedPixel ::class .java)
260+ orientationChangeFixedPixel = BundleCompat .getSerializable(state, " orientationChangeFixedPixel" , FixedPixel ::class .java)
265261 val oldOrientation = state.getInt(" orientation" )
266262 if (orientation != oldOrientation) {
267263 orientationJustChanged = true
0 commit comments