From 27863d5fb36d00444385cc799ccc5d41fe4a7a6b Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Thu, 23 Nov 2017 11:21:11 +0900 Subject: [PATCH] Added implementation for Tizen.NET --- README.md | 1 + nuget/Plugin.nuspec | 4 + src/LocalNotifications.sln | 57 ++++++++++- .../LocalNotificationsImplementation.cs | 94 +++++++++++++++++++ .../Plugin.LocalNotifications.Tizen.csproj | 37 ++++++++ 5 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 src/Plugin.LocalNotifications.Tizen/LocalNotificationsImplementation.cs create mode 100644 src/Plugin.LocalNotifications.Tizen/Plugin.LocalNotifications.Tizen.csproj diff --git a/README.md b/README.md index 6336b2f..9eec28a 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ A consistent and easy way to show local notifications in Xamarin and Windows app |Windows Store (WinRT)|Yes|8.1+| |Windows (UWP)|Yes|10+| |Xamarin.Mac|No|| +|Tizen|Yes|4.0+| ### API Usage diff --git a/nuget/Plugin.nuspec b/nuget/Plugin.nuspec index 3374c85..741403b 100644 --- a/nuget/Plugin.nuspec +++ b/nuget/Plugin.nuspec @@ -67,6 +67,10 @@ + + + + \ No newline at end of file diff --git a/src/LocalNotifications.sln b/src/LocalNotifications.sln index 528bb47..870c191 100644 --- a/src/LocalNotifications.sln +++ b/src/LocalNotifications.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2002 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.LocalNotifications.Abstractions", "Plugin.LocalNotifications.Abstractions\Plugin.LocalNotifications.Abstractions.csproj", "{57564CE6-C079-47C5-9272-4395A0224C3D}" EndProject @@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.LocalNotifications.W EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.LocalNotifications.macOS", "Plugin.LocalNotifications.macOS\Plugin.LocalNotifications.macOS.csproj", "{1F3C7F03-BCEB-46E7-B9B8-843D4DEF7364}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin.LocalNotifications.Tizen", "Plugin.LocalNotifications.Tizen\Plugin.LocalNotifications.Tizen.csproj", "{4A54649B-003D-473C-B194-4DF8DDEA5589}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Ad-Hoc|Any CPU = Ad-Hoc|Any CPU @@ -415,8 +417,59 @@ Global {1F3C7F03-BCEB-46E7-B9B8-843D4DEF7364}.Release|x64.Build.0 = Release|Any CPU {1F3C7F03-BCEB-46E7-B9B8-843D4DEF7364}.Release|x86.ActiveCfg = Release|Any CPU {1F3C7F03-BCEB-46E7-B9B8-843D4DEF7364}.Release|x86.Build.0 = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|x64.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Ad-Hoc|x86.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|Any CPU.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|ARM.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|ARM.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|iPhone.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|x64.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|x64.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|x86.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.AppStore|x86.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|ARM.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|ARM.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|iPhone.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|x64.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|x64.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|x86.ActiveCfg = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Debug|x86.Build.0 = Debug|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|Any CPU.Build.0 = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|ARM.ActiveCfg = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|ARM.Build.0 = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|iPhone.ActiveCfg = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|iPhone.Build.0 = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|x64.ActiveCfg = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|x64.Build.0 = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|x86.ActiveCfg = Release|Any CPU + {4A54649B-003D-473C-B194-4DF8DDEA5589}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CFD1968F-13AE-4B7D-A1ED-01833C6F48C4} + EndGlobalSection EndGlobal diff --git a/src/Plugin.LocalNotifications.Tizen/LocalNotificationsImplementation.cs b/src/Plugin.LocalNotifications.Tizen/LocalNotificationsImplementation.cs new file mode 100644 index 0000000..8eeba26 --- /dev/null +++ b/src/Plugin.LocalNotifications.Tizen/LocalNotificationsImplementation.cs @@ -0,0 +1,94 @@ +using System; +using Plugin.LocalNotifications.Abstractions; +using Tizen.Applications.Notifications; +using System.Timers; + +namespace Plugin.LocalNotifications +{ + /// + /// Local Notifications implementation for Tizen + /// + public class LocalNotificationsImplementation : ILocalNotifications + { + Timer timer; + int notificationId = 0; + /// + /// Show a local notification + /// + /// Title of the notification + /// Body or description of the notification + /// Id of the notification + public void Show(string title, string body, int id = 0) + { + Notification notification = new Notification + { + Title = title, + Content = body, + Tag = id.ToString(), + }; + Notification.IndicatorStyle style = new Notification.IndicatorStyle + { + SubText = body + }; + notification.AddStyle(style); + NotificationManager.Post(notification); + } + + /// + /// Show a local notification at a specified time + /// + /// Title of the notification + /// Body or description of the notification + /// Id of the notification + /// Time to show notification + public void Show(string title, string body, int id, DateTime notifyTime) + { + Notification notification = new Notification + { + Title = title, + Content = body, + Tag = id.ToString(), + }; + notificationId = id; + Notification.IndicatorStyle style = new Notification.IndicatorStyle + { + SubText = body + }; + notification.AddStyle(style); + NotificationManager.Post(notification); + + var time = notifyTime - DateTime.Now; + int duration = (time.Seconds + time.Milliseconds / 1000); + + timer = new Timer(); + timer.Interval = duration * 1000; + timer.Elapsed += new ElapsedEventHandler(TimerElapsed); + timer.Start(); + } + + void TimerElapsed(object sender, ElapsedEventArgs e) + { + Cancel(notificationId); + timer.Stop(); + } + + /// + /// Cancel a local notification + /// + /// Id of the notification to cancel + public void Cancel(int id) + { + Notification loadNotification = null; + try + { + loadNotification = NotificationManager.Load(id.ToString()); + } + catch (Exception ex) + { + Console.Write(ex.Message); + } + if (loadNotification != null) + NotificationManager.Delete(loadNotification); + } + } +} diff --git a/src/Plugin.LocalNotifications.Tizen/Plugin.LocalNotifications.Tizen.csproj b/src/Plugin.LocalNotifications.Tizen/Plugin.LocalNotifications.Tizen.csproj new file mode 100644 index 0000000..7157eeb --- /dev/null +++ b/src/Plugin.LocalNotifications.Tizen/Plugin.LocalNotifications.Tizen.csproj @@ -0,0 +1,37 @@ + + + + + tizen40 + false + Plugin.LocalNotifications + Plugin.LocalNotifications + + + + portable + + + None + + + + + + Runtime + + + + + + CrossLocalNotifications.cs + + + + + {57564CE6-C079-47C5-9272-4395A0224C3D} + Plugin.LocalNotifications.Abstractions + + + +