Add CalendarView 16/115916/8
authorSeunghyun Choi <sh4682.choi@samsung.com>
Wed, 22 Feb 2017 05:10:16 +0000 (14:10 +0900)
committerSeunghyun Choi <sh4682.choi@samsung.com>
Thu, 23 Mar 2017 03:33:14 +0000 (12:33 +0900)
 - RFC : http://suprem.sec.samsung.net/confluence/display/SPTDTLC/%5BFormsTizen%5D+RFC+11+-+CalendarView

Change-Id: I35e33cc6f32dd4d68642b5eaecd1293ea02ede4d
Signed-off-by: Seunghyun Choi <sh4682.choi@samsung.com>
Tizen.Xamarin.Forms.Extension.Renderer/CalendarViewRenderer.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj
Tizen.Xamarin.Forms.Extension/CalendarView.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj

diff --git a/Tizen.Xamarin.Forms.Extension.Renderer/CalendarViewRenderer.cs b/Tizen.Xamarin.Forms.Extension.Renderer/CalendarViewRenderer.cs
new file mode 100644 (file)
index 0000000..614f4b1
--- /dev/null
@@ -0,0 +1,74 @@
+using Xamarin.Forms;
+using Xamarin.Forms.Platform.Tizen;
+using TForms = Xamarin.Forms.Platform.Tizen.Forms;
+using ECalendar = ElmSharp.Calendar;
+using Tizen.Xamarin.Forms.Extension;
+using Tizen.Xamarin.Forms.Extension.Renderer;
+
+[assembly: ExportRenderer(typeof(CalendarView), typeof(CalendarViewRenderer))]
+
+namespace Tizen.Xamarin.Forms.Extension.Renderer
+{
+    public class CalendarViewRenderer : ViewRenderer<CalendarView, ECalendar>
+    {
+        public CalendarViewRenderer()
+        {
+            RegisterPropertyHandler(CalendarView.MinimumDateProperty, UpdateMinimumDate);
+            RegisterPropertyHandler(CalendarView.MaximumDateProperty, UpdateMaximumDate);
+            RegisterPropertyHandler(CalendarView.FirstDayOfWeekProperty, UpdateFirstDayOfWeek);
+            RegisterPropertyHandler(CalendarView.WeekDayNamesProperty, UpdateWeekDayNames);
+            RegisterPropertyHandler(CalendarView.SelectedDateProperty, UpdateSelectedDate);
+        }
+
+        protected override void OnElementChanged(ElementChangedEventArgs<CalendarView> e)
+        {
+            if (Control == null)
+            {
+                var calrendarView = new ECalendar(TForms.Context.MainWindow);
+                SetNativeControl(calrendarView);
+            }
+
+            if (e.OldElement != null)
+            {
+                Control.DateChanged -= DateChangedHandler;
+            }
+
+            if (e.NewElement != null)
+            {
+                Control.DateChanged += DateChangedHandler;
+            }
+
+            base.OnElementChanged(e);
+        }
+
+        void DateChangedHandler(object sender, ElmSharp.DateChangedEventArgs e)
+        {
+            ((IElementController)Element).SetValueFromRenderer(CalendarView.SelectedDateProperty, e.NewDate);
+        }
+
+        void UpdateMinimumDate()
+        {
+            Control.MinimumYear = Element.MinimumDate.Year;
+        }
+
+        void UpdateMaximumDate()
+        {
+            Control.MaximumYear = Element.MaximumDate.Year;
+        }
+
+        void UpdateFirstDayOfWeek()
+        {
+            Control.FirstDayOfWeek = Element.FirstDayOfWeek;
+        }
+
+        void UpdateWeekDayNames()
+        {
+            Control.WeekDayNames = Element.WeekDayNames;
+        }
+
+        void UpdateSelectedDate()
+        {
+            Control.SelectedDate = Element.SelectedDate;
+        }
+    }
+}
\ No newline at end of file
index 49f809b..af02ca8 100644 (file)
@@ -39,6 +39,7 @@
     <Compile Include="ColorPickerViewRenderer.cs" />\r
     <Compile Include="MediaViewRenderer.cs" />\r
     <Compile Include="BackgroundRenderer.cs" />\r
+    <Compile Include="CalendarViewRenderer.cs" />\r
     <Compile Include="Cells\DoubleLabelCellRenderer.cs" />\r
     <Compile Include="Cells\GridViewCellRenderer.cs" />\r
     <Compile Include="Cells\GridViewTypeCellRenderer.cs" />\r
