forked from Clancey/MonoDroid.Dialog
-
Notifications
You must be signed in to change notification settings - Fork 7
/
CheckboxElement.cs
113 lines (95 loc) · 3.09 KB
/
CheckboxElement.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using Android.Content;
using Android.Views;
using Android.Widget;
namespace Android.Dialog
{
public class CheckboxElement : Element, CompoundButton.IOnCheckedChangeListener
{
public bool Value
{
get { return _val; }
set
{
bool emit = _val != value;
_val = value;
if (_checkbox != null && _checkbox.Checked != _val)
_checkbox.Checked = _val;
else if (emit && Changed != null)
Changed(this, EventArgs.Empty);
}
}
private bool _val;
public string SubCaption { get; set; }
public bool ReadOnly
{
get;
set;
}
public event EventHandler Changed;
private CheckBox _checkbox;
private TextView _caption;
private TextView _subCaption;
public string Group;
public CheckboxElement(string caption)
: base(caption, Resource.Layout.dialog_boolfieldright)
{
}
public CheckboxElement(string caption, bool value)
: base(caption, Resource.Layout.dialog_boolfieldright)
{
Value = value;
}
public CheckboxElement(string caption, bool value, string subCaption, string group)
: base(caption, Resource.Layout.dialog_boolfieldsubright)
{
Value = value;
Group = group;
SubCaption = subCaption;
}
public CheckboxElement(string caption, bool value, string group)
: base(caption, Resource.Layout.dialog_boolfieldright)
{
Value = value;
Group = group;
}
public CheckboxElement(string caption, bool value, string group, int layoutId)
: base(caption, layoutId)
{
Value = value;
Group = group;
}
public override View GetView(Context context, View convertView, ViewGroup parent)
{
View checkboxView;
View view = DroidResources.LoadBooleanElementLayout(context, convertView, parent, LayoutId, out _caption, out _subCaption, out checkboxView);
if (view != null)
{
_caption.Text = Caption;
_checkbox = (CheckBox)checkboxView;
_checkbox.SetOnCheckedChangeListener(null);
_checkbox.Checked = Value;
_checkbox.SetOnCheckedChangeListener(this);
_checkbox.Clickable = !ReadOnly;
if (_subCaption != null)
{
_subCaption.Text = SubCaption;
}
}
return view;
}
public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
{
Value = isChecked;
}
public override void Selected()
{
if (!ReadOnly)
_checkbox.Toggle();
}
public override string Summary()
{
return Value ? "On" : "Off"; //Because iOS, that's why.
}
}
}