Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
EntryElement.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.Text;
6 using Android.Util;
7 using Android.Views;
8 using Android.Widget;
9 using Android.App;
10 
11 namespace MonoDroid.Dialog
12 {
14  {
15  public string Value
16  {
17  get { return _val; }
18  set
19  {
20  _val = value;
21  if (_entry != null && _entry.Text != value)
22  {
23  _entry.Text = value;
24  if (ValueChanged != null)
25  ValueChanged(this, EventArgs.Empty);
26  }
27  }
28  }
29 
30  public event EventHandler ValueChanged;
31 
32  public EntryElement(string caption, string value)
33  : this(caption, value, (int)DroidResources.ElementLayout.dialog_textfieldright)
34  {
35 
36  }
37 
38  public EntryElement(string caption, string hint,string value) : this(caption,value)
39  {
40  Hint = hint;
41  }
42 
43  public EntryElement(string caption, string @value, int layoutId)
44  : base(caption, layoutId)
45  {
46  _val = @value;
47  Lines = 1;
48  }
49 
50  public override string Summary()
51  {
52  return _val;
53  }
54 
55  public bool Password { get; set; }
56  public bool Numeric { get; set; }
57  public string Hint { get; set; }
58  public int Lines { get; set; }
59 
60  protected EditText _entry;
61  private string _val;
62  protected Action _entryClicked { get;set; }
63 
64 
65  public override View GetView(Context context, View convertView, ViewGroup parent)
66  {
67  Log.Debug("MDD", "EntryElement: GetView: ConvertView: " + ((convertView == null) ? "false" : "true") +
68  " Value: " + Value + " Hint: " + Hint + " Password: " + (Password ? "true" : "false"));
69 
70 
71  TextView label;
72  var view = DroidResources.LoadStringEntryLayout(context, convertView, parent, LayoutId, out label, out _entry);
73  if (view != null)
74  {
75  // Warning! Crazy ass hack ahead!
76  // since we can't know when out convertedView was was swapped from inside us, we store the
77  // old textwatcher in the tag element so it can be removed!!!! (barf, rech, yucky!)
78  if (_entry.Tag != null)
79  _entry.RemoveTextChangedListener((ITextWatcher)_entry.Tag);
80 
81  _entry.Text = this.Value;
82  _entry.Hint = this.Hint;
83 
84  if (this.Password)
85  _entry.InputType = (InputTypes.ClassText | InputTypes.TextVariationPassword);
86  else if (this.Numeric)
87  _entry.InputType = (InputTypes.ClassNumber | InputTypes.NumberFlagDecimal | InputTypes.NumberFlagSigned);
88  else
89  _entry.InputType = InputTypes.ClassText;
90 
91  // continuation of crazy ass hack, stash away the listener value so we can look it up later
92  _entry.Tag = this;
93  _entry.AddTextChangedListener(this);
94 
95  label.Text = (label != null) ? Caption: string.Empty;
96  }
97  return view;
98  }
99 
100  protected override void Dispose(bool disposing)
101  {
102  if (disposing)
103  {
104  //_entry.Dispose();
105  _entry = null;
106  }
107  }
108 
109  public override bool Matches(string text)
110  {
111  return (Value != null ? Value.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 : false) || base.Matches(text);
112  }
113 
114  public void OnTextChanged(Java.Lang.ICharSequence s, int start, int before, int count)
115  {
116  this.Value = s.ToString();
117  }
118 
119  public void AfterTextChanged(IEditable s)
120  {
121  Console.Write("foo");
122  // nothing needed
123  }
124 
125  public void BeforeTextChanged(Java.Lang.ICharSequence s, int start, int count, int after)
126  {
127  Console.Write("foo");
128  // nothing needed
129  }
130 
131  public override void Selected ()
132  {
133  base.Selected ();
134 
135  if(_entry != null) {
136  var context = this.GetContext();
137  var entryDialog = new AlertDialog.Builder(context)
138  .SetTitle("Enter Text")
139  .SetView(_entry)
140  .SetPositiveButton("OK", (o, e) => {
141  this.Value = _entry.Text;
142  })
143  .Create();
144 
145  entryDialog.Show();
146  }
147  }
148  }
149 }
EventHandler ValueChanged
Definition: EntryElement.cs:30
EditText _entry
Definition: EntryElement.cs:60
EntryElement(string caption, string value)
Definition: EntryElement.cs:32
_In_ size_t count
Definition: DirectXTexP.h:174
override void Dispose(bool disposing)
Definition: EntryElement.cs:13
EntryElement(string caption, string hint, string value)
Definition: EntryElement.cs:38
EntryElement(string caption, string @value, int layoutId)
Definition: EntryElement.cs:43
void BeforeTextChanged(Java.Lang.ICharSequence s, int start, int count, int after)
function s(a)
override void Selected()
override string Summary()
Returns a summary of the value represented by this object, suitable for rendering as the result of a ...
Definition: EntryElement.cs:50
override bool Matches(string text)
void AfterTextChanged(IEditable s)
void OnTextChanged(Java.Lang.ICharSequence s, int start, int before, int count)
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 ...
Definition: EntryElement.cs:65