-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandyAnimator.cs
49 lines (41 loc) · 1.56 KB
/
HandyAnimator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using Android.Animation;
namespace Segmentus
{
class HandyAnimator
{
static HashSet<HandyAnimator> animators = new HashSet<HandyAnimator>();
static public void OnActivityDestroy()
{
List<HandyAnimator> l = animators.ToList();
foreach (HandyAnimator ha in l)
{
ha.RemoveAfterActions();
ha.After = null;
ha.core.End();
}
animators.Clear();
}
public event Action<Java.Lang.Object> Update;
public event Action After;
public ValueAnimator core;
public void RemoveAfterActions() => After = null;
HandyAnimator(ValueAnimator coreAnim, int duration)
{
core = coreAnim;
core.SetDuration(duration);
core.Update += (sender, e) => Update?.Invoke(e.Animation.AnimatedValue);
core.AnimationEnd += (sender, e) => After?.Invoke();
core.AnimationEnd += (sender, e) => animators.Remove(this);
animators.Add(this);
}
static public HandyAnimator OfFloat(float from, float to, int duration) =>
new HandyAnimator(ValueAnimator.OfFloat(from, to), duration);
static public HandyAnimator OfArgb(int from, int to, int duration) =>
new HandyAnimator(ValueAnimator.OfArgb(from, to), duration);
static public HandyAnimator OfNothing(int duration) =>
new HandyAnimator(ValueAnimator.OfInt(0, 0), duration);
}
}