@@ -79,4 +80,4 @@
     <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>\r
     <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>\r
   </PropertyGroup>\r
-</Project>
+</Project>\r
diff --git a/Tizen.Xamarin.Forms.Extension/CalendarView.cs b/Tizen.Xamarin.Forms.Extension/CalendarView.cs
new file mode 100644 (file)
index 0000000..3935162
--- /dev/null
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using Xamarin.Forms;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+    /// <summary>
+    /// This is a calendar widget. It helps applications to flexibly display a calendar with day of the week, date, year and month.
+    /// </summary>
+    /// <example>
+    /// <code>
+    /// new CalendarView
+    /// {
+    ///     FirstDayOfWeek = DayOfWeek.Monday,
+    ///     MinimumDate = DateTime.MinValue,
+    ///     MaximumDate = DateTime.MaxValue
+    /// }
+    /// </code>
+    /// </example>
+    public class CalendarView : View
+    {
+        public static readonly BindableProperty MinimumDateProperty = BindableProperty.Create(nameof(MinimumDate), typeof(DateTime), typeof(CalendarView), DateTime.MinValue);
+
+        public static readonly BindableProperty MaximumDateProperty = BindableProperty.Create(nameof(MaximumDate), typeof(DateTime), typeof(CalendarView), DateTime.MaxValue);
+
+        public static readonly BindableProperty FirstDayOfWeekProperty = BindableProperty.Create(nameof(FirstDayOfWeek), typeof(DayOfWeek), typeof(CalendarView), DayOfWeek.Sunday);
+
+        public static readonly BindableProperty WeekDayNamesProperty = BindableProperty.Create(nameof(WeekDayNames), typeof(IReadOnlyList<string>), typeof(CalendarView), new List<string> { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, validateValue: (bindable, value) =>
+        {
+            List<string> weekDayNames = (List<string>)value;
+            int count = weekDayNames.Count;
+
+            return (count == 7);
+        });
+
+        public static readonly BindableProperty SelectedDateProperty = BindableProperty.Create(nameof(SelectedDate), typeof(DateTime), typeof(CalendarView), DateTime.Today, defaultBindingMode: BindingMode.TwoWay, propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            ((CalendarView)bindable).SelectedDateChanged?.Invoke(bindable, new DateChangedEventArgs((DateTime)oldValue, (DateTime)newValue));
+        });
+
+        public event EventHandler<DateChangedEventArgs> SelectedDateChanged;
+
+        /// <summary>
+        /// Gets or sets the MinimumDate value.
+        /// Can use only Year.
+        /// </summary>
+        public DateTime MinimumDate
+        {
+            get { return (DateTime)GetValue(MinimumDateProperty); }
+            set { SetValue(MinimumDateProperty, value); }
+        }
+
+        /// <summary>
+        /// Gets or sets the MaximumDate value.
+        /// Can use only Year.
+        /// </summary>
+        public DateTime MaximumDate
+        {
+            get { return (DateTime)GetValue(MaximumDateProperty); }
+            set { SetValue(MaximumDateProperty, value); }
+        }
+
+        /// <summary>
+        /// Gets or sets the first day of week.
+        /// </summary>
+        public DayOfWeek FirstDayOfWeek
+        {
+            get { return (DayOfWeek)GetValue(FirstDayOfWeekProperty); }
+            set { SetValue(FirstDayOfWeekProperty, value); }
+        }
+
+        /// <summary>
+        /// Gets or sets the weekday names displayed by the calendar.
+        /// The number of items in WeekdayNames must be 7.
+        /// </summary>
+        public IReadOnlyList<string> WeekDayNames
+        {
+            get { return (IReadOnlyList<string>)GetValue(WeekDayNamesProperty); }
+            set { SetValue(WeekDayNamesProperty, value); }
+        }
+
+        /// <summary>
+        /// Gets or sets the selected date.
+        /// </summary>
+        public DateTime SelectedDate
+        {
+            get { return (DateTime)GetValue(SelectedDateProperty); }
+            set { SetValue(SelectedDateProperty, value); }
+        }
+    }
+}
\ No newline at end of file
index 6f0b282..973f90b 100644 (file)
@@ -59,6 +59,7 @@
     <Compile Include="MediaView.cs" />\r
     <Compile Include="Background.cs" />\r
     <Compile Include="BackgroundOptions.cs" />\r
+    <Compile Include="CalendarView.cs" />\r
     <Compile Include="Cells\GridViewCell.cs" />\r
     <Compile Include="Cells\Type1Cell.cs" />\r
     <Compile Include="Cells\DoubleLabelCell.cs" />\r