Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CheckboxElement.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using Android.Content;
5 using Android.Views;
6 using Android.Widget;
7 
8 namespace MonoDroid.Dialog
9 {
10  public class CheckboxElement : Element, CompoundButton.IOnCheckedChangeListener
11  {
12  public bool Value
13  {
14  get { return _val; }
15  set
16  {
17  bool emit = _val != value;
18  _val = value;
19  if(_checkbox != null && _checkbox.Checked != _val)
20  _checkbox.Checked = _val;
21  else if (emit && ValueChanged != null)
22  ValueChanged(this, EventArgs.Empty);
23  }
24  }
25  private bool _val;
26 
27  public string SubCaption
28  {
29  get
30  {
31  return subCap;
32  }
33  set
34  {
35  subCap = value;
36  }
37  }
38  private string subCap;
39 
40  public bool ReadOnly
41  {
42  get;
43  set;
44  }
45 
46  public event EventHandler ValueChanged;
47 
48  private CheckBox _checkbox;
49  private TextView _caption;
50  private TextView _subCaption;
51 
52  public string Group;
53 
54  public CheckboxElement(string caption)
55  : base(caption, (int)DroidResources.ElementLayout.dialog_boolfieldright)
56  {
57  Value = false;
58  }
59 
60  public CheckboxElement(string caption, bool value)
61  : base(caption, (int)DroidResources.ElementLayout.dialog_boolfieldright)
62  {
63  Value = value;
64  }
65 
66  public CheckboxElement(string caption, bool value, string subCaption, string group)
67  : base(caption, (int)DroidResources.ElementLayout.dialog_boolfieldsubright)
68  {
69  Value = value;
70  Group = group;
71  SubCaption = subCaption;
72  }
73 
74  public CheckboxElement(string caption, bool value, string group)
75  : base(caption, (int)DroidResources.ElementLayout.dialog_boolfieldright)
76  {
77  Value = value;
78  Group = group;
79  }
80 
81  public CheckboxElement(string caption, bool value, string group, int layoutId)
82  : base(caption, layoutId)
83  {
84  Value = value;
85  Group = group;
86  }
87 
88  public override View GetView(Context context, View convertView, ViewGroup parent)
89  {
90  View checkboxView;
91  View view = DroidResources.LoadBooleanElementLayout(context, convertView, parent, LayoutId, out _caption, out _subCaption, out checkboxView);
92  if (view != null)
93  {
94  _caption.Text = Caption;
95 
96  _checkbox = checkboxView as CheckBox;
97  _checkbox.SetOnCheckedChangeListener(this);
98  _checkbox.Checked = Value;
99  _checkbox.Clickable = !ReadOnly;
100 
101  if (_subCaption != null)
102  _subCaption.Text = SubCaption;
103  }
104  return view;
105  }
106 
107  public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
108  {
109  this.Value = isChecked;
110  }
111  }
112 }
CheckboxElement(string caption, bool value)
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 ...
CheckboxElement(string caption, bool value, string group, int layoutId)
Used by root elements to fetch information when they need to render a summary (Checkbox count or sele...
Definition: Group.cs:9
CheckboxElement(string caption, bool value, string group)
CheckboxElement(string caption, bool value, string subCaption, string group)