Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DialogAdapter.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 Android.Content;
4 using Android.Views;
5 using Android.Widget;
6 
7 namespace MonoDroid.Dialog
8 {
9  public class DialogAdapter : BaseAdapter<Section>
10  {
11  const int TYPE_SECTION_HEADER = 0;
12  Context context;
13  LayoutInflater inflater;
14 
15  public DialogAdapter (Context context, RootElement root)
16  {
17  this.context = context;
18  this.inflater = LayoutInflater.From (context);
19  this.Root = root;
20  }
21 
22  public RootElement Root { get; set; }
23 
24  public override bool IsEnabled (int position)
25  {
26  // start counting from here
27  int typeOffset = TYPE_SECTION_HEADER + 1;
28 
29  foreach (var s in Root.Sections) {
30  if (position == 0)
31  return false;
32 
33  int size = s.Adapter.Count + 1;
34 
35  if (position < size)
36  return true;
37 
38  position -= size;
39  typeOffset += s.Adapter.ViewTypeCount;
40  }
41 
42  return false;
43  }
44 
45  public override int Count {
46  get {
47  int count = 0;
48 
49  //Get each adapter's count + 1 for the header
50  foreach (var s in Root.Sections) {
51  count += s.Adapter.Count + 1;
52  }
53 
54  return count;
55  }
56  }
57 
58  public override int ViewTypeCount {
59  get {
60  return this.Count;
61  }
62  }
63 
64  public Element ElementAtIndex (int position)
65  {
66  int sectionIndex = 0;
67  foreach (var s in Root.Sections) {
68  if (position == 0) {
69  return this.Root.Sections [sectionIndex];
70  }
71  // note: plus one for the section header view
72  int size = s.Adapter.Count + 1;
73  if (position < size) {
74  return this.Root.Sections [sectionIndex].Elements [position - 1];
75  }
76  position -= size;
77  sectionIndex++;
78  }
79 
80  return null;
81  }
82 
83  public override Section this [int position] {
84  get { return this.Root.Sections [position]; }
85  }
86 
87  public override bool AreAllItemsEnabled ()
88  {
89  return false;
90  }
91 
92  public override int GetItemViewType (int position)
93  {
94  // start counting from here
95  int typeOffset = TYPE_SECTION_HEADER + 1;
96 
97  foreach (var s in Root.Sections) {
98  if (position == 0)
99  return (TYPE_SECTION_HEADER);
100 
101  int size = s.Adapter.Count + 1;
102 
103  if (position < size)
104  return (typeOffset + s.Adapter.GetItemViewType (position - 1));
105 
106  position -= size;
107  typeOffset += s.Adapter.ViewTypeCount;
108  }
109 
110  return -1;
111  }
112 
113  public override long GetItemId (int position)
114  {
115  return position;
116  }
117 
118  public override View GetView (int position, View convertView, ViewGroup parent)
119  {
120  int sectionIndex = 0;
121 
122  foreach (var s in Root.Sections) {
123  if (s.Adapter.Context == null)
124  s.Adapter.Context = this.context;
125 
126  if (position == 0)
127  return s.GetView (context, convertView, parent);
128 
129  int size = s.Adapter.Count + 1;
130 
131  if (position < size)
132  return (s.Adapter.GetView (position - 1, convertView, parent));
133 
134  position -= size;
135  sectionIndex++;
136  }
137 
138  return null;
139  }
140 
141  public void ReloadData ()
142  {
143  if (Root != null) {
144  this.NotifyDataSetChanged ();
145  }
146  }
147  }
148 }
override int GetItemViewType(int position)
override long GetItemId(int position)
Element ElementAtIndex(int position)
override bool IsEnabled(int position)
_In_ size_t count
Definition: DirectXTexP.h:174
override View GetView(int position, View convertView, ViewGroup parent)
function s(a)
DialogAdapter(Context context, RootElement root)
override bool AreAllItemsEnabled()
Sections contain individual Element instances that are rendered by MonoDroid.Dialog ...
Definition: Section.cs:28
_In_ size_t _In_ size_t size
Definition: DirectXTexP.h:175