forked from Clancey/MonoDroid.Dialog
-
Notifications
You must be signed in to change notification settings - Fork 7
/
BooleanElement.cs
118 lines (101 loc) · 3.19 KB
/
BooleanElement.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
114
115
116
117
118
using System;
using Android.Content;
using Android.Views;
using Android.Widget;
namespace Android.Dialog
{
public abstract class BoolElement : Element
{
private bool _val;
public string TextOff { get; set; }
public string TextOn { get; set; }
public bool Value
{
get { return _val; }
set
{
if (_val != value)
{
_val = value;
if (Changed != null)
Changed(this, EventArgs.Empty);
}
}
}
public event EventHandler Changed;
public BoolElement(string caption, bool value)
: base(caption)
{
_val = value;
}
public BoolElement(string caption, bool value, int layoutId)
: base(caption, layoutId)
{
_val = value;
}
public override string Summary()
{
return _val ? TextOn : TextOff;
}
}
/// <summary>
/// Used to display toggle button on the screen.
/// </summary>
public class BooleanElement : BoolElement, CompoundButton.IOnCheckedChangeListener
{
protected ToggleButton _toggleButton;
protected TextView _caption;
protected TextView _subCaption;
public BooleanElement(string caption, bool value)
: base(caption, value, Resource.Layout.dialog_onofffieldright)
{
}
public BooleanElement(string caption, bool value, int layoutId)
: base(caption, value, layoutId)
{
}
public override View GetView(Context context, View convertView, ViewGroup parent)
{
View toggleButtonView;
View view = DroidResources.LoadBooleanElementLayout(context, convertView, parent, LayoutId, out _caption, out _subCaption, out toggleButtonView);
if (view != null)
{
_caption.Text = Caption;
_toggleButton = (ToggleButton)toggleButtonView;
_toggleButton.SetOnCheckedChangeListener(null);
_toggleButton.Checked = Value;
_toggleButton.SetOnCheckedChangeListener(this);
if (TextOff != null)
{
_toggleButton.TextOff = TextOff;
if (!Value)
_toggleButton.Text = TextOff;
}
if (TextOn != null)
{
_toggleButton.TextOn = TextOn;
if (Value)
_toggleButton.Text = TextOn;
}
}
return view;
}
protected override void Dispose(bool disposing)
{
if (!disposing) return;
//_toggleButton.Dispose();
_toggleButton = null;
//_caption.Dispose();
_caption = null;
}
public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
{
Value = isChecked;
}
public override void Selected()
{
if (_toggleButton != null)
_toggleButton.Toggle();
}
}
}