File tree 2 files changed +28
-8
lines changed
Habitica/src/main/java/com/habitrpg/android/habitica/ui 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -397,4 +397,17 @@ class ArmoireActivity : BaseActivity() {
397
397
dialog.setContentView(R .layout.armoire_drop_rate_dialog)
398
398
dialog.show()
399
399
}
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
+ }
400
413
}
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ constructor(
27
27
invalidate()
28
28
}
29
29
private var paint: Paint = Paint ()
30
+ private var animator: ValueAnimator ? = null
30
31
31
32
var thickness = 3 .dpToPx(context)
32
33
var length = 6 .dpToPx(context)
@@ -59,15 +60,16 @@ constructor(
59
60
}
60
61
61
62
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()
65
72
}
66
- anim.interpolator = AccelerateDecelerateInterpolator ()
67
- anim.repeatCount = Animation .INFINITE
68
- anim.repeatMode = ValueAnimator .REVERSE
69
- anim.duration = animationDuration
70
- anim.start()
71
73
}
72
74
73
75
override fun onMeasure (
@@ -139,4 +141,9 @@ constructor(
139
141
paint
140
142
)
141
143
}
144
+
145
+ fun stopAnimating () {
146
+ animator?.end()
147
+ animator = null
148
+ }
142
149
}
You can’t perform that action at this time.
0 commit comments