Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
BooleanElement.cs
Go to the documentation of this file.
1 using System;
2 using Android.Content;
3 using Android.Views;
4 using Android.Widget;
5 
6 namespace MonoDroid.Dialog
7 {
8  public abstract class BoolElement : Element
9  {
10  private bool _val;
11 
12  public bool Value
13  {
14  get { return _val; }
15  set
16  {
17  if (_val != value)
18  {
19  _val = value;
20  if (ValueChanged != null)
21  ValueChanged(this, EventArgs.Empty);
22  }
23  }
24  }
25 
26  public event EventHandler ValueChanged;
27 
28  public BoolElement(string caption, bool value) : base(caption)
29  {
30  _val = value;
31  }
32 
33  public BoolElement(string caption, bool value, int layoutId)
34  : base(caption, layoutId)
35  {
36  _val = value;
37  }
38 
39  public override string Summary()
40  {
41  return _val ? "On" : "Off";
42  }
43  }
44 
45  /// <summary>
46  /// Used to display toggle button on the screen.
47  /// </summary>
48  public class BooleanElement : BoolElement, CompoundButton.IOnCheckedChangeListener
49  {
50  private ToggleButton _toggleButton;
51  private TextView _caption;
52  private TextView _subCaption;
53 
54  public BooleanElement(string caption, bool value)
55  : base(caption, value, (int) DroidResources.ElementLayout.dialog_onofffieldright)
56  {
57  }
58 
59  public BooleanElement(string caption, bool value, int layoutId)
60  : base(caption, value, layoutId)
61  {
62  }
63 
64  public override View GetView(Context context, View convertView, ViewGroup parent)
65  {
66  View toggleButtonView;
67  View view = DroidResources.LoadBooleanElementLayout(context, convertView, parent, LayoutId, out _caption, out _subCaption, out toggleButtonView);
68 
69  if (view != null)
70  {
71  _caption.Text = Caption;
72  _toggleButton = toggleButtonView as ToggleButton;
73  _toggleButton.SetOnCheckedChangeListener(null);
74  _toggleButton.Checked = Value;
75  _toggleButton.SetOnCheckedChangeListener(this);
76  }
77  return view;
78  }
79 
80  protected override void Dispose(bool disposing)
81  {
82  if (disposing)
83  {
84  //_toggleButton.Dispose();
85  _toggleButton = null;
86  //_caption.Dispose();
87  _caption = null;
88  }
89  }
90 
91  public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
92  {
93  this.Value = isChecked;
94  }
95  }
96 }
override void Dispose(bool disposing)
Used to display toggle button on the screen.
BooleanElement(string caption, bool value)
override string Summary()
Returns a summary of the value represented by this object, suitable for rendering as the result of a ...
void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
override View GetView(Context context, View convertView, ViewGroup parent)
Overriden my most derived classes, creates a view that creates a View with the contents for display ...
BoolElement(string caption, bool value)
BoolElement(string caption, bool value, int layoutId)
BooleanElement(string caption, bool value, int layoutId)