Skip to content

Commit de7eebd

Browse files
authored
Merge pull request #468 from JongHeonChoi/master
Added implementation for Tizen.NET
2 parents 79352bd + afd4ef9 commit de7eebd

17 files changed

+1999
-3
lines changed

readme.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## AS OF v6.5 - USER DIALOGS IS NETSTANDARD - https://docs.microsoft.com/en-us/dotnet/standard/library
44

55
A cross platform library that allows you to call for standard user dialogs from a shared/portable library.
6-
Supports Android, iOS, and Unified Windows Platform (UWP, UAP)
6+
Supports Android, iOS, Unified Windows Platform (UWP, UAP) and Tizen
77

88
[![NuGet](https://img.shields.io/nuget/v/Acr.UserDialogs.svg?maxAge=2592000)](https://www.nuget.org/packages/Acr.UserDialogs/)
99

@@ -33,6 +33,7 @@ _Docs are a work in progress (looking for help!)
3333
* Android
3434
* Universal Windows Platform (Win10/UWP)
3535
* NET Standard 1.1
36+
* Tizen 4.0+
3637

3738
* macOS & tvOS - coming soon
3839

src/Acr.UserDialogs.Shared/UserDialogs.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using Android.App;
77
using Acr.Support.Android;
88
#endif
9+
#if __TIZEN__
10+
using ElmSharp;
11+
#endif
912

1013
namespace Acr.UserDialogs
1114
{
@@ -51,7 +54,15 @@ public static void Init(Func<UIViewController> viewControllerFunc)
5154
{
5255
Instance = new UserDialogsImpl(viewControllerFunc);
5356
}
54-
57+
#elif __TIZEN__
58+
/// <summary>
59+
/// Initialize Tizen user dialogs
60+
/// </summary>
61+
/// <param name="window"></param>
62+
public static void Init(Window window)
63+
{
64+
Instance = new UserDialogsImpl(window);
65+
}
5566
#endif
5667

5768
static IUserDialogs currentInstance;
@@ -65,6 +76,11 @@ public static IUserDialogs Instance
6576
#elif __ANDROID__
6677
if (currentInstance == null)
6778
throw new ArgumentException("[Acr.UserDialogs] In android, you must call UserDialogs.Init(Activity) from your first activity OR UserDialogs.Init(App) from your custom application OR provide a factory function to get the current top activity via UserDialogs.Init(() => supply top activity)");
79+
#elif __TIZEN__
80+
if (currentInstance == null)
81+
{
82+
throw new ArgumentException("[Acr.UserDialogs] In Tizen, the window instance of your custom application must be passed by using UserDialogs.Init(Window).");
83+
}
6884
#else
6985
currentInstance = currentInstance ?? new UserDialogsImpl();
7086
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<!-- Property Group for Tizen Project -->
4+
<PropertyGroup>
5+
<TargetFramework>tizen40</TargetFramework>
6+
<TizenCreateTpkOnBuild>false</TizenCreateTpkOnBuild>
7+
<AssemblyName>Plugin.UserDialogs</AssemblyName>
8+
<RootNamespace>Plugin.UserDialogs</RootNamespace>
9+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
10+
</PropertyGroup>
11+
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13+
<DebugType>portable</DebugType>
14+
<DefineConstants>__TIZEN__;_</DefineConstants>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
17+
<DebugType>None</DebugType>
18+
<DefineConstants>__TIZEN__;_</DefineConstants>
19+
</PropertyGroup>
20+
21+
<!-- Include Nuget Package for Tizen Project building -->
22+
<ItemGroup>
23+
<PackageReference Include="Tizen.NET" Version="4.0.0">
24+
<ExcludeAssets>Runtime</ExcludeAssets>
25+
</PackageReference>
26+
<PackageReference Include="Tizen.NET.Sdk" Version="1.0.0" />
27+
<PackageReference Include="Xamarin.Forms" Version="2.4.0.18342" />
28+
<PackageReference Include="Xamarin.Forms.Platform.Tizen" Version="2.4.0.18342" />
29+
</ItemGroup>
30+
<ItemGroup>
31+
<ProjectReference Include="..\Acr.UserDialogs.Interface\Acr.UserDialogs.Interface.csproj" />
32+
<ProjectReference Include="..\Acr.UserDialogs\Acr.UserDialogs.csproj" />
33+
</ItemGroup>
34+
35+
<Import Project="..\Acr.UserDialogs.Shared\Acr.UserDialogs.Shared.projitems" Label="Shared" />
36+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Splat;
2+
using System;
3+
using System.Windows.Input;
4+
using Xamarin.Forms;
5+
6+
namespace Acr.UserDialogs
7+
{
8+
public class ActionSheetOptionViewModel
9+
{
10+
public ActionSheetOptionViewModel(string text, Action action, IBitmap image = null)
11+
{
12+
this.Text = text;
13+
this.Action = new Command(action);
14+
//this.Visible = visible ? Visibility.Visible : Visibility.Collapsed;
15+
this.ItemIcon = image;
16+
}
17+
18+
//public Visibility Visible { get; }
19+
public string Text { get; }
20+
public ICommand Action { get; }
21+
public IBitmap ItemIcon { get; }
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Acr.UserDialogs
5+
{
6+
public class ActionSheetViewModel
7+
{
8+
public string Title { get; set; }
9+
10+
public string Message { get; set; }
11+
12+
//public Visibility MessageVisibility => String.IsNullOrWhiteSpace(this.Message) ? Visibility.Collapsed : Visibility.Visible;
13+
14+
public ActionSheetOptionViewModel Destructive { get; set; }
15+
//public Visibility DestructiveVisibility { get; set; }
16+
17+
public ActionSheetOptionViewModel Cancel { get; set; }
18+
//public Visibility CancelVisibility { get; set; }
19+
20+
public IList<ActionSheetOptionViewModel> Options { get; set; }
21+
}
22+
}
+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
using System;
2+
using Xamarin.Forms;
3+
4+
namespace Acr.UserDialogs
5+
{
6+
/// <summary>
7+
/// The DateTime view is used to display the input date and time values.
8+
/// </summary>
9+
/// <example>
10+
/// <code>
11+
/// var dateView = new DateTimeView
12+
/// {
13+
/// HorizontalOptions = LayoutOptions.Center,
14+
/// VerticalOptions = LayoutOptions.Start,
15+
/// DateTime = DateTime.Now,
16+
/// MaximumDate = new DateTime(2030, 12, 31),
17+
/// MinimumDate = new DateTime(2017, 1, 1),
18+
/// DisplayFormat = "%F",
19+
/// }
20+
/// </code>
21+
/// </example>
22+
public class DateTimeView : View
23+
{
24+
/// <summary>
25+
/// BindableProperty. Identifies the DateTime bindable property.
26+
/// </summary>
27+
public static readonly BindableProperty DateTimeProperty = BindableProperty.Create(nameof(DateTime), typeof(DateTime), typeof(DateTimeView), DateTime.Now, BindingMode.TwoWay, coerceValue: CoerceDate,
28+
propertyChanged: DatePropertyChanged);
29+
30+
/// <summary>
31+
/// BindableProperty. Identifies the DisplayFormat bindable property.
32+
/// </summary>
33+
public static readonly BindableProperty DisplayFormatProperty = BindableProperty.Create(nameof(DisplayFormat), typeof(string), typeof(DateTimeView), "%F");
34+
35+
/// <summary>
36+
/// BindableProperty. Identifies the MinimumDate bindable property.
37+
/// </summary>
38+
public static readonly BindableProperty MinimumDateProperty = BindableProperty.Create(nameof(MinimumDate), typeof(DateTime), typeof(DateTimeView), new DateTime(1900, 1, 1),
39+
validateValue: ValidateMinimumDate, coerceValue: CoerceMinimumDate);
40+
41+
/// <summary>
42+
/// BindableProperty. Identifies the MaximumDate bindable property.
43+
/// </summary>
44+
public static readonly BindableProperty MaximumDateProperty = BindableProperty.Create(nameof(MaximumDate), typeof(DateTime), typeof(DateTimeView), new DateTime(2100, 12, 31),
45+
validateValue: ValidateMaximumDate, coerceValue: CoerceMaximumDate);
46+
47+
/// <summary>
48+
/// Gets or sets the current value of a DateTime.
49+
/// </summary>
50+
public DateTime DateTime
51+
{
52+
get { return (DateTime)GetValue(DateTimeProperty); }
53+
set { SetValue(DateTimeProperty, value); }
54+
}
55+
56+
/// <summary>
57+
/// Gets or sets the DateTime format.
58+
/// Format is a combination of allowed LIBC date format specifiers like: "%b %d, %Y %I : %M %p".
59+
/// </summary>
60+
/// <remarks>
61+
/// These specifiers can be arranged in any order and the widget displays the fields accordingly.
62+
/// However, you cannot use date and time settings in combination.
63+
/// The default format is taken as per the system locale settings.
64+
/// </remarks>
65+
/// <remarks>
66+
/// The maximum allowed format length is 64 chars.<br>
67+
/// The format can include separators for each individual DateTime field except for the AM/PM field.<br>
68+
/// Each separator can be a maximum of 6 UTF-8 bytes. Space is also taken as a separator.<br>
69+
/// Following are the allowed set of format specifiers for each DateTime field.<br>
70+
/// %Y : The year as a decimal number including the century.<br>
71+
/// %m : The month as a decimal number (range 01 to 12).<br>
72+
/// %b : The abbreviated month name according to the current locale.<br>
73+
/// %B : The full month name according to the current locale.<br>
74+
/// %h : The abbreviated month name according to the current locale(same as %b).<br>
75+
/// %d : The day of the month as a decimal number(range 01 to 31).<br>
76+
/// %e : The day of the month as a decimal number(range 1 to 31). Single digits are preceded by a blank.<br>
77+
/// %I : The hour as a decimal number using a 12-hour clock(range 01 to 12).<br>
78+
/// %H : The hour as a decimal number using a 24-hour clock(range 00 to 23).<br>
79+
/// %k : The hour(24-hour clock) as a decimal number(range 0 to 23). Single digits are preceded by a blank.<br>
80+
/// %l : The hour(12-hour clock) as a decimal number(range 1 to 12). Single digits are preceded by a blank.<br>
81+
/// %M : The minute as a decimal number(range 00 to 59).<br>
82+
/// %p : Either 'AM' or 'PM' according to the given time value, or the corresponding strings for the current locale. Noon is treated as 'PM' and midnight as 'AM'.<br>
83+
/// %P : Like %p, but in lower case: 'am' or 'pm' or a corresponding string for the current locale.<br>
84+
/// %c : The preferred date and time representation for the current locale.<br>
85+
/// %x : The preferred date representation for the current locale without the time.<br>
86+
/// %X : The preferred time representation for the current locale without the date.<br>
87+
/// %r : The complete calendar time using the AM/PM format of the current locale.<br>
88+
/// %R : The hour and minute in decimal numbers using the format H:M.<br>
89+
/// %T : The time of the day in decimal numbers using the format H:M:S.<br>
90+
/// %F : The date using the format %Y-%m-%d.<br>
91+
/// </remarks>
92+
public string DisplayFormat
93+
{
94+
get { return (string)GetValue(DisplayFormatProperty); }
95+
set { SetValue(DisplayFormatProperty, value); }
96+
}
97+
98+
/// <summary>
99+
/// Gets or sets the upper boundary of a DateTime value.
100+
/// </summary>
101+
public DateTime MaximumDate
102+
{
103+
get { return (DateTime)GetValue(MaximumDateProperty); }
104+
set { SetValue(MaximumDateProperty, value); }
105+
}
106+
107+
/// <summary>
108+
/// Gets or sets the lower boundary of a DateTime value.
109+
/// </summary>
110+
public DateTime MinimumDate
111+
{
112+
get { return (DateTime)GetValue(MinimumDateProperty); }
113+
set { SetValue(MinimumDateProperty, value); }
114+
}
115+
116+
/// <summary>
117+
/// An event fired when the DateTime property changes.
118+
/// </summary>
119+
public event EventHandler<DateChangedEventArgs> DateChanged;
120+
121+
static object CoerceDate(BindableObject bindable, object value)
122+
{
123+
var picker = (DateTimeView)bindable;
124+
DateTime dateValue = (DateTime)value;
125+
126+
if (dateValue > picker.MaximumDate)
127+
dateValue = picker.MaximumDate;
128+
129+
if (dateValue < picker.MinimumDate)
130+
dateValue = picker.MinimumDate;
131+
132+
return dateValue;
133+
}
134+
135+
static object CoerceMaximumDate(BindableObject bindable, object value)
136+
{
137+
DateTime dateValue = ((DateTime)value).Date;
138+
var selector = (DateTimeView)bindable;
139+
if (selector.DateTime > dateValue)
140+
selector.DateTime = dateValue;
141+
142+
return dateValue;
143+
}
144+
145+
static object CoerceMinimumDate(BindableObject bindable, object value)
146+
{
147+
DateTime dateValue = ((DateTime)value).Date;
148+
var selector = (DateTimeView)bindable;
149+
if (selector.DateTime < dateValue)
150+
selector.DateTime = dateValue;
151+
152+
return dateValue;
153+
}
154+
155+
static void DatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
156+
{
157+
var selector = (DateTimeView)bindable;
158+
EventHandler<DateChangedEventArgs> selected = selector.DateChanged;
159+
160+
if (selected != null)
161+
selected(selector, new DateChangedEventArgs((DateTime)oldValue, (DateTime)newValue));
162+
}
163+
164+
static bool ValidateMaximumDate(BindableObject bindable, object value)
165+
{
166+
return (DateTime)value >= ((DateTimeView)bindable).MinimumDate;
167+
}
168+
169+
static bool ValidateMinimumDate(BindableObject bindable, object value)
170+
{
171+
return (DateTime)value <= ((DateTimeView)bindable).MaximumDate;
172+
}
173+
}
174+
}

0 commit comments

Comments
 (0)