Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit dd525cf

Browse files
committed
更换修改ValueAnimator#sDurationScale的方式。修复targetSdkVersion=29,开发者选项关闭动画缩放,无法播放动画
1 parent a8bcaf2 commit dd525cf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,19 @@ open class SVGAImageView @JvmOverloads constructor(context: Context, attrs: Attr
149149
var scale = 1.0
150150
try {
151151
val animatorClass = Class.forName("android.animation.ValueAnimator") ?: return scale
152-
val field = animatorClass.getDeclaredField("sDurationScale") ?: return scale
153-
field.isAccessible = true
154-
scale = field.getFloat(animatorClass).toDouble()
152+
val getMethod = animatorClass.getDeclaredMethod("getDurationScale") ?: return scale
153+
scale = (getMethod.invoke(animatorClass) as Float).toDouble()
155154
if (scale == 0.0) {
156-
field.setFloat(animatorClass, 1.0f)
155+
val setMethod = animatorClass.getDeclaredMethod("setDurationScale",Float::class.java) ?: return scale
156+
setMethod.isAccessible = true
157+
setMethod.invoke(animatorClass,1.0f)
157158
scale = 1.0
158159
LogUtils.info(TAG,
159160
"The animation duration scale has been reset to" +
160161
" 1.0x, because you closed it on developer options.")
161162
}
162163
} catch (ignore: Exception) {
164+
ignore.printStackTrace()
163165
}
164166
return scale
165167
}

0 commit comments

Comments
 (0)