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

Commit

Permalink
更换修改ValueAnimator#sDurationScale的方式。修复targetSdkVersion=29,开发者选项关闭动画缩放…
Browse files Browse the repository at this point in the history
…,无法播放动画
  • Loading branch information
fdh19979 committed Nov 20, 2020
1 parent a8bcaf2 commit dd525cf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,19 @@ open class SVGAImageView @JvmOverloads constructor(context: Context, attrs: Attr
var scale = 1.0
try {
val animatorClass = Class.forName("android.animation.ValueAnimator") ?: return scale
val field = animatorClass.getDeclaredField("sDurationScale") ?: return scale
field.isAccessible = true
scale = field.getFloat(animatorClass).toDouble()
val getMethod = animatorClass.getDeclaredMethod("getDurationScale") ?: return scale
scale = (getMethod.invoke(animatorClass) as Float).toDouble()
if (scale == 0.0) {
field.setFloat(animatorClass, 1.0f)
val setMethod = animatorClass.getDeclaredMethod("setDurationScale",Float::class.java) ?: return scale
setMethod.isAccessible = true
setMethod.invoke(animatorClass,1.0f)
scale = 1.0
LogUtils.info(TAG,
"The animation duration scale has been reset to" +
" 1.0x, because you closed it on developer options.")
}
} catch (ignore: Exception) {
ignore.printStackTrace()
}
return scale
}
Expand Down

0 comments on commit dd525cf

Please sign in to comment.