File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed
Habitica/src/main/java/com/habitrpg/android/habitica/ui Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -397,4 +397,17 @@ class ArmoireActivity : BaseActivity() {
397397 dialog.setContentView(R .layout.armoire_drop_rate_dialog)
398398 dialog.show()
399399 }
400+
401+ override fun onPause () {
402+ super .onPause()
403+ // Clear infinite animations on pause to make sure Context references aren't leaked.
404+ stopInfiniteAnimations()
405+ }
406+
407+ private fun stopInfiniteAnimations () {
408+ binding.leftSparkView.stopAnimating()
409+ binding.rightSparkView.stopAnimating()
410+ binding.iconView.animation?.cancel()
411+ binding.iconView.animation = null
412+ }
400413}
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ constructor(
2727 invalidate()
2828 }
2929 private var paint: Paint = Paint ()
30+ private var animator: ValueAnimator ? = null
3031
3132 var thickness = 3 .dpToPx(context)
3233 var length = 6 .dpToPx(context)
@@ -59,15 +60,16 @@ constructor(
5960 }
6061
6162 fun startAnimating () {
62- val anim = ObjectAnimator .ofFloat(thickness.toFloat(), maxSpacing.toFloat())
63- anim.addUpdateListener {
64- spacing = it.animatedValue as Float
63+ animator = ObjectAnimator .ofFloat(thickness.toFloat(), maxSpacing.toFloat()).apply {
64+ addUpdateListener {
65+ spacing = it.animatedValue as Float
66+ }
67+ interpolator = AccelerateDecelerateInterpolator ()
68+ repeatCount = Animation .INFINITE
69+ repeatMode = ValueAnimator .REVERSE
70+ duration = animationDuration
71+ start()
6572 }
66- anim.interpolator = AccelerateDecelerateInterpolator ()
67- anim.repeatCount = Animation .INFINITE
68- anim.repeatMode = ValueAnimator .REVERSE
69- anim.duration = animationDuration
70- anim.start()
7173 }
7274
7375 override fun onMeasure (
@@ -139,4 +141,9 @@ constructor(
139141 paint
140142 )
141143 }
144+
145+ fun stopAnimating () {
146+ animator?.end()
147+ animator = null
148+ }
142149}
You can’t perform that action at this time.
0 commit comments