Skip to content

Commit

Permalink
Update CircleStepperRenderer and CircleDateTimeSelectorRenderer (Sams…
Browse files Browse the repository at this point in the history
  • Loading branch information
shyunMin authored and rookiejava committed May 17, 2020
1 parent fd5f02e commit 5123b95
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using Xamarin.Forms.Platform.Tizen.Native;
using Xamarin.Forms.Platform.Tizen.Native.Watch;
using XForms = Xamarin.Forms.Forms;
using ECircleDateTimeSelector = ElmSharp.Wearable.CircleDateTimeSelector;
using EDateTimeFieldType = ElmSharp.DateTimeFieldType;

[assembly: ExportRenderer(typeof(Tizen.Wearable.CircularUI.Forms.CircleDateTimeSelector), typeof(Tizen.Wearable.CircularUI.Forms.Renderer.CircleDateTimeSelectorRenderer))]

[assembly: ExportRenderer(typeof(Tizen.Wearable.CircularUI.Forms.CircleDateTimeSelector), typeof(Tizen.Wearable.CircularUI.Forms.Renderer.CircleDateTimeSelectorRenderer))]

namespace Tizen.Wearable.CircularUI.Forms.Renderer
{
public class CircleDateTimeSelectorRenderer : ViewRenderer<CircleDateTimeSelector, ECircleDateTimeSelector>
public class CircleDateTimeSelectorRenderer : ViewRenderer<CircleDateTimeSelector, WatchDateTimePicker>
{
public CircleDateTimeSelectorRenderer()
{
Expand All @@ -53,7 +54,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<CircleDateTimeS
var surface = this.GetSurface();
if (null != surface)
{
SetNativeControl(new ECircleDateTimeSelector(XForms.NativeParent, surface));
SetNativeControl(new WatchDateTimePicker(XForms.NativeParent, surface));
Control.DateTimeChanged += OnDateTimeChanged;
}
}
Expand All @@ -72,49 +73,31 @@ protected override ElmSharp.Size Measure(int availableWidth, int availableHeight

void UpdateMinimum()
{
if (null != Control && null != Element)
{
Control.MinimumDateTime = Element.MinimumDate;
}
Control.MinimumDateTime = Element.MinimumDate;
}

void UpdateMaximum()
{
if (null != Control && null != Element)
{
Control.MaximumDateTime = Element.MaximumDate;
}
Control.MaximumDateTime = Element.MaximumDate;
}

void UpdateDateTime()
{
if (null != Control && null != Element && Element.DateTime != Control.DateTime)
if (Element.DateTime != Control.DateTime)
{
Control.DateTime = Element.DateTime;
}
}

void UpdateValueType()
{
if (null != Control && null != Element)
{
if (Element.ValueType == DateTimeType.Date)
{
Control.Style = "datepicker/circle";
Control.Format = "%d/%b/%Y";
}
else if (Element.ValueType == DateTimeType.Time)
{
Control.Style = "timepicker/circle";
Control.Format = "%d/%b/%Y%I:%M%p";
}
}
Control.Mode = Element.ValueType.ToNative();
}

void UpdateMarkerColor()
{
#pragma warning disable CS0618 // MarkerColor is obsolete
if (null != Control && null != Element && Element.MarkerColor != Xamarin.Forms.Color.Default)
if (Element.MarkerColor != Xamarin.Forms.Color.Default)
{
Control.MarkerColor = Element.MarkerColor.ToNative();
}
Expand All @@ -123,57 +106,52 @@ void UpdateMarkerColor()

void OnDateTimeChanged(object sender, EventArgs e)
{
if (null != Control && null != Element)
{
Element.DateTime = Control.DateTime;
}
Element.DateTime = Control.DateTime;
}

void UpdateFieldVisibilityOfYear()
{
if (null != Control && null != Element)
{
Control.SetFieldVisible(EDateTimeFieldType.Year, Element.IsVisibleOfYear);
}
Control.SetFieldVisible(EDateTimeFieldType.Year, Element.IsVisibleOfYear);
}

void UpdateFieldVisibilityOfMonth()
{
if (null != Control && null != Element)
{
Control.SetFieldVisible(EDateTimeFieldType.Month, Element.IsVisibleOfMonth);
}
Control.SetFieldVisible(EDateTimeFieldType.Month, Element.IsVisibleOfMonth);
}

void UpdateFieldVisibilityOfDate()
{
if (null != Control && null != Element)
{
Control.SetFieldVisible(EDateTimeFieldType.Date, Element.IsVisibleOfDate);
}
Control.SetFieldVisible(EDateTimeFieldType.Date, Element.IsVisibleOfDate);
}

void UpdateFieldVisibilityOfHour()
{
if (null != Control && null != Element)
{
Control.SetFieldVisible(EDateTimeFieldType.Hour, Element.IsVisibleOfHour);
}
Control.SetFieldVisible(EDateTimeFieldType.Hour, Element.IsVisibleOfHour);
}

void UpdateFieldVisibilityOfMinute()
{
if (null != Control && null != Element)
{
Control.SetFieldVisible(EDateTimeFieldType.Minute, Element.IsVisibleOfMinute);
}
Control.SetFieldVisible(EDateTimeFieldType.Minute, Element.IsVisibleOfMinute);
}

void UpdateFieldVisibilityOfAmPm()
{
if (null != Control && null != Element)
Control.SetFieldVisible(EDateTimeFieldType.AmPm, Element.IsVisibleOfAmPm);
}
}

internal static class DateTimeTypeEntensions
{
internal static DateTimePickerMode ToNative(this DateTimeType type)
{
switch (type)
{
Control.SetFieldVisible(EDateTimeFieldType.AmPm, Element.IsVisibleOfAmPm);
case DateTimeType.Date:
return DateTimePickerMode.Date;
case DateTimeType.Time:
return DateTimePickerMode.Time;
default:
throw new NotImplementedException($"DateTimeType {type} not supported");
}
}
}
Expand Down
123 changes: 15 additions & 108 deletions src/Tizen.Wearable.CircularUI.Forms.Renderer/CircleStepperRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using XForms = Xamarin.Forms.Forms;
using ESpinner = ElmSharp.Wearable.CircleSpinner;
using Xamarin.Forms.Platform.Tizen.Native.Watch;
using ElmSharp.Wearable;
using ESize = ElmSharp.Size;

[assembly: ExportRenderer(typeof(Tizen.Wearable.CircularUI.Forms.CircleStepper), typeof(Tizen.Wearable.CircularUI.Forms.Renderer.CircleStepperRenderer))]


namespace Tizen.Wearable.CircularUI.Forms.Renderer
{
public class CircleStepperRenderer : ViewRenderer<CircleStepper, ESpinner>
public class CircleStepperRenderer : StepperRenderer
{
ElmSharp.SmartEvent _listShow, _listHide;

public CircleStepperRenderer()
{
#pragma warning disable CS0618 // MarkerColorProperty and MarkerLineWidthProperty are obsolete
Expand All @@ -38,71 +36,19 @@ public CircleStepperRenderer()
#pragma warning restore CS0618 // MarkerColorProperty and MarkerLineWidthProperty are obsolete
RegisterPropertyHandler(CircleStepper.LabelFormatProperty, UpdateLabelFormat);
RegisterPropertyHandler(CircleStepper.TitleProperty, UpdateTitle);
RegisterPropertyHandler(Stepper.MinimumProperty, UpdateMinimum);
RegisterPropertyHandler(Stepper.MaximumProperty, UpdateMaximum);
RegisterPropertyHandler(Stepper.ValueProperty, UpdateValue);
RegisterPropertyHandler(Stepper.IncrementProperty, UpdateIncrement);
RegisterPropertyHandler(CircleStepper.IsWrapEnabledProperty, UpdateWrapEnabled);
}

protected override void OnElementChanged(ElementChangedEventArgs<CircleStepper> e)
{
if (Control == null)
{
var surface = this.GetSurface();
if (null != surface)
{
var spinner = new ESpinner(XForms.NativeParent, surface);
spinner.Style = "circle";

SetNativeControl(spinner);
Control.ValueChanged += OnValueChanged;

if (Tizen.Common.DotnetUtil.TizenAPIVersion == 4)
{
_listShow = new ElmSharp.SmartEvent(Control, "genlist,show");
_listHide = new ElmSharp.SmartEvent(Control, "genlist,hide");
}
else
{
_listShow = new ElmSharp.SmartEvent(Control, "list,show");
_listHide = new ElmSharp.SmartEvent(Control, "list,hide");
}
_listShow.On += OnListShow;
_listHide.On += OnListHide;
}
}
protected new WatchSpinner Control => base.Control as WatchSpinner;

base.OnElementChanged(e);
}
protected new CircleStepper Element => base.Element as CircleStepper;

private void OnValueChanged(object sender, EventArgs e)
protected override void OnElementChanged(ElementChangedEventArgs<Stepper> e)
{
double newValue = Control.Value;
((IElementController)Element).SetValueFromRenderer(Stepper.ValueProperty, newValue);
base.OnElementChanged(e);

if (Element.LabelFormat == null)
{
// Determines how many decimal places are there in current Stepper's value.
// The 15 pound characters below correspond to the maximum precision of Double type.
var decimalValue = Decimal.Parse(newValue.ToString("0.###############"));

// GetBits() method returns an array of four 32-bit integer values.
// The third (0-indexing) element of an array contains the following information:
// bits 00-15: unused, required to be 0
// bits 16-23: an exponent between 0 and 28 indicating the power of 10 to divide the integer number passed as a parameter.
// Conversely this is the number of decimal digits in the number as well.
// bits 24-30: unused, required to be 0
// bit 31: indicates the sign. 0 means positive number, 1 is for negative numbers.
//
// The precision information needs to be extracted from bits 16-23 of third element of an array
// returned by GetBits() call. Right-shifting by 16 bits followed by zeroing anything else results
// in a nice conversion of this data to integer variable.
var precision = (Decimal.GetBits(decimalValue)[3] >> 16) & 0x000000FF;

// Sets Stepper's inner label decimal format to use exactly as many decimal places as needed:
Control.LabelFormat = string.Format("%.{0}f", precision);
}
Control.WheelAppeared += OnListShow;
Control.WheelDisappeared += OnListHide;
}

protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -141,7 +87,7 @@ void OnListHide(object sender, EventArgs args)
void UpdateMarkerColor()
{
#pragma warning disable CS0618 // MarkerColor is obsolete
if (null != Control && null != Element && Element.MarkerColor != Color.Default)
if (Element.MarkerColor != Color.Default)
{
Control.MarkerColor = Element.MarkerColor.ToNative();
}
Expand All @@ -150,68 +96,29 @@ void UpdateMarkerColor()

void UpdateMarkerLineWidth()
{
if (null != Control && null != Element)
{
#pragma warning disable CS0618 // MarkerLineWidth is obsolete
Control.MarkerLineWidth = Element.MarkerLineWidth;
Control.MarkerLineWidth = Element.MarkerLineWidth;
#pragma warning restore CS0618 // MarkerLineWidth is obsolete
}
}

void UpdateLabelFormat()
{
if (null != Control && null != Element)
{
Control.LabelFormat = Element.LabelFormat;
}
Control.LabelFormat = Element.LabelFormat;
}

void UpdateTitle()
{
if (null != Control && null != Element)
{
Control.SetPartText("elm.text", Element.Title);
}
}

void UpdateValue()
{
if (null != Control && null != Element)
{
Control.Value = Element.Value;
}
}

void UpdateMaximum()
{
if (null != Control && null != Element)
{
Control.Maximum = Element.Maximum;
}
}

void UpdateMinimum()
{
if (null != Control && null != Element)
{
Control.Minimum = Element.Minimum;
}
Control.SetPartText("elm.text", Element.Title);
}

void UpdateIncrement()
{
if (null != Control && null != Element)
{
Control.Step = Element.Increment;
}
Control.Step = Element.Increment;
}

void UpdateWrapEnabled()
{
if (null != Control && null != Element)
{
Control.IsWrapEnabled = Element.IsWrapEnabled;
}
Control.IsWrapEnabled = Element.IsWrapEnabled;
}
}
}

0 comments on commit 5123b95

Please sign in to comment.