4 using System.Collections;
5 using System.Collections.Generic;
11 namespace MonoDroid.Dialog
18 int _summarySection, _summaryElement;
19 internal Group _group;
33 Sections =
new List<Section>();
44 public RootElement(
string caption, Func<RootElement, View> createOnSelected)
48 this._createOnSelected = createOnSelected;
49 Sections =
new List<Section>();
67 _summarySection = section;
68 _summaryElement = element;
90 public Context Context {
get; set; }
92 internal List<Section> Sections =
new List<Section>();
98 return Sections.Count;
106 return Sections[idx];
110 internal int IndexOf(
Section target)
122 internal void Prepare()
125 foreach (Section s
in Sections)
127 foreach (Element e
in s.Elements)
129 var re = e as RadioElement;
131 re.RadioIdx = current++;
132 if (UnevenRows ==
false && e is IElementSizing)
140 return GetSelectedValue();
143 void SetSectionStartIndex()
145 int currentIndex = 0;
146 foreach(var section
in Sections)
148 section.StartIndex = currentIndex;
149 currentIndex += section.Count;
163 Sections.Add(section);
164 section.Parent =
this;
165 SetSectionStartIndex();
177 foreach (var s
in sections)
180 SetSectionStartIndex();
198 if (idx < 0 || idx > Sections.Count)
200 if (newSections == null)
207 foreach (var s
in newSections)
210 Sections.Insert(pos++,
s);
213 SetSectionStartIndex();
221 if (idx < 0 || idx >= Sections.Count)
224 Sections.RemoveAt(idx);
226 SetSectionStartIndex();
233 int idx = Sections.IndexOf(
s);
238 SetSectionStartIndex();
243 foreach (var s
in Sections)
245 Sections =
new List<Section>();
248 protected override void Dispose(
bool disposing)
253 if (Sections == null)
263 public int RadioSelected
269 return radio.Selected;
276 radio.Selected = value;
280 private string GetSelectedValue()
286 int selected = radio.Selected;
288 string radioValue = string.Empty;
289 foreach (var s
in Sections)
291 foreach (var e
in s.Elements)
296 if (current == selected)
306 public override View
GetView(Context context, View convertView, ViewGroup parent)
310 LayoutInflater inflater = LayoutInflater.FromContext(context);
312 View cell =
new TextView(context) {TextSize = 16f, Text = Caption};
313 var radio = _group as RadioGroup;
317 string radioValue = GetSelectedValue();
318 cell = DroidResources.LoadStringElementLayout(context, convertView, parent, LayoutId, out _caption, out _value);
321 _caption.Text = Caption;
322 _value.Text = radioValue;
324 this.Click += delegate { SelectRadio(); };
327 else if (_group != null)
330 foreach (var s
in Sections)
332 foreach (var e
in s.Elements)
352 else if (_summarySection != -1 && _summarySection < Sections.Count)
354 var s = Sections[_summarySection];
366 List<string> items =
new List<string>();
367 foreach (var s
in Sections)
369 foreach (var e
in s.Elements)
372 items.Add(e.Summary());
376 var dialog =
new AlertDialog.Builder(Context);
377 dialog.SetSingleChoiceItems(items.ToArray(), this.RadioSelected,
this);
378 dialog.SetTitle(this.Caption);
379 dialog.SetNegativeButton(
"Cancel",
this);
380 dialog.Create().Show();
383 void IDialogInterfaceOnClickListener.OnClick(IDialogInterface dialog,
int which)
387 this.RadioSelected = which;
388 string radioValue = GetSelectedValue();
389 _value.Text = radioValue;
403 return Sections.GetEnumerator();
409 IEnumerator IEnumerable.GetEnumerator()
411 return Sections.GetEnumerator();
void Add(Section section)
Adds a new section to this RootElement
Func< RootElement, View > _createOnSelected
void Add(IEnumerable< Section > sections)
void Insert(int idx, params Section[] newSections)
Inserts a new section into the RootElement
RootElement(string caption, Func< RootElement, View > createOnSelected)
Initializes a RootSection with a caption and a callback that will create the nested UIViewController ...
RootElement(string caption, int section, int element)
Initializes a RootElement with a caption with a summary fetched from the specified section and leemen...
IEnumerator< Section > GetEnumerator()
Enumerator that returns all the sections in the RootElement.
override void Dispose(bool disposing)
Sections contain individual Element instances that are rendered by MonoDroid.Dialog ...
void RemoveAt(int idx)
Removes a section at a specified location
RootElement(string caption)
Initializes a RootSection with a caption
RootElement(string caption, Group group)
Initializes a RootElement that renders the summary based on the radio settings of the contained eleme...
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 ...
Used by root elements to fetch information when they need to render a summary (Checkbox count or sele...
override string Summary()
Returns a summary of the value represented by this object, suitable for rendering as the result of a ...
Captures the information about mutually exclusive elements in a RootElement