@@ -106,11 +106,14 @@ class ApngDrawable @VisibleForTesting internal constructor(
106
106
*/
107
107
val isRecycled: Boolean = apngState.apng.isRecycled
108
108
109
- private val paint: Paint = Paint (Paint .FILTER_BITMAP_FLAG or Paint .DITHER_FLAG )
110
- private val animationCallbacks: MutableList <Animatable2Compat .AnimationCallback > = arrayListOf ()
111
- private val repeatAnimationCallbacks: MutableList <RepeatAnimationCallback > = arrayListOf ()
112
- private val currentRepeatCount: Int
113
- get() = (animationElapsedTimeMillis / durationMillis).toInt() + 1
109
+ /* *
110
+ * The number indicating the current loop number.
111
+ * The first loop is `1` and last loop is same with [loopCount]
112
+ */
113
+ val currentRepeatCount: Int
114
+ get() =
115
+ if (currentRepeatCountInternal > loopCount) loopCount else currentRepeatCountInternal
116
+
114
117
/* *
115
118
* [currentFrameIndex] is the index to indicate which frame should show at that time.
116
119
* [currentFrameIndex] is calculated with APNG meta data and elapsed time after animation
@@ -121,13 +124,18 @@ class ApngDrawable @VisibleForTesting internal constructor(
121
124
* If this image isn't infinite looping image and [animationElapsedTimeMillis] is larger than
122
125
* total duration of this image's animation, returns always last frame index.
123
126
*/
124
- private val currentFrameIndex: Int
127
+ val currentFrameIndex: Int
125
128
get() = if (loopCount != LOOP_FOREVER && exceedsRepeatCountLimitation()) {
126
129
frameCount - 1
127
130
} else {
128
131
(animationElapsedTimeMillis % durationMillis * frameCount / durationMillis).toInt()
129
132
}
130
133
134
+ private val currentRepeatCountInternal: Int
135
+ get() = (animationElapsedTimeMillis / durationMillis).toInt() + 1
136
+ private val paint: Paint = Paint (Paint .FILTER_BITMAP_FLAG or Paint .DITHER_FLAG )
137
+ private val animationCallbacks: MutableList <Animatable2Compat .AnimationCallback > = arrayListOf ()
138
+ private val repeatAnimationCallbacks: MutableList <RepeatAnimationCallback > = arrayListOf ()
131
139
private var scaledWidth: Int = apngState.width
132
140
private var scaledHeight: Int = apngState.height
133
141
private var isStarted: Boolean = false
@@ -292,7 +300,7 @@ class ApngDrawable @VisibleForTesting internal constructor(
292
300
frameChanged
293
301
) {
294
302
repeatAnimationCallbacks.forEach {
295
- it.onRepeat(this , currentRepeatCount + 1 )
303
+ it.onRepeat(this , currentRepeatCountInternal + 1 )
296
304
}
297
305
}
298
306
}
@@ -308,20 +316,20 @@ class ApngDrawable @VisibleForTesting internal constructor(
308
316
309
317
private fun isLastFrame (): Boolean = currentFrameIndex == frameCount - 1
310
318
311
- private fun isFirstLoop (): Boolean = currentRepeatCount == 1
319
+ private fun isFirstLoop (): Boolean = currentRepeatCountInternal == 1
312
320
313
321
private fun hasNextLoop (): Boolean {
314
322
if (loopCount == LOOP_FOREVER ) {
315
323
return true
316
324
}
317
- return currentRepeatCount < loopCount
325
+ return currentRepeatCountInternal < loopCount
318
326
}
319
327
320
328
private fun exceedsRepeatCountLimitation (): Boolean {
321
329
if (loopCount == LOOP_FOREVER ) {
322
330
return false
323
331
}
324
- return currentRepeatCount > loopCount
332
+ return currentRepeatCountInternal > loopCount
325
333
}
326
334
327
335
private fun computeBitmapSize () {
0 commit comments