{
/// <summary>
/// DateChangedEventArgs default constructor.
- /// <param name="month">month value of DatePicker.</param>
- /// <param name="day">day value of DatePicker.</param>
- /// <param name="year">year value of DatePicker.</param>
+ /// <param name="date">date value of DatePicker.</param>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public DateChangedEventArgs(int month, int day, int year)
+ public DateChangedEventArgs(DateTime date)
{
- Month = month;
- Day = day;
- Year = year;
+ Date = date;
}
/// <summary>
/// DateChangedEventArgs default constructor.
- /// <returns>The current month value of DatePicker.</returns>
+ /// <returns>The current date value of DatePicker.</returns>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public int Month { get; }
-
- /// <summary>
- /// DateChangedEventArgs default constructor.
- /// <returns>The current day value of DatePicker.</returns>
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int Day { get; }
-
- /// <summary>
- /// DateChangedEventArgs default constructor.
- /// <returns>The current year value of DatePicker.</returns>
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int Year { get; }
+ public DateTime Date { get; }
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class DatePicker : Control
{
- private int day;
- private int month;
- private int year;
+ private DateTime currentDate;
private Picker dayPicker;
private Picker monthPicker;
private Picker yearPicker;
public event EventHandler<DateChangedEventArgs> DateChanged;
/// <summary>
- /// The month value of DatePicker.
+ /// The Date value of DatePicker.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public int Month
+ public DateTime Date
{
get
{
- return month;
+ return currentDate;
}
set
{
- if (value < 1 || value > 12 || value == month) return;
-
- month = value;
- monthPicker.CurrentValue = month;
+ currentDate = value;
+ dayPicker.CurrentValue = currentDate.Day;
+ monthPicker.CurrentValue = currentDate.Month;
+ yearPicker.CurrentValue = currentDate.Year;
}
}
/// <summary>
- /// The day value of DatePicker.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int Day
- {
- get
- {
- return day;
- }
- set
- {
- if (value < 1 || value > 31 || value == day) return;
-
- day = value;
- dayPicker.CurrentValue = day;
- }
- }
-
- /// <summary>
- /// The year value of DatePicker.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int Year
- {
- get
- {
- return year;
- }
- set
- {
- if (value < 1970 || value > 2038 || value == year) return;
-
- year = value;
- yearPicker.CurrentValue = year;
- }
- }
-
- /// <summary>
/// Initialize TimePicker object.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
yearPicker = new Picker()
{
MinValue = 1970,
- MaxValue = 2038,
+ MaxValue = 2100,
};
yearPicker.ValueChanged += OnYearValueChanged;
- //FIXME: Changes it to get current system date.
- day = 1;
- month = 1;
- year = 1970;
+ currentDate = DateTime.Now;
+ dayPicker.CurrentValue = currentDate.Day;
+ monthPicker.CurrentValue = currentDate.Month;
+ yearPicker.CurrentValue = currentDate.Year;
}
[SuppressMessage("Microsoft.Reliability",
PickersOrderSet();
SetMonthText();
- MaxDaySet();
+ MaxDaySet(currentDate.Month);
}
private void OnDayValueChanged(object sender, ValueChangedEventArgs e)
{
- if (day == e.Value) return;
+ if (currentDate.Day == e.Value) return;
- day = e.Value;
+ currentDate = new DateTime(currentDate.Year, currentDate.Month, e.Value);
OnDateChanged();
}
private void OnMonthValueChanged(object sender, ValueChangedEventArgs e)
{
- if (Month == e.Value) return;
+ if (currentDate.Month == e.Value) return;
- Month = e.Value;
- MaxDaySet();
+ MaxDaySet(e.Value);
OnDateChanged();
}
private void OnYearValueChanged(object sender, ValueChangedEventArgs e)
{
- if (Year == e.Value) return;
+ if (currentDate.Year == e.Value) return;
- Year = e.Value;
+ currentDate = new DateTime(e.Value, currentDate.Month, currentDate.Day);
OnDateChanged();
}
private void OnDateChanged()
{
- DateChangedEventArgs eventArgs = new DateChangedEventArgs(day, month, year);
+ DateChangedEventArgs eventArgs = new DateChangedEventArgs(currentDate);
DateChanged?.Invoke(this, eventArgs);
}
- private void MaxDaySet()
+ private void MaxDaySet(int month)
{
- int maxDaysInMonth = DateTime.DaysInMonth(year, month);
+ int maxDaysInMonth = DateTime.DaysInMonth(currentDate.Year, month);
dayPicker.MaxValue = maxDaysInMonth;
- if (day > maxDaysInMonth)
+ if (currentDate.Day > maxDaysInMonth)
{
- day = maxDaysInMonth;
- dayPicker.CurrentValue = day;
+ currentDate = new DateTime(currentDate.Year, month, maxDaysInMonth);
+ dayPicker.CurrentValue = maxDaysInMonth;
+ return;
}
+ currentDate = new DateTime(currentDate.Year, month, currentDate.Day);
}
//FIXME: There is no way to know when system locale changed in NUI.
{
/// <summary>
/// TimeChangedEventArgs default constructor.
- /// <param name="hour">hour value of TimePicker.</param>
- /// <param name="minute">minute value of TimePicker.</param>
+ /// <param name="time">time value of TimePicker.</param>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public TimeChangedEventArgs(int hour, int minute)
+ public TimeChangedEventArgs(DateTime time)
{
- Hour = hour;
- Minute = minute;
+ Time = time;
}
/// <summary>
/// TimeChangedEventArgs default constructor.
- /// <returns>The current hour value of TimePicker.</returns>
+ /// <returns>The current time value of TimePicker.</returns>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public int Hour { get; }
-
- /// <summary>
- /// TimeChangedEventArgs default constructor.
- /// <returns>The current minute value of TimePicker.</returns>
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int Minute { get; }
+ public DateTime Time { get; }
}
/// <summary>
{
private bool isAm;
private bool is24HourView;
- private int hour;
- private int minute;
+ private DateTime currentTime;
private String[] ampmText;
private Picker hourPicker;
private Picker minutePicker;
/// The hour value of TimePicker.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public int Hour
+ public DateTime Time
{
get
{
- return hour;
+ return currentTime;
}
set
{
- if (value < 1 || value > 24 || value == hour) return;
-
- hour = value;
+ currentTime = value;
if (!is24HourView)
{
- if (hour >= 12 && hour <= 23)
+ if (currentTime.Hour >= 12 && currentTime.Hour <= 23)
{
isAm = false;
- if (hour == 12) hourPicker.CurrentValue = hour;
- else hourPicker.CurrentValue = hour -= 12;
+ if (currentTime.Hour == 12) hourPicker.CurrentValue = currentTime.Hour;
+ else hourPicker.CurrentValue = currentTime.Hour - 12;
ampmPicker.CurrentValue = 2;
}
else
{
isAm = true;
- hourPicker.CurrentValue = hour;
+ hourPicker.CurrentValue = currentTime.Hour;
ampmPicker.CurrentValue = 1;
}
}
- else hourPicker.CurrentValue = hour;
- }
- }
+ else hourPicker.CurrentValue = currentTime.Hour;
- /// <summary>
- /// The Minute value of TimePicker.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public int Minute
- {
- get
- {
- return minute;
- }
- set
- {
- if (value < 1 || value > 60 || value == minute) return;
-
- minute = value;
- minutePicker.CurrentValue = minute;
+ minutePicker.CurrentValue = currentTime.Minute;
}
}
{
if (is24HourView == value) return;
+ Console.WriteLine(" Is 24 Hour View");
is24HourView = value;
if (value == true)
{
Remove(ampmPicker);
- hourPicker.MaxValue = 24;
+ hourPicker.MinValue = 0;
+ hourPicker.MaxValue = 23;
+ hourPicker.CurrentValue = currentTime.Hour;
}
else
{
+ hourPicker.MinValue = 1;
hourPicker.MaxValue = 12;
PickersOrderSet(true);
SetAmpmText();
+ if (currentTime.Hour > 12)
+ {
+ ampmPicker.CurrentValue = 2;
+ hourPicker.CurrentValue = currentTime.Hour - 12;
+ }
}
}
}
hourPicker = new Picker()
{
MinValue = 1,
- MaxValue = 24,
+ MaxValue = 12,
};
hourPicker.ValueChanged += OnHourValueChanged;
MaxValue = 2,
};
ampmPicker.ValueChanged += OnAmpmValueChanged;
+
+ currentTime = DateTime.Now;
+ Console.WriteLine(" Time " + currentTime.Hour + " " + currentTime.Minute);
+ if (currentTime.Hour > 12)
+ {
+ ampmPicker.CurrentValue = 2;
+ hourPicker.CurrentValue = currentTime.Hour - 12;
+ }
+ else
+ hourPicker.CurrentValue = currentTime.Hour;
+
+ minutePicker.CurrentValue = currentTime.Minute;
}
/// <summary>
LinearOrientation = LinearLayout.Orientation.Horizontal,
CellPadding = new Size(timePickerStyle.CellPadding.Width, timePickerStyle.CellPadding.Height),
};
+ Console.WriteLine("initialize");
- is24HourView = true;
+ is24HourView = false;
PickersOrderSet(false);
+ SetAmpmText();
+ }
- if (!is24HourView)
- {
- SetAmpmText();
- hourPicker.MaxValue = 12;
- }
+ private void ChangeTime(int hour, int minute, bool hourUpdate)
+ {
+ if (hourUpdate)
+ currentTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, hour, currentTime.Minute, 0);
+ else
+ currentTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, minute, 0);
}
private void OnHourValueChanged(object sender, ValueChangedEventArgs e)
{
- if (hour == e.Value) return;
+ if (currentTime.Hour == e.Value) return;
if (!is24HourView)
{
if (isAm)
{
- if (e.Value == 12) hour = 24;
- else hour = e.Value;
+ if (e.Value == 12) ChangeTime(12, 0, true);
+ else ChangeTime(e.Value, 0, true);
}
else
{
- if (e.Value == 12) hour = 12;
- else hour = e.Value + 12;
+ if (e.Value == 12) ChangeTime(0, 0, true);
+ else ChangeTime(e.Value + 12, 0, true);
}
}
else
- hour = e.Value;
+ ChangeTime(e.Value, 0, true);
OnTimeChanged();
}
private void OnMinuteValueChanged(object sender, ValueChangedEventArgs e)
{
- if (minute == e.Value) return;
+ if (currentTime.Minute == e.Value) return;
- minute = e.Value;
+ ChangeTime(0, e.Value, false);
OnTimeChanged();
}
if (e.Value == 1)
{ //AM
- if (hour >= 12 || hour < 24)
+ if (currentTime.Hour > 12 || currentTime.Hour == 0)
{
- if (hour == 12) hour += 12;
- else hour -= 12;
+ if (currentTime.Hour == 0) ChangeTime(12, 0, true);
+ else ChangeTime(currentTime.Hour - 12, 0, true);
}
isAm = true;
}
else
{ //PM
- if (hour == 24 || hour < 12)
+ if (currentTime.Hour > 0 && currentTime.Hour <= 12)
{
- if (hour == 24) hour -= 12;
- else hour += 12;
+ if (currentTime.Hour == 12) ChangeTime(0, 0, true);
+ else ChangeTime(currentTime.Hour + 12, 0, true);
}
isAm = false;
}
private void OnTimeChanged()
{
- TimeChangedEventArgs eventArgs = new TimeChangedEventArgs(hour, minute);
+ TimeChangedEventArgs eventArgs = new TimeChangedEventArgs(currentTime);
TimeChanged?.Invoke(this, eventArgs);
}