blob: f2ea5cc35690fc059f65fd374f4b6823d1ae5704 (
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
62
63
64
65
66
|
using System.ComponentModel;
using Android.Content;
using Android.Views;
using AView = Android.Views.View;
using ASwitch = Android.Widget.Switch;
namespace Xamarin.Forms.Platform.Android
{
public class SwitchCellRenderer : CellRenderer
{
const double DefaultHeight = 30;
SwitchCellView _view;
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
{
var cell = (SwitchCell)Cell;
if ((_view = convertView as SwitchCellView) == null)
_view = new SwitchCellView(context, item);
_view.Cell = cell;
UpdateText();
UpdateChecked();
UpdateHeight();
UpdateIsEnabled(_view, cell);
return _view;
}
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == SwitchCell.TextProperty.PropertyName)
UpdateText();
else if (args.PropertyName == SwitchCell.OnProperty.PropertyName)
UpdateChecked();
else if (args.PropertyName == "RenderHeight")
UpdateHeight();
else if (args.PropertyName == Cell.IsEnabledProperty.PropertyName)
UpdateIsEnabled(_view, (SwitchCell)sender);
}
void UpdateChecked()
{
((ASwitch)_view.AccessoryView).Checked = ((SwitchCell)Cell).On;
}
void UpdateIsEnabled(SwitchCellView cell, SwitchCell switchCell)
{
cell.Enabled = switchCell.IsEnabled;
var aSwitch = cell.AccessoryView as ASwitch;
if (aSwitch != null)
aSwitch.Enabled = switchCell.IsEnabled;
}
void UpdateHeight()
{
_view.SetRenderHeight(Cell.RenderHeight);
}
void UpdateText()
{
_view.MainText = ((SwitchCell)Cell).Text;
}
}
}
|