This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathProgressBarRenderer.cs
98 lines (84 loc) · 2.34 KB
/
ProgressBarRenderer.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.ComponentModel;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.OS;
using AProgressBar = Android.Widget.ProgressBar;
namespace Xamarin.Forms.Platform.Android
{
public class ProgressBarRenderer : ViewRenderer<ProgressBar, AProgressBar>
{
public ProgressBarRenderer(Context context) : base(context)
{
AutoPackage = false;
}
[Obsolete("This constructor is obsolete as of version 2.5. Please use ProgressBarRenderer(Context) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public ProgressBarRenderer()
{
AutoPackage = false;
}
protected override AProgressBar CreateNativeControl()
{
return new AProgressBar(Context, null, global::Android.Resource.Attribute.ProgressBarStyleHorizontal) { Indeterminate = false, Max = 10000 };
}
protected override void OnElementChanged(ElementChangedEventArgs<ProgressBar> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
if (Control == null)
{
var progressBar = CreateNativeControl();
SetNativeControl(progressBar);
}
UpdateProgressColor();
UpdateProgress();
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (this.IsDisposed())
{
return;
}
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == ProgressBar.ProgressProperty.PropertyName)
UpdateProgress();
else if (e.PropertyName == ProgressBar.ProgressColorProperty.PropertyName)
UpdateProgressColor();
}
internal virtual protected void UpdateProgressColor()
{
if (Element == null || Control == null)
return;
Color color = Element.ProgressColor;
if (color.IsDefault)
{
(Control.Indeterminate ? Control.IndeterminateDrawable :
Control.ProgressDrawable).ClearColorFilter();
}
else
{
if (Forms.SdkInt < BuildVersionCodes.Lollipop)
{
(Control.Indeterminate ? Control.IndeterminateDrawable :
Control.ProgressDrawable).SetColorFilter(color, FilterMode.SrcIn);
}
else
{
var tintList = ColorStateList.ValueOf(color.ToAndroid());
if (Control.Indeterminate)
Control.IndeterminateTintList = tintList;
else
Control.ProgressTintList = tintList;
}
}
}
void UpdateProgress()
{
Control.Progress = (int)(Element.Progress * 10000);
}
}
}