blob: f536b47ee6d1c06aaccde498458367d0e558eed8 (
plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
|
using System.ComponentModel;
using Android.Graphics;
using Android.OS;
using Android.Views;
using AProgressBar = Android.Widget.ProgressBar;
namespace Xamarin.Forms.Platform.Android
{
public class ActivityIndicatorRenderer : ViewRenderer<ActivityIndicator, AProgressBar>
{
public ActivityIndicatorRenderer()
{
AutoPackage = false;
}
protected override AProgressBar CreateNativeControl()
{
return new AProgressBar(Context) { Indeterminate = true };
}
protected override void OnElementChanged(ElementChangedEventArgs<ActivityIndicator> e)
{
base.OnElementChanged(e);
AProgressBar progressBar = Control;
if (progressBar == null)
{
progressBar = CreateNativeControl();
SetNativeControl(progressBar);
}
UpdateColor();
UpdateVisibility();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == ActivityIndicator.IsRunningProperty.PropertyName)
UpdateVisibility();
else if (e.PropertyName == ActivityIndicator.ColorProperty.PropertyName)
UpdateColor();
}
void UpdateColor()
{
Color color = Element.Color;
if (!color.IsDefault)
Control.IndeterminateDrawable.SetColorFilter(color.ToAndroid(), PorterDuff.Mode.SrcIn);
else
Control.IndeterminateDrawable.ClearColorFilter();
}
void UpdateVisibility()
{
Control.Visibility = Element.IsRunning ? ViewStates.Visible : ViewStates.Invisible;
}
}
}
|