Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DateTimeElement.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.App;
5 using Android.Content;
6 
7 namespace MonoDroid.Dialog
8 {
10  {
11  public DateTime DateValue
12  {
13  get { return DateTime.Parse(Value); }
14  set { Value = Format(value); }
15  }
16 
17  public DateTimeElement(string caption, DateTime date)
18  : base(caption)
19  {
20  DateValue = date;
21  }
22 
23  public DateTimeElement(string caption, DateTime date, int layoutId)
24  : base(caption, layoutId)
25  {
26  DateValue = date;
27  }
28 
29  public virtual string Format(DateTime dt)
30  {
31  return dt.ToShortDateString() + " " + dt.ToShortTimeString();
32  }
33  }
34 
36  {
37  public DateElement(string caption, DateTime date)
38  : base(caption, date)
39  {
40  this.Click = delegate { EditDate(); };
41  }
42 
43  public DateElement(string caption, DateTime date, int layoutId)
44  : base(caption, date, layoutId)
45  {
46  this.Click = delegate { EditDate(); };
47  }
48 
49  public override string Format(DateTime dt)
50  {
51  return dt.ToShortDateString();
52  }
53 
54  // the event received when the user "sets" the date in the dialog
55  void OnDateSet(object sender, DatePickerDialog.DateSetEventArgs e)
56  {
57  DateTime current = DateValue;
58  DateValue = new DateTime(e.Date.Year, e.Date.Month, e.Date.Day, current.Hour, current.Minute, 0);
59  }
60 
61  private void EditDate()
62  {
63  Context context = GetContext();
64  if (context == null)
65  {
66  Android.Util.Log.Warn("DateElement", "No Context for Edit");
67  return;
68  }
69  DateTime val = DateValue;
70  new DatePickerDialog(context, OnDateSet, val.Year, val.Month - 1, val.Day).Show();
71  }
72  }
73 
75  {
76  public TimeElement(string caption, DateTime date)
77  : base(caption, date)
78  {
79  this.Click = delegate { EditDate(); };
80  }
81 
82  public TimeElement(string caption, DateTime date, int layoutId)
83  : base(caption, date, layoutId)
84  {
85  this.Click = delegate { EditDate(); };
86  }
87 
88  public override string Format(DateTime dt)
89  {
90  return dt.ToShortTimeString();
91  }
92 
93  // the event received when the user "sets" the date in the dialog
94  void OnDateSet(object sender, TimePickerDialog.TimeSetEventArgs e)
95  {
96  DateTime current = DateValue;
97  DateValue = new DateTime(current.Year, current.Month, current.Day, e.HourOfDay, e.Minute, 0);
98  }
99 
100  private void EditDate()
101  {
102  Context context = GetContext();
103  if (context == null)
104  {
105  Android.Util.Log.Warn("TimeElement", "No Context for Edit");
106  return;
107  }
108  DateTime val = DateValue;
109  // TODO: get the current time setting for thge 24 hour clock
110  new TimePickerDialog(context, OnDateSet, val.Hour, val.Minute, false).Show();
111  }
112  }
113 }
DateElement(string caption, DateTime date)
override string Format(DateTime dt)
TimeElement(string caption, DateTime date, int layoutId)
DateTimeElement(string caption, DateTime date)
virtual string Format(DateTime dt)
DateTimeElement(string caption, DateTime date, int layoutId)
override string Format(DateTime dt)
TimeElement(string caption, DateTime date)
DateElement(string caption, DateTime date, int layoutId)