Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Element.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 
7 namespace MonoDroid.Dialog
8 {
9  public abstract class Element : Java.Lang.Object, IDisposable
10  {
11  /// <summary>
12  /// Initializes the element with the given caption.
13  /// </summary>
14  /// <param name="caption">
15  /// The caption.
16  /// </param>
17  public Element(string caption)
18  {
19  Caption = caption;
20  }
21 
22  public Element(string caption, int layoutId)
23  {
24  Caption = caption;
25  LayoutId = layoutId;
26  }
27 
28  /// <summary>
29  /// The caption to display for this given element
30  /// </summary>
31  public string Caption { get; set; }
32 
33  public int LayoutId { get; private set; }
34 
35  /// For sections this points to a RootElement, for every other object this points to a Section and it is null
36  /// for the root RootElement.
37  /// </remarks>
38  public Element Parent { get; set; }
39 
40  /// <summary>
41  /// Override for click the click event
42  /// </summary>
43  public Action Click { get; set; }
44 
45  /// <summary>
46  /// Override for long click events, some elements use this for action
47  /// </summary>
48  public Action LongClick { get; set; }
49 
50  /// <summary>
51  /// An Object that contains data about the element. The default is null.
52  /// </summary>
53  public Object Tag { get; set; }
54 
55  public void Dispose()
56  {
57  Dispose(true);
58  }
59 
60  protected virtual void Dispose(bool disposing) { }
61 
62  /// <summary>
63  /// Returns a summary of the value represented by this object, suitable
64  /// for rendering as the result of a RootElement with child objects.
65  /// </summary>
66  /// <returns>
67  /// The return value must be a short description of the value.
68  /// </returns>
69  public virtual string Summary()
70  {
71  return string.Empty;
72  }
73 
74  /// <summary>
75  /// Overriden my most derived classes, creates a view that creates a View with the contents for display
76  /// </summary>
77  /// <param name="context"></param>
78  /// <param name="convertView"></param>
79  /// <param name="parent"></param>
80  /// <returns></returns>
81  public virtual View GetView(Context context, View convertView, ViewGroup parent)
82  {
83  var view = LayoutId == 0 ? new View(context) : null;
84  return view;
85  }
86 
87  public virtual void Selected() {}
88 
89  public virtual bool Matches(string text)
90  {
91  return Caption != null && Caption.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1;
92  }
93 
94  public Context GetContext()
95  {
96  Element element = this;
97  while (element.Parent != null)
98  element = element.Parent;
99 
100  RootElement rootElement = element as RootElement;
101  return rootElement == null ? null : rootElement.Context;
102  }
103  }
104 }
virtual bool Matches(string text)
Definition: Element.cs:89
virtual void Dispose(bool disposing)
Definition: Element.cs:60
Element(string caption, int layoutId)
Definition: Element.cs:22
virtual string Summary()
Returns a summary of the value represented by this object, suitable for rendering as the result of a ...
Definition: Element.cs:69
Context GetContext()
Definition: Element.cs:94
virtual void Selected()
Definition: Element.cs:87
virtual 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: Element.cs:81
Element(string caption)
Initializes the element with the given caption.
Definition: Element.cs:17