From: seungha.son Date: Fri, 24 Mar 2017 06:12:38 +0000 (+0900) Subject: Renewal Notification X-Git-Tag: submit/trunk/20170823.075128~121^2~50 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03f542adbaa76b4d9dea914b0496696d1b6b3c4e;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Renewal Notification Signed-off-by: seungha.son Change-Id: Ia6253fe7ba07ae250a6ce67c405ee2e319254f7e Signed-off-by: jusung son --- diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj index 201adcf..6d687e6 100755 --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -76,7 +76,6 @@ - @@ -103,10 +102,6 @@ - - - - @@ -118,7 +113,6 @@ - @@ -139,6 +133,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Tizen.Applications/Tizen.Applications.project.json b/Tizen.Applications/Tizen.Applications.project.json index 55ec093..156ef7a 100755 --- a/Tizen.Applications/Tizen.Applications.project.json +++ b/Tizen.Applications/Tizen.Applications.project.json @@ -1,9 +1,9 @@ { "dependencies": { "NETStandard.Library": "1.6.0", - "Tizen": "1.0.2" + "Tizen": "1.0.3" }, "frameworks": { "netstandard1.3": {} } -} +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Interop/Interop.Libraries.cs b/src/Tizen.Applications.Notification/Interop/Interop.Libraries.cs index f841a1f..d5edebd 100755 --- a/src/Tizen.Applications.Notification/Interop/Interop.Libraries.cs +++ b/src/Tizen.Applications.Notification/Interop/Interop.Libraries.cs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/Tizen.Applications.Notification/Interop/Interop.Notification.cs b/src/Tizen.Applications.Notification/Interop/Interop.Notification.cs index 5252adb..ce81769 100755 --- a/src/Tizen.Applications.Notification/Interop/Interop.Notification.cs +++ b/src/Tizen.Applications.Notification/Interop/Interop.Notification.cs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ using System; +using System.ComponentModel; using System.Runtime.InteropServices; using Tizen.Applications; using Tizen.Applications.Notifications; @@ -24,149 +25,288 @@ internal static partial class Interop internal static class Notification { [DllImport(Libraries.Notification, EntryPoint = "notification_create")] - internal static extern SafeNotificationHandle Create(NotificationType type); + internal static extern IntPtr Create(NotificationType type); [DllImport(Libraries.Notification, EntryPoint = "notification_free")] - internal static extern int Destroy(IntPtr handle); + internal static extern NotificationError Destroy(IntPtr handle); [DllImport(Libraries.Notification, EntryPoint = "notification_get_text")] - internal static extern int GetText(SafeNotificationHandle handle, NotiText type, out IntPtr text); + internal static extern NotificationError GetTextReferenceType(NotificationSafeHandle handle, NotificationText type, out IntPtr text); [DllImport(Libraries.Notification, EntryPoint = "notification_set_text")] - internal static extern int SetText(SafeNotificationHandle handle, NotiText type, string text, string key, int args); + internal static extern NotificationError SetText(NotificationSafeHandle handle, NotificationText type, string text, string key, int args); [DllImport(Libraries.Notification, EntryPoint = "notification_get_image")] - internal static extern int GetImage(SafeNotificationHandle handle, NotiImage type, out IntPtr text); + internal static extern NotificationError GetImageReferenceType(NotificationSafeHandle handle, NotificationImage type, out IntPtr path); [DllImport(Libraries.Notification, EntryPoint = "notification_set_image")] - internal static extern int SetImage(SafeNotificationHandle handle, NotiImage type, string text); + internal static extern NotificationError SetImage(NotificationSafeHandle handle, NotificationImage type, string path); [DllImport(Libraries.Notification, EntryPoint = "notification_get_time")] - internal static extern int GetTime(SafeNotificationHandle handle, out int time); + internal static extern NotificationError GetTime(NotificationSafeHandle handle, out int time); [DllImport(Libraries.Notification, EntryPoint = "notification_set_time")] - internal static extern int SetTime(SafeNotificationHandle handle, int time); + internal static extern NotificationError SetTime(NotificationSafeHandle handle, int time); [DllImport(Libraries.Notification, EntryPoint = "notification_get_insert_time")] - internal static extern int GetInsertTime(SafeNotificationHandle handle, out long time); + internal static extern NotificationError GetInsertTime(NotificationSafeHandle handle, out long time); [DllImport(Libraries.Notification, EntryPoint = "notification_get_sound")] - internal static extern int GetSound(SafeNotificationHandle handle, out SoundOption type, out IntPtr path); + internal static extern NotificationError GetSoundReferenceType(NotificationSafeHandle handle, out AccessoryOption type, out IntPtr path); [DllImport(Libraries.Notification, EntryPoint = "notification_set_sound")] - internal static extern int SetSound(SafeNotificationHandle handle, SoundOption type, string path); + internal static extern NotificationError SetSound(NotificationSafeHandle handle, AccessoryOption type, string path); [DllImport(Libraries.Notification, EntryPoint = "notification_get_vibration")] - internal static extern int GetVibration(SafeNotificationHandle handle, out VibrationOption type, out IntPtr path); + internal static extern NotificationError GetVibrationReferenceType(NotificationSafeHandle handle, out AccessoryOption type, out IntPtr path); [DllImport(Libraries.Notification, EntryPoint = "notification_set_vibration")] - internal static extern int SetVibration(SafeNotificationHandle handle, VibrationOption type, string path); + internal static extern NotificationError SetVibration(NotificationSafeHandle handle, AccessoryOption type, string path); [DllImport(Libraries.Notification, EntryPoint = "notification_get_led")] - internal static extern int GetLed(SafeNotificationHandle handle, out LedOption type, out int color); + internal static extern NotificationError GetLed(NotificationSafeHandle handle, out AccessoryOption type, out int color); [DllImport(Libraries.Notification, EntryPoint = "notification_set_led")] - internal static extern int SetLed(SafeNotificationHandle handle, LedOption type, int color); + internal static extern NotificationError SetLed(NotificationSafeHandle handle, AccessoryOption type, int color); [DllImport(Libraries.Notification, EntryPoint = "notification_get_led_time_period")] - internal static extern int GetLedTimePeriod(SafeNotificationHandle handle, out int on, out int off); + internal static extern NotificationError GetLedTimePeriod(NotificationSafeHandle handle, out int onMillisecond, out int offMillisecond); [DllImport(Libraries.Notification, EntryPoint = "notification_set_led_time_period")] - internal static extern int SetLedTimePeriod(SafeNotificationHandle handle, int on, int off); + internal static extern NotificationError SetLedTimePeriod(NotificationSafeHandle handle, int onMillisecond, int offMillisecond); [DllImport(Libraries.Notification, EntryPoint = "notification_get_launch_option")] - internal static extern int GetAppControl(SafeNotificationHandle handle, LaunchOption type, out SafeAppControlHandle apphandle); + internal static extern NotificationError GetAppControl(NotificationSafeHandle handle, LaunchOption type, out SafeAppControlHandle apphandle); [DllImport(Libraries.Notification, EntryPoint = "notification_set_launch_option")] - internal static extern int SetAppControl(SafeNotificationHandle handle, LaunchOption type, SafeAppControlHandle appHandle); + internal static extern NotificationError SetAppControl(NotificationSafeHandle handle, LaunchOption type, SafeAppControlHandle appHandle); [DllImport(Libraries.Notification, EntryPoint = "notification_get_event_handler")] - internal static extern int GetEventHandler(SafeNotificationHandle handle, int type, out SafeAppControlHandle appHandle); + internal static extern NotificationError GetEventHandler(NotificationSafeHandle handle, int type, out SafeAppControlHandle appHandle); [DllImport(Libraries.Notification, EntryPoint = "notification_set_event_handler")] - internal static extern int SetEventHandler(SafeNotificationHandle handle, int type, SafeAppControlHandle appHandle); + internal static extern NotificationError SetEventHandler(NotificationSafeHandle handle, int type, SafeAppControlHandle appHandle); [DllImport(Libraries.Notification, EntryPoint = "notification_get_property")] - internal static extern int GetProperties(SafeNotificationHandle handle, out int flags); + internal static extern NotificationError GetProperties(NotificationSafeHandle handle, out int flags); [DllImport(Libraries.Notification, EntryPoint = "notification_set_property")] - internal static extern int SetProperties(SafeNotificationHandle handle, int flags); + internal static extern NotificationError SetProperties(NotificationSafeHandle handle, int flags); [DllImport(Libraries.Notification, EntryPoint = "notification_get_display_applist")] - internal static extern int GetApplist(SafeNotificationHandle handle, out int flags); + internal static extern NotificationError GetApplist(NotificationSafeHandle handle, out int flags); [DllImport(Libraries.Notification, EntryPoint = "notification_set_display_applist")] - internal static extern int SetApplist(SafeNotificationHandle handle, int flags); + internal static extern NotificationError SetApplist(NotificationSafeHandle handle, int flags); [DllImport(Libraries.Notification, EntryPoint = "notification_get_size")] - internal static extern int GetProgressSize(SafeNotificationHandle handle, out double value); + internal static extern NotificationError GetProgressSize(NotificationSafeHandle handle, out double size); [DllImport(Libraries.Notification, EntryPoint = "notification_set_size")] - internal static extern int SetProgressSize(SafeNotificationHandle handle, double value); + internal static extern NotificationError SetProgressSize(NotificationSafeHandle handle, double size); [DllImport(Libraries.Notification, EntryPoint = "notification_get_progress")] - internal static extern int GetProgress(SafeNotificationHandle handle, out double value); + internal static extern NotificationError GetProgress(NotificationSafeHandle handle, out double progress); [DllImport(Libraries.Notification, EntryPoint = "notification_set_progress")] - internal static extern int SetProgress(SafeNotificationHandle handle, double value); + internal static extern NotificationError SetProgress(NotificationSafeHandle handle, double progress); [DllImport(Libraries.Notification, EntryPoint = "notification_get_layout")] - internal static extern int GetLayout(SafeNotificationHandle handle, out NotiLayout type); + internal static extern NotificationError GetLayout(NotificationSafeHandle handle, out NotificationLayout layout); [DllImport(Libraries.Notification, EntryPoint = "notification_set_layout")] - internal static extern int SetLayout(SafeNotificationHandle handle, NotiLayout type); + internal static extern NotificationError SetLayout(NotificationSafeHandle handle, NotificationLayout layout); [DllImport(Libraries.Notification, EntryPoint = "notification_get_type")] - internal static extern int GetType(SafeNotificationHandle handle, out NotificationType type); + internal static extern NotificationError GetType(NotificationSafeHandle handle, out NotificationType type); [DllImport(Libraries.Notification, EntryPoint = "notification_update")] - internal static extern int Update(SafeNotificationHandle handle); + internal static extern NotificationError Update(NotificationSafeHandle handle); [DllImport(Libraries.Notification, EntryPoint = "notification_delete")] - internal static extern int Delete(SafeNotificationHandle handle); + internal static extern NotificationError Delete(NotificationSafeHandle handle); [DllImport(Libraries.Notification, EntryPoint = "notification_delete_all")] - internal static extern int DeleteAll(int type); + internal static extern NotificationError DeleteAll(int type); [DllImport(Libraries.Notification, EntryPoint = "notification_post")] - internal static extern int Post(SafeNotificationHandle handle); + internal static extern NotificationError Post(NotificationSafeHandle handle); [DllImport(Libraries.Notification, EntryPoint = "notification_get_pkgname")] - internal static extern int GetPackageName(SafeNotificationHandle handle, out IntPtr name); + internal static extern NotificationError GetPackageName(NotificationSafeHandle handle, out IntPtr name); - [DllImport(Libraries.Notification, EntryPoint = "notification_add_button")] - internal static extern int AddButton(SafeNotificationHandle handle, int index); + [DllImport(Libraries.Notification, EntryPoint = "notification_set_event_handler")] + internal static extern NotificationError AddButtonAction(NotificationSafeHandle handle, ButtonIndex type, SafeAppControlHandle appcontrol); [DllImport(Libraries.Notification, EntryPoint = "notification_remove_button")] - internal static extern int RemoveButton(SafeNotificationHandle handle, int index); + internal static extern NotificationError RemoveButton(NotificationSafeHandle handle, ButtonIndex index); [DllImport(Libraries.Notification, EntryPoint = "notification_set_tag")] - internal static extern int SetTag(SafeNotificationHandle handle, string tag); + internal static extern NotificationError SetTag(NotificationSafeHandle handle, string tag); [DllImport(Libraries.Notification, EntryPoint = "notification_get_tag")] - internal static extern int GetTag(SafeNotificationHandle handle, out IntPtr tag); + internal static extern NotificationError GetTagReferenceType(NotificationSafeHandle handle, out IntPtr tag); [DllImport(Libraries.Notification, EntryPoint = "notification_load_by_tag")] - internal static extern SafeNotificationHandle Load(string text); + internal static extern IntPtr Load(string text); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_id")] + internal static extern NotificationError GetID(NotificationSafeHandle handle, out int groupID, out int privID); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_priv_id")] + internal static extern NotificationError SetID(NotificationSafeHandle handle, int privID); + + [DllImport(Libraries.Notification, EntryPoint = "notification_save_as_template")] + internal static extern NotificationError SaveTemplate(NotificationSafeHandle handle, string name); + + [DllImport(Libraries.Notification, EntryPoint = "notification_create_from_template")] + internal static extern IntPtr LoadTemplate(string name); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_noti_block_state")] + internal static extern NotificationError GetBlockState(out NotificationBlockState status); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_auto_remove")] + internal static extern NotificationError SetAutoRemove(NotificationSafeHandle handle, bool autoRemove); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_auto_remove")] + internal static extern NotificationError GetAutoRemove(NotificationSafeHandle handle, out bool autoRemove); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_ongoing_value_type")] + internal static extern NotificationError SetProgressType(NotificationSafeHandle handle, ProgressCategory category); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_ongoing_value_type")] + internal static extern NotificationError GetProgressType(NotificationSafeHandle handle, out ProgressCategory category); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_ongoing_flag")] + internal static extern NotificationError SetOngoingFlag(NotificationSafeHandle handle, bool flag); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_ongoing_flag")] + internal static extern NotificationError GetProgressFlag(NotificationSafeHandle handle, bool flag); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_ongoing_flag")] + internal static extern NotificationError GetProgressFlag(NotificationSafeHandle handle, out bool flag); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_text_input")] + internal static extern NotificationError SetPlaceHolderLength(NotificationSafeHandle handle, int length); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_text_input_max_length")] + internal static extern NotificationError GetPlaceHolderLength(NotificationSafeHandle handle, out int length); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_hide_timeout")] + internal static extern NotificationError GetHideTime(NotificationSafeHandle handle, out int timeout); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_hide_timeout")] + internal static extern NotificationError SetHideTime(NotificationSafeHandle handle, int timeout); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_delete_timeout")] + internal static extern NotificationError GetDeleteTime(NotificationSafeHandle handle, out int timeout); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_delete_timeout")] + internal static extern NotificationError SetDeleteTime(NotificationSafeHandle handle, int timeout); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_extension_image_size")] + internal static extern NotificationError SetBigPictureSize(NotificationSafeHandle handle, int size); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_extension_image_size")] + internal static extern NotificationError GetBigPictureSize(NotificationSafeHandle handle, out int size); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_extention_data")] + internal static extern NotificationError SetExtentionData(NotificationSafeHandle handle, string key, SafeBundleHandle bundleHandle); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_extention_data")] + internal static extern NotificationError GetExtentionData(NotificationSafeHandle handle, string key, out SafeBundleHandle bundleHandle); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_args")] + internal static extern NotificationError GetExtentionBundle(NotificationSafeHandle handle, out IntPtr args, out IntPtr group_args); + + internal static NotificationError GetText(NotificationSafeHandle handle, NotificationText type, out string text) + { + NotificationError ret; + IntPtr ptr; + ret = GetTextReferenceType(handle, type, out ptr); + + if (ptr == IntPtr.Zero) + { + text = null; + } + else + { + text = Marshal.PtrToStringAnsi(ptr); + } + + return ret; + } - internal sealed class SafeNotificationHandle : SafeHandle + internal static NotificationError GetImage(NotificationSafeHandle handle, NotificationImage type, out string path) { - public SafeNotificationHandle() - : base(IntPtr.Zero, true) + NotificationError ret; + IntPtr ptr; + ret = GetImageReferenceType(handle, type, out ptr); + + if (ptr == IntPtr.Zero) + { + path = null; + } + else { + path = Marshal.PtrToStringAnsi(ptr); } - public override bool IsInvalid + return ret; + } + + internal static NotificationError GetSound(NotificationSafeHandle handle, out AccessoryOption type, out string path) + { + NotificationError ret; + IntPtr ptr; + ret = GetSoundReferenceType(handle, out type, out ptr); + + if (ptr == IntPtr.Zero) { - get { return this.handle == IntPtr.Zero; } + path = null; } + else + { + path = Marshal.PtrToStringAnsi(ptr); + } + + return ret; + } - protected override bool ReleaseHandle() + internal static NotificationError GetVibration(NotificationSafeHandle handle, out AccessoryOption type, out string path) + { + NotificationError ret; + IntPtr ptr; + ret = GetVibrationReferenceType(handle, out type, out ptr); + + if (ptr == IntPtr.Zero) + { + path = null; + } + else + { + path = Marshal.PtrToStringAnsi(ptr); + } + + return ret; + } + + internal static NotificationError GetTag(NotificationSafeHandle handle, out string tag) + { + NotificationError ret; + IntPtr ptr; + ret = GetTagReferenceType(handle, out ptr); + + if (ptr == IntPtr.Zero) { - Notification.Destroy(this.handle); - this.SetHandle(IntPtr.Zero); - return true; + tag = null; } + else + { + tag = Marshal.PtrToStringAnsi(ptr); + } + + return ret; } } } diff --git a/src/Tizen.Applications.Notification/Properties/AssemblyInfo.cs b/src/Tizen.Applications.Notification/Properties/AssemblyInfo.cs index 8cc714d..9a545d3 100755 --- a/src/Tizen.Applications.Notification/Properties/AssemblyInfo.cs +++ b/src/Tizen.Applications.Notification/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using System.Runtime.InteropServices; diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notification.csproj b/src/Tizen.Applications.Notification/Tizen.Applications.Notification.csproj index 3dece70..b2abd7b 100755 --- a/src/Tizen.Applications.Notification/Tizen.Applications.Notification.csproj +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notification.csproj @@ -1,4 +1,4 @@ - + Debug @@ -48,12 +48,25 @@ - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notification.project.json b/src/Tizen.Applications.Notification/Tizen.Applications.Notification.project.json index 55ec093..9eb5df1 100755 --- a/src/Tizen.Applications.Notification/Tizen.Applications.Notification.project.json +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notification.project.json @@ -1,9 +1,9 @@ { "dependencies": { - "NETStandard.Library": "1.6.0", - "Tizen": "1.0.2" + "NETStandard.Library": "1.6.1", + "Tizen": "1.0.3" }, "frameworks": { "netstandard1.3": {} } -} +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/Notification.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/Notification.cs new file mode 100755 index 0000000..6ea56b6 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/Notification.cs @@ -0,0 +1,506 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using System; + using System.Collections.Generic; + using System.ComponentModel; + + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification : IDisposable + { + internal static readonly string LogTag = "Tizen.Applications.Notification"; + + private NotificationSafeHandle safeHandle; + private bool disposed = false; + + private IDictionary styleDictionary; + private IDictionary extenderDictionary; + private int count = 0; + + /// + /// Initializes a new instance of the class. + /// + public Notification() + { + styleDictionary = new Dictionary(); + extenderDictionary = new Dictionary(); + } + + /// + /// Gets or sets Tag of Notification. + /// + public string Tag { get; set; } = string.Empty; + + /// + /// Gets or sets Title of Notification. + /// + public string Title { get; set; } = string.Empty; + + /// + /// Gets or sets icon of Notification. + /// + public string Icon { get; set; } = string.Empty; + + /// + /// Gets or sets sub icon of Notification. + /// This SubIcon is displayed in Icon you set. + /// + public string SubIcon { get; set; } = string.Empty; + + /// + /// Gets or sets content of Notification. + /// + public string Content { get; set; } = string.Empty; + + /// + /// Gets or sets a value indicating whether TimeStamp of Notification is Visible or not. + /// Default to true. + /// + public bool IsTimeStampVisible { get; set; } = true; + + /// + /// Gets or sets TimeStamp of Notification. + /// + /// + /// If you don't set TimeStamp, It will be set value that time when the notification is posted. + /// TimeStamp requires NotificationManager.Post() to be called. + /// If you set IsVisibleTimeStamp property is false, TimeStamp is not Visible in Notification. + /// + public DateTime TimeStamp { get; set; } + + /// + /// Gets or sets Action which is invoked when notification is clicked + /// + /// + /// If you set it to null, the already set AppControl will be removed and nothing will happen when you click on notification. + /// + /// + public AppControl Action { get; set; } + + /// + /// Gets or sets Count which is displayed at the right side of notification. + /// + /// + /// You must set only positive number. + /// If you set count to negative number, This property throw exception. + /// + /// Thrown when argument is invalid + public int Count + { + get + { + return count; + } + + set + { + if (value < 0) + { + Log.Error(LogTag, "Count value is negative"); + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The Count must be a positive integer."); + } + + count = value; + } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsOngoing { get; set; } = false; + + /// + /// Gets or sets property + /// + /// + public NotificationProperty Property { get; set; } = NotificationProperty.None; + + /// + /// Gets or sets object for display at notification + /// + /// + public ProgressType Progress { get; set; } + + /// + /// Gets or sets which is included vibration, led and sound option to be applied at Notification. + /// + /// + /// If you set it to null, the already set AccessorySet will be initialized. + /// + /// + /// + /// Notification notification = new Notification + /// { + /// Title = "Notification", + /// Content = "Hello Tizen", + /// Icon = "Icon path", + /// Count = 3 + /// }; + /// + /// Notification.AccessorySet accessory = new Notification.AccessorySet + /// { + /// SoundOption = AccessoryOption.Custom, + /// SoundPath = "Sound File Path", + /// IsVibration = true, + /// LedOption = AccessoryOption.Custom, + /// LedOnMs = 100; + /// LedOffMs = 50; + /// LedColor = Color.Lime + /// }; + /// + /// notification.Accessory = accessory; + /// + /// NotificationManager.Post(notification); + /// + /// + public AccessorySet Accessory { get; set; } + + /// + /// Gets or sets a value indicating whether notification is displayed on default viewer. + /// If you set false and add style, you can see only style notification. + /// + public bool IsDisplay { get; set; } = true; + + /// + /// Gets or sets NotificationSafeHandle + /// + internal NotificationSafeHandle Handle + { + get + { + return safeHandle; + } + + set + { + if (value == null) + { + Log.Error(LogTag, "Invalid argument NotificationSafeHandle"); + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to set NotificationSafeHandle"); + } + + safeHandle = value; + } + } + + /// + /// Gets or sets Private ID + /// + internal int PrivID { get; set; } = -1; + + /// + /// Method to add various style to be applied to notification. + /// + /// + /// The user always see about valid notification style. If you add style which is not supported in platform, + /// this method has no effect. + /// + /// The style to be applied to notification + /// Thrown when argument is invalid + /// + /// + /// Notification notification = new Notification + /// { + /// Title = "Notification", + /// Content = "Hello Tizen", + /// Icon = "Icon path", + /// Count = 3 + /// }; + /// + /// Notification.LockStyle lockStyle = new Notification.LockStyle + /// { + /// IconPath = "Icon path", + /// ThumbnailPath = "Thumbnail Path" + /// }; + /// + /// notification.AddStyle(lockStyle); + /// + /// NotificationManager.Post(notification); + /// + /// + public void AddStyle(StyleBase style) + { + if (style == null) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + + if (styleDictionary.ContainsKey(style.Key) == true) + { + Log.Info(LogTag, "The Style is existed, so extender data is replaced"); + styleDictionary.Remove(style.Key); + styleDictionary.Add(style.Key, style); + } + else + { + styleDictionary.Add(style.Key, style); + } + } + + /// + /// Method to remove style you already added. + /// + /// Type of notification style to be queried + /// Thrown when argument is invalid + public void RemoveStyle() where T : Notification.StyleBase, new() + { + T type = new T(); + + if (styleDictionary.ContainsKey(type.Key)) + { + styleDictionary.Remove(type.Key); + } + else + { + Log.Error(LogTag, "Sytle Can't be removed, there is no style matched input key"); + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + } + + /// + /// Method to get style you already added. + /// + /// Type of notification style to be queried + /// + /// The Notification.Style object associated with the given style + /// + /// Thrown when argument is invalid + public T GetStyle() where T : Notification.StyleBase, new() + { + T type = new T(); + StyleBase style = null; + + styleDictionary.TryGetValue(type.Key, out style); + + if (style == null) + { + Log.Error(LogTag, "Invalid Style"); + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + else + { + return style as T; + } + } + + /// + /// Method to set extender data to add extra data + /// + /// + /// The type of extra data is Bundle. + /// + /// The key of the extra data you want to add. + /// The value you want to add. + /// Thrown when argument is invalid + /// + /// + /// Notification notification = new Notification + /// { + /// Title = "Notification", + /// Content = "Hello Tizen", + /// Icon = "Icon path", + /// }; + /// + /// Bundle bundle = new Bundle(); + /// bundle.AddItem("key", "value"); + /// + /// notification.SetExtender("firstKey", bundle); + /// + /// + public void SetExtender(string key, Bundle value) + { + if (value == null || value.SafeBundleHandle.IsInvalid || string.IsNullOrEmpty(key)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + + if (extenderDictionary.ContainsKey(key) == true) + { + Log.Info(LogTag, "The key is existed, so extender data is replaced"); + extenderDictionary.Remove(key); + extenderDictionary.Add(key, value); + } + else + { + extenderDictionary.Add(key, value); + } + } + + /// + /// Method to remove extender you already added. + /// + /// + /// The type of extra data is Bundle. + /// + /// The key of the extra data to add. + /// Thrown when argument is invalid + public void RemoveExtender(string key) + { + if (string.IsNullOrEmpty(key)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + + if (extenderDictionary.ContainsKey(key)) + { + extenderDictionary.Remove(key); + } + else + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + } + + /// + /// Method to get extender data you already set + /// + /// The key of the extra data to get. + /// Bundle Object that include extender data + /// Thrown when argument is invalid + public Bundle GetExtender(string key) + { + if (string.IsNullOrEmpty(key)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + + Bundle bundle; + if (extenderDictionary.TryGetValue(key, out bundle) == false) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered : " + key); + } + + return bundle; + } + + /// + /// Releases any unmanaged resources used by this object. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + internal void Dispose(bool disposing) + { + if (disposed) + { + return; + } + + if (disposing) + { + Handle.Dispose(); + } + + disposed = true; + } + + internal IDictionary GetStyleDictionary() + { + return styleDictionary; + } + + internal IDictionary GetExtenderDictionary() + { + return extenderDictionary; + } + + internal StyleBase GetStyle(string key) + { + if (string.IsNullOrEmpty(key)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "Key is null or empty"); + } + + StyleBase style = null; + bool ret = styleDictionary.TryGetValue(key, out style); + if (ret == false) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The Style object matched input key is not existed"); + } + + return style; + } + + internal void Make() + { + NotificationBinder.BindObject(this); + + foreach (string key in GetExtenderDictionary().Keys) + { + Log.Info(LogTag, "Start to bind Notification.ExtenderData to SafeHandle"); + Interop.Notification.SetExtentionData(Handle, key, extenderDictionary[key].SafeBundleHandle); + } + + foreach (Notification.StyleBase style in styleDictionary.Values) + { + Log.Info(LogTag, "Start to bind Notification.Style to SafeHandle [" + style.Key + "]"); + style.Make(this); + } + + if (Accessory != null) + { + Log.Info(LogTag, "Start to bind Notification.AccessetSet to SafeHandle"); + Accessory.Make(this); + } + + if (Progress != null) + { + Log.Info(LogTag, "Start to bind Notification.Progress to SafeHandle"); + Progress.Make(this); + } + } + + internal Notification Build() + { + IntPtr extention = IntPtr.Zero; + IntPtr extentionBundlePtr = IntPtr.Zero; + + NotificationBinder.BindSafeHandle(this); + + Interop.Notification.GetExtentionBundle(Handle, out extention, out extentionBundlePtr); + + if (extention != IntPtr.Zero) + { + Bundle bundle = new Bundle(new SafeBundleHandle(extention, false)); + foreach (string key in bundle.Keys) + { + SafeBundleHandle sbh; + Interop.Notification.GetExtentionData(Handle, key, out sbh); + extenderDictionary.Add(key, new Bundle(sbh)); + } + } + + ProgressBinder.BindSafeHandle(this); + AccessorySetBinder.BindSafeHandle(this); + IndicatorBinder.BindSafeHandle(this); + ActiveBinder.BindSafeHandle(this); + LockBinder.BindSafehandle(this); + BigPictureBinder.BindSafeHandle(this); + + return this; + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationAccessorySet.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationAccessorySet.cs new file mode 100755 index 0000000..ec7958d --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationAccessorySet.cs @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using Tizen.Common; + + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// Class for Notification AccessorySet which is included vibration, led, sound option + /// + public sealed class AccessorySet : MakerBase + { + /// + /// Gets or sets the sound option. Default to AccessoryOption.Off. + /// + /// + /// If you set AccessoryOption.Custom and not set SoundPath, then turn on the default sound. + /// + public AccessoryOption SoundOption { get; set; } = AccessoryOption.Off; + + /// + /// Gets or sets the sound path, It will play on the sound file you set. + /// + public string SoundPath { get; set; } + + /// + /// Gets or sets a value indicating whether vibration is operated. Default to false. + /// + public bool CanVibrate { get; set; } = false; + + /// + /// Gets or sets the led option. Default to AccessoryOption.Off. + /// + /// + /// If you set AccessoryOption.Custom and not set LedColor, then turn on the LED with default color. + /// + public AccessoryOption LedOption { get; set; } = AccessoryOption.Off; + + /// + /// Gets or sets the led on time period that you would like the LED on the device to blink. as well as the rate + /// + /// + /// Default value of LedOnMillisecond is 0. + /// The rate is specified in terms of the number of Milliseconds to be on. + /// You should always set LedOnMillisecond with LedOffMillisecond. Otherwise, it may not operate normally. + /// + public int LedOnMillisecond { get; set; } + + /// + /// Gets or sets the led on time period that you would like the LED on the device to blink. as well as the rate. + /// + /// + /// The rate is specified in terms of the number of Milliseconds to be off. + /// You should always set LedOffMillisecond with LedOnMillisecond. Otherwise, it may not operate normally. + /// + public int LedOffMillisecond { get; set; } + + /// + /// Gets or sets the led color that you would like the LED on the device to blink. + /// + /// + /// If you want to set LedColor, you should always set LedOption is AccessoryOption.Custom. Otherwise, it may operate default led color. + /// + public Color LedColor { get; set; } + + internal override void Make(Notification notification) + { + AccessorySetBinder.BindObject(notification); + } + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationAccessorySetBinder.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationAccessorySetBinder.cs new file mode 100755 index 0000000..91e2282 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationAccessorySetBinder.cs @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using Tizen.Common; + + internal static class AccessorySetBinder + { + internal static void BindObject(Notification notification) + { + BindLedToHandle(notification); + BindSoundToHandle(notification); + BindVibrationToHandle(notification); + } + + internal static void BindSafeHandle(Notification notification) + { + Notification.AccessorySet accessory = new Notification.AccessorySet(); + BindHandleToLed(notification, accessory); + BindHandleToSound(notification, accessory); + BindHandleToVibration(notification, accessory); + notification.Accessory = accessory; + } + + private static void BindLedToHandle(Notification notification) + { + NotificationError ret = NotificationError.None; + Notification.AccessorySet accessory = notification.Accessory; + + ret = Interop.Notification.SetLed(notification.Handle, accessory.LedOption, 0); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set led"); + } + + ret = Interop.Notification.SetLedTimePeriod(notification.Handle, accessory.LedOnMillisecond, accessory.LedOffMillisecond); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set led period"); + } + + if (notification.Accessory.LedOption == AccessoryOption.Custom) + { + Color color = accessory.LedColor; + ret = Interop.Notification.SetLed(notification.Handle, AccessoryOption.Custom, color.GetArgb()); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set led color"); + } + } + } + + private static void BindVibrationToHandle(Notification notification) + { + Notification.AccessorySet accessory = notification.Accessory; + if (accessory.CanVibrate == false) + { + Interop.Notification.SetVibration(notification.Handle, AccessoryOption.Off, null); + } + else + { + Interop.Notification.SetVibration(notification.Handle, AccessoryOption.On, null); + } + } + + private static void BindSoundToHandle(Notification notification) + { + Notification.AccessorySet accessory = notification.Accessory; + + if (accessory.SoundOption == AccessoryOption.Custom && string.IsNullOrEmpty(accessory.SoundPath)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "If the option is set to Custom, the path must also be set."); + } + + NotificationError ret = Interop.Notification.SetSound(notification.Handle, accessory.SoundOption, accessory.SoundPath); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set sound"); + } + } + + private static void BindHandleToLed(Notification notification, Notification.AccessorySet accessory) + { + AccessoryOption type; + int argb; + Interop.Notification.GetLed(notification.Handle, out type, out argb); + + accessory.LedOption = type; + if (type == AccessoryOption.Custom) + { + accessory.LedColor = new Color(argb >> 16 & 255, argb >> 8 & 255, argb >> 0 & 255, argb >> 24 & 255); + } + + int onMillisecond, offMillisecond; + Interop.Notification.GetLedTimePeriod(notification.Handle, out onMillisecond, out offMillisecond); + accessory.LedOnMillisecond = onMillisecond; + accessory.LedOffMillisecond = offMillisecond; + } + + private static void BindHandleToSound(Notification notification, Notification.AccessorySet accessory) + { + AccessoryOption type; + string path; + + Interop.Notification.GetSound(notification.Handle, out type, out path); + + accessory.SoundOption = type; + if (type == AccessoryOption.Custom) + { + accessory.SoundPath = path; + } + } + + private static void BindHandleToVibration(Notification notification, Notification.AccessorySet accessory) + { + AccessoryOption type; + string path; + + Interop.Notification.GetVibration(notification.Handle, out type, out path); + if (type == AccessoryOption.Off) + { + accessory.CanVibrate = false; + } + else + { + accessory.CanVibrate = true; + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationActiveStyle.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationActiveStyle.cs new file mode 100755 index 0000000..a9a1aa4 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationActiveStyle.cs @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using System.Collections.Generic; + + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// Class for generating Active style notification + /// + public sealed class ActiveStyle : StyleBase + { + private IDictionary buttonDictionary; + private int hideTimeout = 0; + private int deleteTimeout = 0; + + /// + /// Initializes a new instance of the class. + /// + public ActiveStyle() + { + buttonDictionary = new Dictionary(); + } + + /// + /// Gets or sets an absolute path for an image file to display on the background of active notification + /// + public string BackgroundImage { get; set; } + + /// + /// Gets or sets a value indicating whether the active notification is removed automatically. Default value is true. + /// + /// + /// IsAutoRemove option lets the active notification be removed several seconds after it shows. + /// When 'IsAutoRemove' is set as false, the active notification will not be removed as long as the user removes + /// the active notification or the app which posted the active notification removes the active notification. + /// > + public bool IsAutoRemove { get; set; } = true; + + /// + /// Gets or sets a ReplyAction to this active notification style. + /// + /// + /// When you add a ReplyAction to the ActiveStyle, the notification UI will show a ReplyAction with button. + /// If you set null parameter, ReplyAction is disappeared. + /// + /// + /// + /// + /// ButtonAction button = new ButtonAction + /// { + /// Index = ButtonIndex.First, + /// Text = "Yes" + /// Action = new AppControl{ ApplicationId = "org.tizen.app" }; + /// }; + /// + /// ReplyAction reply = new ReplyAction + /// { + /// ParentIndex = ButtonIndex.First; + /// PlaceHolderText = "Please write your reply." + /// ReplyMax = 160, + /// Button = new ButtonAction + /// { + /// Text = "Yes", + /// ImagePath = "image path" + /// Action = new AppControl{ ApplicationId = "org.tizen.app" }; + /// }; + /// }; + /// + /// ActiveStyle active = new ActiveStyle + /// { + /// AutoRemove = true, + /// BackgroundImage = "image path", + /// ReplyAction = reply + /// }; + /// + /// active.AddButtonAction(button); + /// + /// + public ReplyAction ReplyAction { get; set; } + + /// + /// Gets the key of ActiveStyle + /// + internal override string Key + { + get + { + return "Active"; + } + } + + /// + /// Method to set times to hide or delete notification. + /// + /// + /// The time settings for hiding and deleting are only reflected on Tizen TV. + /// If you use this API on other profile, this time settings have no effect + /// + /// The value in second when the notification can be hidden from the notification viewer after notification is posted + /// The value in second when the notification can be deleted from the notification list in setting application after notification is posted + /// Thrown when argument is invalid + public void SetRemoveTime(int hideTime, int deleteTime) + { + if (hideTime < 0 || deleteTime < 0) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument"); + } + + hideTimeout = hideTime; + deleteTimeout = deleteTime; + } + + /// + /// Method to get times to hide or delete notification. + /// + /// The value in second when the notification can be hidden from the notification viewer after notification is posted + /// The value in second when the notification can be deleted from the notification list in setting application after notification is posted + public void GetRemoveTime(out int hideTime, out int deleteTime) + { + hideTime = hideTimeout; + deleteTime = deleteTimeout; + } + + /// + /// Method to add a button to the active notification style. + /// Buttons are displayed on the notification. + /// + /// + /// If you add button that has same index, the button is replaced to latest adding button. + /// If you don't set an index on ButtonAction, the index is set sequentially from zero. + /// + /// An ButtonAction for appear to the notification + /// Thrown when argument is invalid + /// + /// + /// + /// ButtonAction button = new ButtonAction + /// { + /// Index = 0, + /// Text = "Yes" + /// Action = new AppControl{ ApplicationId = "org.tizen.app" }; + /// }; + /// + /// ActiveStyle active = new ActiveStyle + /// { + /// IsAutoRemove = true, + /// BackgroundImage = "image path", + /// }; + /// + /// active.AddButtonAction(button); + /// + /// + /// + public void AddButtonAction(ButtonAction button) + { + if (button == null) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid ButtonAction object"); + } + + if (button.Index == ButtonIndex.None) + { + button.Index = (ButtonIndex)buttonDictionary.Count; + buttonDictionary.Add(button.Index, button); + } + else if (button.Index >= ButtonIndex.First) + { + if (buttonDictionary.ContainsKey(button.Index)) + { + buttonDictionary.Remove(button.Index); + } + + buttonDictionary.Add(button.Index, button); + } + } + + /// + /// Remove the ButtonAction you already add. + /// + /// The index to remove a button + /// true if the element is successfully found and removed; otherwise, false + /// Thrown when argument is invalid + public bool RemoveButtonAction(ButtonIndex index) + { + bool ret = buttonDictionary.Remove(index); + + if (ret == false) + { + Log.Debug(Notification.LogTag, "Invalid key, there is no button matched input index"); + } + else + { + Log.Debug(Notification.LogTag, "The button was removed."); + } + + return ret; + } + + /// + /// Gets the ButtonAction of the active notification. + /// + /// The index to get a button you already add + /// The ButtonAction object which is you already add + /// Thrown when argument is invalid + public ButtonAction GetButtonAction(ButtonIndex index) + { + ButtonAction button = null; + + if (buttonDictionary.ContainsKey(index) == true) + { + buttonDictionary.TryGetValue(index, out button); + } + else + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value is not existed."); + } + + return button; + } + + internal ICollection GetButtonAction() + { + return buttonDictionary.Values; + } + + internal override void Make(Notification notification) + { + ActiveBinder.BindObject(notification); + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBigPictureStyle.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBigPictureStyle.cs new file mode 100755 index 0000000..416405c --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBigPictureStyle.cs @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// Class for generating BigPicture style notification + /// + public sealed class BigPictureStyle : StyleBase + { + /// + /// Gets or sets the absolute path for a big picture image file to display on BigPicture style of the notification. + /// + public string ImagePath { get; set; } + + /// + /// Gets or sets the absolute path for a big picture image size to display on BigPicture style of the notification. + /// + /// + /// This value is only height size. + /// > + public int ImageSize { get; set; } + + /// + /// Gets or sets the content text to display on BigPicture style of the notification. + /// + public string Content { get; set; } + + /// + /// Gets the key of BigPictureStyle + /// + internal override string Key + { + get + { + return "BigPicture"; + } + } + + internal override void Make(Notification notification) + { + BigPictureBinder.BindObject(notification); + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBinder.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBinder.cs new file mode 100755 index 0000000..2d7eb4b --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBinder.cs @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using System; + + internal static class NotificationBinder + { + private static readonly int DoNotShowTimeStamp = -1; + + internal static void BindObject(Notification notification) + { + BindNotificationSafeHandle(notification); + BindNotificationText(notification); + BindNotificationTime(notification); + + Interop.Notification.SetID(notification.Handle, notification.PrivID); + + if (notification.IsDisplay) + { + Interop.Notification.SetApplist(notification.Handle, (int)NotificationDisplayApplist.Tray); + } + else + { + Interop.Notification.SetApplist(notification.Handle, 0); + } + + if (notification.IsOngoing == true) + { + Log.Info(Notification.LogTag, "Start to set IsOngoing to SafeHandle"); + Interop.Notification.SetLayout(notification.Handle, NotificationLayout.Ongoing); + Interop.Notification.SetOngoingFlag(notification.Handle, true); + } + + if (string.IsNullOrEmpty(notification.Tag) != true) + { + Interop.Notification.SetTag(notification.Handle, notification.Tag); + } + + if (notification.Action != null && notification.Action.SafeAppControlHandle.IsInvalid == false) + { + Interop.Notification.SetAppControl(notification.Handle, LaunchOption.AppControl, notification.Action.SafeAppControlHandle); + } + + Interop.Notification.SetProperties(notification.Handle, (int)notification.Property); + } + + internal static void BindSafeHandle(Notification notification) + { + int privID, groupID; + Interop.Notification.GetID(notification.Handle, out groupID, out privID); + notification.PrivID = privID; + + NotificationLayout layout; + Interop.Notification.GetLayout(notification.Handle, out layout); + NotificationType type; + Interop.Notification.GetType(notification.Handle, out type); + if (layout == NotificationLayout.Ongoing && type == NotificationType.Ongoing) + { + notification.IsOngoing = true; + } + + int appList; + Interop.Notification.GetApplist(notification.Handle, out appList); + if ((appList & (int)NotificationDisplayApplist.Tray) == 0) + { + notification.IsDisplay = false; + } + + BindSafeHandleText(notification); + BindSafeHandleTime(notification); + BindSafeHandleTag(notification); + BindSafeHandleAction(notification); + } + + private static void BindNotificationSafeHandle(Notification notification) + { + IntPtr ptr; + NotificationError ret; + + if (notification.Handle != null && notification.Handle.IsInvalid == false) + { + notification.Handle.Dispose(); + } + + if (notification.IsOngoing == true || notification.Progress != null) + { + ptr = Interop.Notification.Create(NotificationType.Ongoing); + } + else + { + ptr = Interop.Notification.Create(NotificationType.Basic); + } + + if (ptr == IntPtr.Zero) + { + ret = (NotificationError)Tizen.Internals.Errors.ErrorFacts.GetLastResult(); + throw NotificationErrorFactory.GetException(ret, "Unable to create IntPtr Notification"); + } + + notification.Handle = new NotificationSafeHandle(ptr, true); + } + + private static void BindNotificationText(Notification notification) + { + Interop.Notification.SetText(notification.Handle, NotificationText.Title, notification.Title, null, -1); + Interop.Notification.SetText(notification.Handle, NotificationText.Content, notification.Content, null, -1); + Interop.Notification.SetImage(notification.Handle, NotificationImage.Icon, notification.Icon); + Interop.Notification.SetImage(notification.Handle, NotificationImage.SubIcon, notification.SubIcon); + Interop.Notification.SetText(notification.Handle, NotificationText.EventCount, notification.Count.ToString(), null, -1); + } + + private static void BindNotificationTime(Notification notification) + { + if (notification.IsTimeStampVisible == true) + { + if (notification.TimeStamp != DateTime.MinValue) + { + TimeSpan datatime = notification.TimeStamp.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + Interop.Notification.SetTime(notification.Handle, (int)datatime.TotalSeconds); + } + } + else + { + Interop.Notification.SetTime(notification.Handle, DoNotShowTimeStamp); + } + } + + private static void BindSafeHandleText(Notification notification) + { + string text; + Interop.Notification.GetText(notification.Handle, NotificationText.Title, out text); + if (string.IsNullOrEmpty(text) == false) + { + notification.Title = text; + } + + Interop.Notification.GetText(notification.Handle, NotificationText.Content, out text); + if (string.IsNullOrEmpty(text) == false) + { + notification.Content = text; + } + + string path; + Interop.Notification.GetImage(notification.Handle, NotificationImage.Icon, out path); + if (string.IsNullOrEmpty(path) == false) + { + notification.Icon = path; + } + + Interop.Notification.GetImage(notification.Handle, NotificationImage.SubIcon, out path); + if (string.IsNullOrEmpty(path) == false) + { + notification.SubIcon = path; + } + + Interop.Notification.GetText(notification.Handle, NotificationText.EventCount, out text); + if (string.IsNullOrEmpty(text) == false) + { + try + { + notification.Count = int.Parse(text); + } + catch (Exception ex) + { + Log.Error(Notification.LogTag, ex.ToString()); + } + } + } + + private static void BindSafeHandleTime(Notification notification) + { + int time; + + Interop.Notification.GetTime(notification.Handle, out time); + + if (time == DoNotShowTimeStamp) + { + notification.IsTimeStampVisible = false; + } + else + { + notification.IsTimeStampVisible = true; + + if (time != 0) + { + notification.TimeStamp = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local)).AddSeconds(time).ToLocalTime(); + } + } + } + + private static void BindSafeHandleTag(Notification notification) + { + string text; + Interop.Notification.GetTag(notification.Handle, out text); + if (string.IsNullOrEmpty(text) != true) + { + notification.Tag = text; + } + } + + private static void BindSafeHandleProperty(Notification notification) + { + int property; + Interop.Notification.GetProperties(notification.Handle, out property); + notification.Property = (NotificationProperty)property; + } + + private static void BindSafeHandleAction(Notification notification) + { + SafeAppControlHandle appcontrol = null; + Interop.Notification.GetAppControl(notification.Handle, LaunchOption.AppControl, out appcontrol); + if (appcontrol != null && appcontrol.IsInvalid == false) + { + notification.Action = new AppControl(appcontrol); + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationButtonAction.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationButtonAction.cs new file mode 100755 index 0000000..b783db4 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationButtonAction.cs @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// Class to help you set button on Active style of Notification + /// + /// + /// It must include a Text, an Index, an ImagePath, and an Action to be invoked when user select the button. + /// > + public sealed class ButtonAction : MakerBase + { + /// + /// Gets or sets the index of Button which is appeared at Notification. + /// + public ButtonIndex Index { get; set; } = ButtonIndex.None; + + /// + /// Gets or sets the text describing the button + /// + public string Text { get; set; } + + /// + /// Gets or sets the image path that represent the button + /// + public string ImagePath { get; set; } + + /// + /// Gets or sets the action which is invoked when button is clicked + /// + /// + /// If you don't set Action, nothing happens when button is clicked. + /// + /// Thrown when argument is invalid + /// + /// + /// ButtonAction button = new ButtonAction + /// { + /// Index = ButtonIndex.First, + /// text = "Yes", + /// ImagePath = "image path", + /// Action = new AppControl{ ApplicationId = "org.tizen.app" }; + /// }; + /// + /// + /// + public AppControl Action { get; set; } + + internal override void Make(Notification notification) + { + int enumIndex = (int)NotificationText.FirstButton + (int)Index; + + Interop.Notification.SetText(notification.Handle, (NotificationText)enumIndex, Text, null, -1); + enumIndex = (int)NotificationImage.FirstButton + (int)Index; + Interop.Notification.SetImage(notification.Handle, (NotificationImage)enumIndex, ImagePath); + if (Action != null && Action.SafeAppControlHandle.IsInvalid == false) + { + Interop.Notification.SetEventHandler(notification.Handle, (int)Index, Action.SafeAppControlHandle); + } + } + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationEnumerations.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationEnumerations.cs new file mode 100755 index 0000000..162e032 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationEnumerations.cs @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using System; + + /// + /// Enumeration for Progress category + /// + public enum ProgressCategory + { + /// + /// Value for percent type + /// + Percent, + + /// + /// Value for time type + /// + Time, + + /// + /// Value for pending type which is not updated progress current value + /// + PendingBar + } + + /// + /// Enumeration for Accessory option + /// + public enum AccessoryOption + { + /// + /// Value for off accessory option + /// + Off = -1, + + /// + /// Value for on accessory option + /// + On, + + /// + /// Value for custom accessory option + /// + Custom + } + + /// + /// Enumeration for Button Index + /// + public enum ButtonIndex + { + /// + /// Value for default button index + /// + None = -1, + + /// + /// Value for first button index + /// + First, + + /// + /// Value for second button index + /// + Second, + + /// + /// Value for third button index + /// + Third + } + + /// + /// Enumeration for notification particular property + /// + [Flags] + public enum NotificationProperty + { + /// + /// Value for adjust nothing + /// + None = 0x00, + + /// + /// Value for display only SIM card inserted + /// + DisplayOnlySimmode = 0x01, + + /// + /// Value for disable application launch when it selected + /// + DisableAppLaunch = 0x02, + + /// + /// Value for disable auto delete when it selected + /// + DisableAutoDelete = 0x04, + + /// + /// Value for deleted when device is rebooted even though notification is not set Ongoing + /// + VolatileDisplay = 0x100 + } + + /// + /// Enumeration for block state + /// + public enum NotificationBlockState + { + /// + /// Value to check the app is allowed to post notification + /// + Allowed = 0, + + /// + /// Value to check the app is not allowed to post any notification + /// + Blocked, + + /// + /// Value to check do not disturb mode which is user set + /// + DoNotDisturb + } + + internal enum NotificationType + { + None = -1, + Basic = 0, + Ongoing, + } + + internal enum NotificationEventType + { + FirstButton = 0, + SecondButton, + ThirdButton, + ClickOnIcon = 6, + ClockOnThumbnail = 7, + ClickOnTextInputButton = 8 + } + + internal enum NotificationLayout + { + None = 0, + SingleEvent = 1, + Thumbnail = 3, + Ongoing = 4, + Progress = 5, + Extension = 6 + } + + internal enum NotificationText + { + Title = 0, + Content, + EventCount = 3, + FirstMainText, + FirstSubText, + SecondMainText, + SecondSubText, + FirstButton = 13, + SeceondButton = 14, + ThirdButton = 15, + PlaceHolder = 19, + InputButton = 20, + BigPicture = 21, + } + + internal enum NotificationImage + { + Icon = 0, + IconForIndicator, + IconForLock, + Thumbnail, + ThumbnailForLock, + SubIcon, + Background, + FirstButton = 12, + SecondButton, + ThirdButton, + TextInputButton = 18, + BigPicture = 19, + } + + internal enum LaunchOption + { + AppControl = 1 + } + + [Flags] + internal enum NotificationDisplayApplist + { + Tray = 0x00000001, + Ticker = 0x00000002, + Lock = 0x00000004, + Indicator = 0x00000008, + Active = 0x00000010, + All = 0x0000000f, + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications/NotificationErrorFactory.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationErrorFactory.cs similarity index 75% rename from src/Tizen.Applications.Notification/Tizen.Applications/NotificationErrorFactory.cs rename to src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationErrorFactory.cs index 5ca094f..12f92f3 100755 --- a/src/Tizen.Applications.Notification/Tizen.Applications/NotificationErrorFactory.cs +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationErrorFactory.cs @@ -14,10 +14,11 @@ * limitations under the License. */ -using System; - namespace Tizen.Applications.Notifications { + using System; + using System.Runtime.CompilerServices; + internal enum NotificationError { None = Tizen.Internals.Errors.ErrorCode.None, @@ -35,17 +36,19 @@ namespace Tizen.Applications.Notifications internal static class NotificationErrorFactory { - private const string _logTag = "Tizen.Applications.Notification"; - - internal static Exception GetException(NotificationError ret, string msg) + internal static Exception GetException(NotificationError ret, string msg, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0) { + Log.Error(Notification.LogTag, memberName + " : " + lineNumber); + switch (ret) { case NotificationError.InvalidParameter: - Log.Error(_logTag, msg); + Log.Error(Notification.LogTag, msg); return new ArgumentException(ret + " error occurred."); + case NotificationError.PermissionDenied: + throw new UnauthorizedAccessException("Permission denied (http://tizen.org/privilege/notification)"); default: - Log.Error(_logTag, msg); + Log.Error(Notification.LogTag, msg); return new InvalidOperationException(ret + " error occurred."); } } diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationIndicatorStyle.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationIndicatorStyle.cs new file mode 100755 index 0000000..7e87c84 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationIndicatorStyle.cs @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// Class for generating Indicator style notification + /// + public sealed class IndicatorStyle : StyleBase + { + /// + /// Gets or sets an absolute path for an image file. + /// If you set IconPath, you can see the icon on the right side of indicator. + /// + public string IconPath { get; set; } + + /// + /// Gets or sets a sub text for displaying Indicator style + /// + public string SubText { get; set; } + + /// + /// Gets the key of IndicatorStyle + /// + internal override string Key + { + get + { + return "Indicator"; + } + } + + internal override void Make(Notification notification) + { + IndicatorBinder.BindObject(notification); + } + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationLockStyle.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationLockStyle.cs new file mode 100755 index 0000000..78029a7 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationLockStyle.cs @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// Class for generating Lock style notification + /// + public sealed class LockStyle : StyleBase + { + /// + /// Gets or sets an absolute path for an image file to display on the icon of Lock style + /// + public string IconPath { get; set; } + + /// + /// Gets or sets an absolute path for a thumbnail image file to display on Lock style + /// + public string ThumbnailPath { get; set; } + + /// + /// Gets the key of LockStyle + /// + internal override string Key + { + get + { + return "Lock"; + } + } + + internal override void Make(Notification notification) + { + LockBinder.BindObject(notification); + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationMakerBase.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationMakerBase.cs new file mode 100755 index 0000000..859a81f --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationMakerBase.cs @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using System.ComponentModel; + + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// An object that help notification make to SafeHandle. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class MakerBase + { + internal abstract void Make(Notification notification); + } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs new file mode 100755 index 0000000..ad5a928 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs @@ -0,0 +1,497 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using System; + using System.ComponentModel; + + /// + /// NotificationManager class to post, update, delete and get Notification. + /// + public static class NotificationManager + { + /// + /// Posts a new Notification. + /// + /// Notification to post + /// Thrown when argument is invalid + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// + /// + /// Notification notification = new Notification + /// { + /// Title = "title", + /// Content = "content", + /// Icon = "absolute icon path", + /// Tag = "first notification" + /// }; + /// + /// Notification.AccessorySet accessory = new Notification.AccessorySet + /// { + /// SoundOption = AccessoryOption.On, + /// CanVibrate = true + /// }; + /// notification.Accessory = accessory; + /// + /// // do something + /// + /// NotificationManager.Post(notification); + /// + /// + /// http://tizen.org/privilege/notification + public static void Post(Notification notification) + { + if (notification == null) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); + } + + notification.Make(); + + NotificationError ret = Interop.Notification.Post(notification.Handle); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "post notification failed"); + } + + int priv_id, group_id; + Interop.Notification.GetID(notification.Handle, out group_id, out priv_id); + notification.PrivID = priv_id; + } + + /// + /// Updates a posted Notification. + /// + /// Notification to update + /// Thrown when argument is invalid + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// + /// + /// string tag = "first tag"; + /// + /// Notification notification = new Notification + /// { + /// Title = "title", + /// Content = "content", + /// Icon = "absolute icon path", + /// Tag = tag + /// }; + /// + /// Notification.AccessorySet accessory = new Notification.AccessorySet + /// { + /// LedOption = AccessoryOption.On, + /// VibrationOption = AccessoryOption.Custom, + /// VibrationPath = "vibration absolute path" + /// } + /// notification.Accessory = accessory; + /// + /// NotificationManager.Post(notification); + /// + /// // do something + /// + /// Notification loadNotification = NotificationManager.Load(tag); + /// + /// loadNotification.Progress = new ProgressType(ProgressCategory.Percent, 0.0. 100.0); + /// + /// Thread thread = new Thread(new ParameterizedThreadStart(UpdateProgress)); + /// thread.IsBackground = true; + /// thread.Start(notification); + /// + /// ... + /// + /// static void UpdateProgress(Object obj) + /// { + /// Notification notification = (Notification)obj; + /// + /// for (double current = 1.0; current <= 100.0; current = current + 1.0) + /// { + /// notification.Progress.ProgressCurrent = current; + /// NotificationManager.Update(notification); + /// Thread.Sleep(300); + /// } + /// } + /// + /// + /// http://tizen.org/privilege/notification + ///
+        /// Post method should be called on the Notification object.
+        /// 
+ public static void Update(Notification notification) + { + if (notification == null || notification.Handle == null || notification.Handle.IsInvalid) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); + } + + notification.Make(); + NotificationError ret = Interop.Notification.Update(notification.Handle); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "update notification failed"); + } + } + + /// + /// Deletes a posted Notification. + /// + /// Notification to remove + /// Thrown when argument is invalid + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// + /// + /// Notification notification = new Notification + /// { + /// Title = "title", + /// Content = "content", + /// Icon = "absolute icon path", + /// Tag = "first notification" + /// }; + /// NotificationManager.Post(notification); + /// + /// // do something + /// + /// NotificationManager.Delete(notification); + /// + /// + /// http://tizen.org/privilege/notification + ///
+        /// Post method should be called on the Notification object.
+        /// 
+ public static void Delete(Notification notification) + { + if (notification == null || notification.Handle == null || notification.Handle.IsInvalid) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); + } + + NotificationError ret = Interop.Notification.Delete(notification.Handle); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "delete notification failed"); + } + } + + /// + /// Removes all posted Notification of calling application. + /// + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// + /// + /// Notification firstNotification = new Notification + /// { + /// Title = "title", + /// Content = "content", + /// Icon = "absolute icon path", + /// Tag = "first notification" + /// }; + /// NotificationManager.Post(firstNotification); + /// + /// Notification secondNotification = new Notification + /// { + /// Title = "title", + /// Content = "content", + /// Icon = "absolute icon path", + /// Tag = "second notification" + /// }; + /// NotificationManager.Post(secondNotification); + /// NotificationManager.DeleteAll(); + /// + /// + /// http://tizen.org/privilege/notification + public static void DeleteAll() + { + NotificationError ret; + + ret = Interop.Notification.DeleteAll((int)NotificationType.Basic); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "delete all notifications failed of Noti type"); + } + + ret = Interop.Notification.DeleteAll((int)NotificationType.Ongoing); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "delete all notifications failed of Ongoing type"); + } + } + + /// + /// Searches for a posted notification which has the inputted tag and isn't deleted not yet. + /// + /// + /// Load method should be called only for notifications which have been posted using NotificationManager.Post method. + /// If two or more notifications share the same tag, the notification posted most recently is returned. + /// + /// Tag used to query + /// Notification Object with inputted tag + /// Thrown when argument is invalid or when the tag does not exist + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// + /// + /// Notification notification = new Notification + /// { + /// Title = "title", + /// Content = "content", + /// Icon = "absolute icon path", + /// Tag = "first notification" + /// }; + /// NotificationManager.Post(notification); + /// + /// // do someting + /// + /// Notification loadNotification = NotificationManager.Load("first notification"); + /// + /// + /// http://tizen.org/privilege/notification + public static Notification Load(string tag) + { + IntPtr ptr = IntPtr.Zero; + + if (string.IsNullOrEmpty(tag)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + + ptr = Interop.Notification.Load(tag); + + if (ptr == IntPtr.Zero) + { + NotificationError ret = (NotificationError)Tizen.Internals.Errors.ErrorFacts.GetLastResult(); + Log.Error(Notification.LogTag, "unable to load Notification : " + ret.ToString()); + if (ret == NotificationError.DbError) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "the tag does not exist"); + } + else + { + throw NotificationErrorFactory.GetException(ret, "unable to load Notification"); + } + } + + Notification notification = new Notification + { + Handle = new NotificationSafeHandle(ptr, true) + }.Build(); + + return notification; + } + + /// + /// Saves a notification template to the notification database + /// + /// Notification to save as template + /// Template name + /// Thrown when argument is invalid + /// Thrown in case of permission denied. + /// Thrown when can't save as template + /// + /// + /// Notification notification = new Notification + /// { + /// Title = "title", + /// Content = "content", + /// Icon = "absolute icon path", + /// Tag = "first notification" + /// }; + /// + /// Notification.Accessory accessory = new Notification.Accessory + /// { + /// LedOption = AccessoryOption.On, + /// VibrationOption = AccessoryOption.Custom, + /// VibrationPath = "vibration absolute path" + /// } + /// notification.setAccessory(accessory); + /// + /// // do something + /// + /// NotificationManager.Post(notification); + /// + /// Notification.LockStyle style = new Notification.LockStyle + /// { + /// IconPath = "icon path", + /// ThumbnailPath = "Thumbnail path" + /// } + /// notification.AddStyle(style); + /// NotificationManager.SaveTemplate(notification, "firstTemplate"); + /// + /// + /// http://tizen.org/privilege/notification + public static void SaveTemplate(Notification notification, string name) + { + if (notification == null || string.IsNullOrEmpty(name)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to save template"); + } + + notification.Make(); + + NotificationError ret = Interop.Notification.SaveTemplate(notification.Handle, name); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "save as template failed"); + } + } + + /// + /// Loads a notification template from the notification database + /// + /// Template name + /// Notification Object with inputted template name + /// Thrown when argument is invalid or when no template with input name exists + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// + /// + /// Notification notification = new Notification + /// { + /// Title = "title", + /// Content = "content", + /// Icon = "absolute icon path", + /// Tag = "first notification" + /// }; + /// + /// Notification.Accessory accessory = new Notification.Accessory + /// { + /// LedOption = AccessoryOption.On, + /// VibrationOption = AccessoryOption.Custom, + /// VibrationPath = "vibration absolute path" + /// } + /// notification.setAccessory(accessory); + /// + /// // do something + /// + /// NotificationManager.Post(notification); + /// + /// Notification.LockStyle style = new Notification.LockStyle + /// { + /// IconPath = "icon path", + /// ThumbnailPath = "Thumbnail path" + /// } + /// notification.AddStyle(style); + /// NotificationManager.SaveTemplate(notification, "firstTemplate"); + /// Notification notificationTemplate = NotificationManager.LoadTemplate("firstTemplate"); + /// + /// + /// http://tizen.org/privilege/notification + public static Notification LoadTemplate(string name) + { + IntPtr handle = IntPtr.Zero; + + if (string.IsNullOrEmpty(name)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to load template"); + } + + handle = Interop.Notification.LoadTemplate(name); + if (handle == IntPtr.Zero) + { + NotificationError ret = (NotificationError)Tizen.Internals.Errors.ErrorFacts.GetLastResult(); + if (ret == NotificationError.DbError) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "the name does not exist"); + } + else + { + throw NotificationErrorFactory.GetException(ret, "unable to create Notification from template"); + } + } + + Notification notification = new Notification + { + Handle = new NotificationSafeHandle(handle, true) + }.Build(); + + return notification; + } + + /// + /// Gets notification block state. + /// + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// + /// The user can set the notification block state in settings. + /// The block state indicates whether or not notifications can be posted. + /// Additionally only notifications to the notification panel are allowed in "Do not disturb mode". + /// Sound, Vibrate and Active notifications are blocked. + /// + /// NotificationBlockState is state if notification is posted + /// Thrown when no template with input name exists + /// http://tizen.org/privilege/notification + public static NotificationBlockState GetBlockState() + { + NotificationBlockState state; + NotificationError ret; + + ret = Interop.Notification.GetBlockState(out state); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "GetBlockState failed"); + } + + Log.Info(Notification.LogTag, "Current block state is " + state.ToString()); + return state; + } + + /// + /// Method to get style you already added. + /// + /// Thrown when argument is null + /// Notification to make . + /// + /// The Notification object + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static NotificationSafeHandle MakeNotificationSafeHandle(Notification notification) + { + if (notification == null) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid notification object"); + } + + notification.Make(); + + return notification.Handle; + } + + /// + /// Method to get style you already added. + /// + /// Thrown when argument is null + /// SafeHandle to make Object + /// + /// The Notification object + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static Notification MakeNotification(NotificationSafeHandle handle) + { + if (handle == null || handle.IsInvalid == true) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "handle is invalid or null"); + } + + Notification notification = new Notification { Handle = handle }.Build(); + + return notification; + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationProgress.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationProgress.cs new file mode 100755 index 0000000..3630755 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationProgress.cs @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// Class for displaying progress notification + /// You must initialize progress category, current, max value when you create object. + /// + public sealed class ProgressType : MakerBase + { + private double progressCurrent; + private double progressMax; + + /// + /// Initializes a new instance of the class. + /// You must initialize category, current, max value of progress. + /// + /// The category of progress that appeared on Notification + /// The current value of the progress + /// The max value of the progress + /// Thrown when argument is invalid + public ProgressType(ProgressCategory category, double current, double max) + { + if (IsNegativeNumber(current)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The current must be a positive integer."); + } + + if (IsNegativeNumber(max)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The max must be a positive integer."); + } + + Category = category; + ProgressCurrent = current; + ProgressMax = max; + } + + /// + /// Gets or sets category of ProgressType. + /// + /// + public ProgressCategory Category { get; set; } + + /// + /// Gets or sets current value of ProgressType + /// + /// Thrown when argument is invalid + public double ProgressCurrent + { + get + { + return progressCurrent; + } + + set + { + if (IsNegativeNumber(value)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value must be a positive integer."); + } + + progressCurrent = value; + } + } + + /// + /// Gets or sets max value of ProgressType + /// + /// Thrown when argument is invalid + public double ProgressMax + { + get + { + return progressMax; + } + + set + { + if (IsNegativeNumber(value)) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value must be a positive integer."); + } + + progressMax = value; + } + } + + internal override void Make(Notification notification) + { + ProgressBinder.BindObject(notification); + } + + private bool IsNegativeNumber(double number) + { + return number < 0; + } + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationProgressBinder.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationProgressBinder.cs new file mode 100755 index 0000000..adc0ab4 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationProgressBinder.cs @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + internal static class ProgressBinder + { + internal static void BindObject(Notification notification) + { + double current, max; + + Notification.ProgressType progress = notification.Progress; + Interop.Notification.SetProgressType(notification.Handle, progress.Category); + + if (progress.Category == ProgressCategory.PendingBar) + { + current = 0; + max = 0; + } + else if (progress.Category == ProgressCategory.Percent) + { + current = progress.ProgressCurrent / 100; + max = progress.ProgressMax; + } + else + { + current = progress.ProgressCurrent; + max = progress.ProgressMax; + } + + Interop.Notification.SetProgress(notification.Handle, current); + Interop.Notification.SetProgressSize(notification.Handle, max); + Interop.Notification.SetLayout(notification.Handle, NotificationLayout.Progress); + Interop.Notification.SetOngoingFlag(notification.Handle, true); + } + + internal static void BindSafeHandle(Notification notification) + { + NotificationLayout layout; + Interop.Notification.GetLayout(notification.Handle, out layout); + + if (layout == NotificationLayout.Progress) + { + ProgressCategory category; + double current, max; + + Interop.Notification.GetProgressType(notification.Handle, out category); + Interop.Notification.GetProgress(notification.Handle, out current); + Interop.Notification.GetProgressSize(notification.Handle, out max); + + if (category == ProgressCategory.Percent) + { + current *= 100; + } + + notification.Progress = new Notification.ProgressType(category, current, max); + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationReplyAction.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationReplyAction.cs new file mode 100755 index 0000000..f3bc10a --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationReplyAction.cs @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// Class for displaying direct-reply at notification. + /// You must set a ReplyMax and Button. Otherwise user can't send written text to application which is set by AppControl. + /// + public sealed class ReplyAction : MakerBase + { + /// + /// Gets or sets the Index of Button which is appeared at Notification. + /// If you set ParentIndex, ReplyAction is displayed when button matched with ParentIndex click by the user. + /// If you don't set ParentIndex, appeared to notification directly. + /// + public ButtonIndex ParentIndex { get; set; } = ButtonIndex.None; + + /// + /// Gets or sets the PlaceHolderText of ReplyAction which is appeared at Notification. + /// If you set PlaceHolderText, it is displayed to placeholder in notification. + /// + public string PlaceHolderText { get; set; } + + /// + /// Gets or sets the ReplyMax of ReplyAction which is appeared at Notification. + /// You must set a ReplyMax. Otherwise user don't write text to placeholder in notification. + /// + /// + /// Default value is 160. + /// + public int ReplyMax { get; set; } = 160; + + /// + /// Gets or sets the Button which is appeared to ReplyAction in Notification. + /// You must set a Button. Otherwise user can't send written text to application which is set by AppControl. + /// + /// + /// If you set it to null, the already set ButtonAction will be removed. + /// + /// + /// + /// ReplyAction button = new ReplyAction + /// { + /// ParentIndex = ButtonIndex.Second; + /// PlaceHolderText = "Please write your reply." + /// ReplyMax = 160, + /// Button = new ButtonAction + /// { + /// text = "Yes", + /// ImagePath = "image path", + /// Action = new AppControl{ ApplicationId = "org.tizen.app" }; + /// }; + /// }; + /// + /// + public ButtonAction Button { get; set; } + + internal override void Make(Notification notification) + { + string replyKey = "__PARENT_INDEX__"; + + if (Button != null) + { + Interop.Notification.SetText(notification.Handle, NotificationText.InputButton, Button.Text, null, -1); + Interop.Notification.SetImage(notification.Handle, NotificationImage.TextInputButton, Button.ImagePath); + + if (this.Button.Action != null && this.Button.Action.SafeAppControlHandle.IsInvalid == false) + { + Interop.Notification.SetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, this.Button.Action.SafeAppControlHandle); + + if (this.ParentIndex != ButtonIndex.None) + { + Interop.Notification.SetEventHandler(notification.Handle, (int)this.ParentIndex, this.Button.Action.SafeAppControlHandle); + } + } + } + + Bundle bundle = new Bundle(); + bundle.AddItem(replyKey, ((int)this.ParentIndex).ToString()); + Interop.Notification.SetExtentionData(notification.Handle, replyKey, bundle.SafeBundleHandle); + + Interop.Notification.SetPlaceHolderLength(notification.Handle, this.ReplyMax); + Interop.Notification.SetText(notification.Handle, NotificationText.PlaceHolder, PlaceHolderText, null, -1); + } + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationSafeHandle.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationSafeHandle.cs new file mode 100755 index 0000000..28ce60a --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationSafeHandle.cs @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using System; + using System.ComponentModel; + using System.Runtime.InteropServices; + + [EditorBrowsable(EditorBrowsableState.Never)] + public sealed class NotificationSafeHandle : SafeHandle + { + [EditorBrowsable(EditorBrowsableState.Never)] + public NotificationSafeHandle() + : base(IntPtr.Zero, true) + { + } + + internal NotificationSafeHandle(IntPtr existingHandle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) + { + SetHandle(existingHandle); + } + + /// + /// Gets a value that indicates whether the handle is invalid. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool IsInvalid + { + get { return this.DangerousGetHandle() == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + Interop.Notification.Destroy(this.handle); + this.SetHandle(IntPtr.Zero); + return true; + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationStyle.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationStyle.cs new file mode 100755 index 0000000..84ec3a7 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationStyle.cs @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + /// + /// Class containing common properties and methods of Notifications + /// + /// + /// A notification is a message that is displayed on the notification area. + /// It is created to notify information to the user through the application. + /// This class helps you to provide method and property for creating notification object. + /// + public sealed partial class Notification + { + /// + /// An object that can apply a rich notification style to a Notification object. + /// If the platform does not provide rich notification styles in this class have no effect. + /// + public abstract class StyleBase : MakerBase + { + internal abstract string Key { get; } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationStyleBinder.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationStyleBinder.cs new file mode 100755 index 0000000..dbb66f7 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationStyleBinder.cs @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Applications.Notifications +{ + using System; + + internal static class IndicatorBinder + { + internal static void BindObject(Notification notification) + { + int flag; + NotificationError ret = NotificationError.None; + Notification.IndicatorStyle style = (Notification.IndicatorStyle)notification.GetStyle("Indicator"); + + ret = Interop.Notification.SetText(notification.Handle, NotificationText.FirstMainText, style.SubText, null, -1); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set indicator text"); + } + + ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForIndicator, style.IconPath); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set indicator image"); + } + + Interop.Notification.GetApplist(notification.Handle, out flag); + Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Indicator | (int)NotificationDisplayApplist.Ticker); + } + + internal static void BindSafeHandle(Notification notification) + { + int appList; + Interop.Notification.GetApplist(notification.Handle, out appList); + if ((appList & ((int)NotificationDisplayApplist.Ticker | (int)NotificationDisplayApplist.Indicator)) != 0) + { + string path, text; + Notification.IndicatorStyle indicator = new Notification.IndicatorStyle(); + Interop.Notification.GetImage(notification.Handle, NotificationImage.IconForIndicator, out path); + indicator.IconPath = path; + Interop.Notification.GetText(notification.Handle, NotificationText.FirstMainText, out text); + indicator.SubText = text; + + notification.AddStyle(indicator); + } + } + } + + internal static class ActiveBinder + { + internal static void BindObject(Notification notification) + { + int flag; + NotificationError ret = NotificationError.None; + Notification.ActiveStyle style = (Notification.ActiveStyle)notification.GetStyle("Active"); + + Interop.Notification.SetAutoRemove(notification.Handle, style.IsAutoRemove); + if (style.IsAutoRemove == true) + { + int hidetime; + int deletetime; + style.GetRemoveTime(out hidetime, out deletetime); + + Interop.Notification.SetHideTime(notification.Handle, hidetime); + Interop.Notification.SetDeleteTime(notification.Handle, deletetime); + } + + ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.Background, style?.BackgroundImage); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set background Image"); + } + + Interop.Notification.GetApplist(notification.Handle, out flag); + Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Active); + + foreach (Notification.ButtonAction button in style.GetButtonAction()) + { + button.Make(notification); + } + + if (style.ReplyAction != null) + { + style.ReplyAction.Make(notification); + } + } + + internal static void BindSafeHandle(Notification notification) + { + int appList; + Interop.Notification.GetApplist(notification.Handle, out appList); + + if ((appList & (int)NotificationDisplayApplist.Active) != 0) + { + Notification.ActiveStyle active = new Notification.ActiveStyle(); + bool isExisted = false; + bool autoRemove; + string path, text; + SafeAppControlHandle appcontrol = null; + string replyKey = "__PARENT_INDEX__"; + + for (int i = (int)ButtonIndex.First; i <= (int)ButtonIndex.Third; i++) + { + appcontrol = null; + + Interop.Notification.GetImage(notification.Handle, NotificationImage.FirstButton + i, out path); + Interop.Notification.GetText(notification.Handle, NotificationText.FirstButton + i, out text); + Interop.Notification.GetEventHandler(notification.Handle, i, out appcontrol); + + if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false + || (appcontrol != null && appcontrol.IsInvalid == false)) + { + Notification.ButtonAction button = new Notification.ButtonAction(); + if (appcontrol != null && appcontrol.IsInvalid == false) + { + button.Action = new AppControl(appcontrol); + } + + button.ImagePath = path; + button.Text = text; + button.Index = (ButtonIndex)i; + active.AddButtonAction(button); + isExisted = true; + } + } + + Interop.Notification.GetAutoRemove(notification.Handle, out autoRemove); + active.IsAutoRemove = autoRemove; + if (autoRemove) + { + int hidetime, deletetime; + Interop.Notification.GetHideTime(notification.Handle, out hidetime); + Interop.Notification.GetDeleteTime(notification.Handle, out deletetime); + active.SetRemoveTime(hidetime, deletetime); + } + + Interop.Notification.GetImage(notification.Handle, NotificationImage.Background, out path); + if (string.IsNullOrEmpty(path) == false) + { + isExisted = true; + active.BackgroundImage = path; + } + + appcontrol = null; + Interop.Notification.GetImage(notification.Handle, NotificationImage.TextInputButton, out path); + Interop.Notification.GetText(notification.Handle, NotificationText.InputButton, out text); + Interop.Notification.GetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, out appcontrol); + + if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false + || (appcontrol != null && appcontrol.IsInvalid == false)) + { + Notification.ReplyAction reply = new Notification.ReplyAction(); + Notification.ButtonAction button = new Notification.ButtonAction(); + if (appcontrol != null && appcontrol.IsInvalid == false) + { + button.Action = new AppControl(appcontrol); + } + + button.ImagePath = path; + button.Text = text; + reply.Button = button; + + Interop.Notification.GetText(notification.Handle, NotificationText.PlaceHolder, out text); + reply.PlaceHolderText = text; + + int holderLength; + Interop.Notification.GetPlaceHolderLength(notification.Handle, out holderLength); + reply.ReplyMax = holderLength; + + isExisted = true; + + try + { + SafeBundleHandle bundleHandle; + Interop.Notification.GetExtentionData(notification.Handle, replyKey, out bundleHandle); + Bundle bundle = new Bundle(bundleHandle); + reply.ParentIndex = (ButtonIndex)int.Parse(bundle.GetItem(replyKey).ToString()); + } + catch (Exception ex) + { + Log.Error(Notification.LogTag, ex.ToString()); + } + + active.ReplyAction = reply; + } + + if (isExisted) + { + notification.AddStyle(active); + } + } + } + } + + internal static class LockBinder + { + internal static void BindObject(Notification notification) + { + int flag; + NotificationError ret = NotificationError.None; + Notification.LockStyle style = (Notification.LockStyle)notification.GetStyle("Lock"); + + ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForLock, style.IconPath); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set lock icon"); + } + + ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.ThumbnailForLock, style.ThumbnailPath); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "unable to set lock thumbnail"); + } + + Interop.Notification.GetApplist(notification.Handle, out flag); + Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Lock); + } + + internal static void BindSafehandle(Notification notification) + { + int applist; + Interop.Notification.GetApplist(notification.Handle, out applist); + + if ((applist & (int)NotificationDisplayApplist.Lock) != 0) + { + string path; + Notification.LockStyle lockStyle = new Notification.LockStyle(); + + Interop.Notification.GetImage(notification.Handle, NotificationImage.IconForLock, out path); + lockStyle.IconPath = path; + + Interop.Notification.GetImage(notification.Handle, NotificationImage.ThumbnailForLock, out path); + lockStyle.ThumbnailPath = path; + + notification.AddStyle(lockStyle); + } + } + } + + internal static class BigPictureBinder + { + internal static void BindObject(Notification notification) + { + Notification.BigPictureStyle style = (Notification.BigPictureStyle)notification.GetStyle("BigPicture"); + + Interop.Notification.SetImage(notification.Handle, NotificationImage.BigPicture, style.ImagePath); + Interop.Notification.SetBigPictureSize(notification.Handle, style.ImageSize); + Interop.Notification.SetText(notification.Handle, NotificationText.BigPicture, style.Content, null, -1); + Interop.Notification.SetLayout(notification.Handle, NotificationLayout.Extension); + } + + internal static void BindSafeHandle(Notification notification) + { + NotificationLayout layout; + + Interop.Notification.GetLayout(notification.Handle, out layout); + if (layout == NotificationLayout.Extension) + { + Notification.BigPictureStyle style = new Notification.BigPictureStyle(); + + string text; + Interop.Notification.GetImage(notification.Handle, NotificationImage.BigPicture, out text); + style.ImagePath = text; + + int size; + Interop.Notification.GetBigPictureSize(notification.Handle, out size); + style.ImageSize = size; + + Interop.Notification.GetText(notification.Handle, NotificationText.BigPicture, out text); + style.Content = text; + + notification.AddStyle(style); + } + } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications/EventNotification.cs b/src/Tizen.Applications.Notification/Tizen.Applications/EventNotification.cs deleted file mode 100755 index 7a166bf..0000000 --- a/src/Tizen.Applications.Notification/Tizen.Applications/EventNotification.cs +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Runtime.InteropServices; - -namespace Tizen.Applications.Notifications -{ - /// - /// Class for creating a simple event notification - /// - /// - /// - /// public class EventNotificationExample - /// { - /// /// ... - /// EventNotification noti = new EventNotification(); - /// noti.EventCount = 2; - /// noti.Title = "Unread Messages"; - /// NotificationManager.Post(noti); - /// } - /// - /// - public class EventNotification : Notification - { - /// - /// Intializes instance of EventNotification class - /// - public EventNotification() - { - int ret; - - _handle = Interop.Notification.Create(NotificationType.Event); - if (_handle.IsInvalid) - { - ret = Tizen.Internals.Errors.ErrorFacts.GetLastResult(); - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to create Event Notification"); - } - - ret = Interop.Notification.SetLayout(_handle, NotiLayout.SingleEvent); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set event layout"); - } - - NotificationType = NotificationType.Event; - } - - internal EventNotification(Interop.Notification.SafeNotificationHandle handle) - { - _handle = handle; - - NotificationType = NotificationType.Event; - } - - /// - /// Sets and gets the event count to be displayed on a Notification. - /// - /// - /// EventCount is a numeric value which is displayed on a notification. - /// For example, to show unread message count on a messenger notification event count can be set. - /// - /// - /// - /// EventNotification noti = new EventNotification(); - /// noti.EventCount = 2; - /// Log.Debug(LogTag, "Event Count: " + noti.EventCount); - /// - /// - public int EventCount - { - get - { - IntPtr countPtr; - string count; - int cnt; - int ret = Interop.Notification.GetText(_handle, NotiText.EventCount, out countPtr); - if(ret != (int)NotificationError.None) - { - Log.Warn(_logTag, "unable to get event count"); - return 0; - } - - if(countPtr == IntPtr.Zero) - return 0; - - count = Marshal.PtrToStringAnsi(countPtr); - if(Int32.TryParse(count, out cnt)) - { - return cnt; - } - else - { - Log.Warn(_logTag, "unable to parse string"); - return 0; - } - } - set - { - int ret; - if(value <= 0) - { - throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid value for event count"); - } - - ret = Interop.Notification.SetText(_handle, NotiText.EventCount, value.ToString(), null, -1); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set event count"); - } - } - } - - /// - /// Gets and sets TimeStamp. Defaults to 0 ms UTC i.e 1 Jan 1970. - /// - /// - /// Timestamp can be used to display a timestamp on a notification. - /// For example, in a message received notification, Timestamp can be used to display the time of message reception. - /// - /// - /// - /// EventNotification noti = new EventNotification(); - /// noti.Timestamp = DateTime.Now; - /// Log.Debug(LogTag, "Timestamp: " + noti.Timestamp); - /// - /// - public DateTime Timestamp - { - get - { - int time; - int ret = Interop.Notification.GetTime(_handle, out time); - if(ret != (int)NotificationError.None) - { - Log.Warn(_logTag, "unable to get timestamp"); - return (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(0).ToLocalTime(); - } - - return (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(time).ToLocalTime(); - } - set - { - int time = (int)value.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; - int ret = Interop.Notification.SetTime(_handle, time); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set timestamp"); - } - } - } - - /// - /// Method to add a button to an event notification - /// - /// Index of the Button to be added to notification - /// Path of Button image - /// Text of button - /// App control to be invoke on button click - /// - /// AddButton method can be used to add 2 different types of buttons, one for positive response and one for negative. - /// A button comprises of Image path for the button, Text for the button and an App control which is to be invoked on button click. - /// - /// - /// - /// Application app = Application.Current; - /// DirectoryInfo dir = app.DirectoryInfo; - /// string imagePath = dir.Resource+"notification.png"; - /// string text = "Click"; - /// AppControl clickApp = new AppControl(); - /// clickApp.ApplicationId = "org.tizen.setting"; /// EventNotification noti = new EventNotification(); - /// noti.AddButton(ButtonIndex.Positive, imagePath, text, clickApp); - /// - /// - public void AddButton(ButtonIndex index, string imagePath = "", string text = "", AppControl appControl = null) - { - int ret = Interop.Notification.SetImage(_handle, (NotiImage)((int)index + (int)NotiImage.PositiveButton), imagePath); - if (ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "set button image path failed"); - } - - ret = Interop.Notification.SetText(_handle, (NotiText)((int)NotiText.PositiveButton + (int)index), text, null, -1); - if (ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set button text"); - } - - if(appControl != null) - { - ret = Interop.Notification.SetEventHandler(_handle, (int)index, appControl.SafeAppControlHandle); - if (ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set button event handler"); - } - } - - ret = Interop.Notification.AddButton(_handle, (int)index + 1); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to add button"); - } - } - - /// - /// Method to remove a button from an event notification - /// - /// Index of button to be removed - /// - /// RemoveButton method can be used to remove a button which has been added to the notification. - /// RemoveButton should only be called after a button has been added. - /// - /// - /// - /// EventNotification noti = new EventNotification(); - /// noti.AddButton(ButtonIndex.Positive); - /// /// ... - /// noti.RemoveButton(ButtonIndex.Negative); - /// - /// - public void RemoveButton(ButtonIndex index) - { - int ret = Interop.Notification.RemoveButton(_handle, (int)index + 1); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to remove button"); - } - - ret = Interop.Notification.SetImage(_handle, (NotiImage)((int)index + (int)NotiImage.PositiveButton), string.Empty); - if (ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "set button image path failed"); - } - - ret = Interop.Notification.SetText(_handle, (NotiText)((int)NotiText.PositiveButton + (int)index), string.Empty, null, -1); - if (ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set button text"); - } - } - } -} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications/NotificationManager.cs b/src/Tizen.Applications.Notification/Tizen.Applications/NotificationManager.cs deleted file mode 100755 index c9abb3b..0000000 --- a/src/Tizen.Applications.Notification/Tizen.Applications/NotificationManager.cs +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; - -namespace Tizen.Applications.Notifications -{ - /// - /// NotificationManager class to post, update, delete and get Notifications. - /// - public static class NotificationManager - { - /// - /// Posts a new Notification. - /// - /// Notification to post - /// Thrown when argument is null - /// - /// - /// EventNotification noti = new EventNotification(); - /// noti.Title = "Title"; - /// NotificationManager.Post(noti); - /// - /// - /// http://tizen.org/privilege/appmanager.launch - public static void Post(Notification notification) - { - if(notification == null) - { - throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); - } - - int ret = Interop.Notification.Post(notification._handle); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "post notification failed"); - } - } - - /// - /// Updates a posted Notification. - /// - /// Notification to update - /// Thrown when argument is null - /// - /// - /// EventNotification noti = new EventNotification(); - /// noti.Title = "Title"; - /// NotificationManager.Post(noti); - /// ... - /// noti.Title = "New Title"; - /// NotificationManager.Update(noti); - /// - /// - /// http://tizen.org/privilege/appmanager.launch - ///
-        /// Post method should be called on the Notification object.
-        /// 
- public static void Update(Notification notification) - { - if(notification == null) - { - throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); - } - - int ret = Interop.Notification.Update(notification._handle); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "update notification failed"); - } - } - - /// - /// Deletes a posted Notification. - /// - /// Notification to remove - /// Thrown when argument is null - /// - /// - /// EventNotification noti = new EventNotification(); - /// NotificationManager.Post(noti); - /// ... - /// NotificationManager.Delete(noti); - /// - /// - /// http://tizen.org/privilege/appmanager.launch - ///
-        /// Post method should be called on the Notification object.
-        /// 
- public static void Delete(Notification notification) - { - if(notification == null) - { - throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method"); - } - - int ret = Interop.Notification.Delete(notification._handle); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "delete notification failed"); - } - } - - /// - /// Removes all posted Notification of NotificationType type of calling application. - /// - /// Type of Notifications to remove - /// - /// - /// EventNotification notiE = new EventNotification(); - /// NotificationManager.Post(notiE); - /// NotificationManager.DeleteAll(NotificationType.Event); - /// /// ... - /// ProgressNotification notiP = new ProgressNotification(); - /// NotificationManager.Post(notiP); - /// NotificationManager.DeleteAll(NotificationType.Progress); - /// - /// - /// http://tizen.org/privilege/appmanager.launch - public static void DeleteAll(NotificationType type) - { - int ret = Interop.Notification.DeleteAll((int)type); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "delete all notifications failed of type " + type); - } - } - - /// - /// Removes all posted Notification of calling application. - /// - /// - /// - /// EventNotification notiE = new EventNotification(); - /// NotificationManager.Post(notiE); - /// ProgressNotification notiP = new ProgressNotification(); - /// NotificationManager.Post(notiP); - /// NotificationManager.DeleteAll(); - /// - /// - /// http://tizen.org/privilege/appmanager.launch - public static void DeleteAll() - { - DeleteAll(NotificationType.Progress); - - DeleteAll(NotificationType.Event); - } - - /// - /// Searches for a posted notification which has the inputted tag - /// - /// - /// Load method should be called only for notifcations which have been posted using NotificationManager.Post method. - /// If two or more notifications share the same tag, the notification posted most recently is returned. - /// - /// Type of notification to be queried - /// Tag used to query - /// Notification Object with inputted tag - /// Thrown when no notification with inputed tag exists - /// - /// - /// EventNotification noti = new EventNotification(); - /// noti.Title = "Title"; - /// noti.Tag = "Hello"; - /// NotificationManager.Post(noti); - /// /// ... - /// EventNotification notiCopy = NotificationManager/("Hello"); - /// - /// - /// http://tizen.org/privilege/appmanager.launch - public static T Load(string tag) where T : Notification - { - Notification result = null; - Interop.Notification.SafeNotificationHandle handle = Interop.Notification.Load(tag); - if(handle.IsInvalid) - { - int ret = Tizen.Internals.Errors.ErrorFacts.GetLastResult(); - - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to load Notification"); - } - - result = CreateNotificationFromTag(handle); - - return (T)result; - } - - internal static Notification CreateNotificationFromTag(Interop.Notification.SafeNotificationHandle handle) - { - Notification result = null; - NotificationType type; - - int ret = Interop.Notification.GetType(handle, out type); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to get type"); - } - - if(type == NotificationType.Event) - { - result = (Notification)new EventNotification(handle); - } - else - { - result = (Notification)new ProgressNotification(handle); - } - - return result; - } - } -} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications/ProgressNotification.cs b/src/Tizen.Applications.Notification/Tizen.Applications/ProgressNotification.cs deleted file mode 100755 index 36994bb..0000000 --- a/src/Tizen.Applications.Notification/Tizen.Applications/ProgressNotification.cs +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; - -namespace Tizen.Applications.Notifications -{ - /// - /// Class for creating progress notifications - /// - public class ProgressNotification : Notification - { - /// - /// Intializes instance of ProgressNotification class - /// - public ProgressNotification() - { - int ret; - - _handle = Interop.Notification.Create(NotificationType.Progress); - if (_handle.IsInvalid) - { - ret = Tizen.Internals.Errors.ErrorFacts.GetLastResult(); - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to create Progress Notification"); - } - - ret = Interop.Notification.SetLayout(_handle, NotiLayout.Progress); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set progress layout"); - } - - ret = Interop.Notification.SetProgressSize(_handle, 100.0); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set default progress size"); - } - - NotificationType = NotificationType.Progress; - } - - internal ProgressNotification(Interop.Notification.SafeNotificationHandle handle) - { - _handle = handle; - - NotificationType = NotificationType.Progress; - } - - /// - /// Gets and sets maximum value for progress ticker. Defaults to 100. - /// - /// - /// Maximum should not be less than 0. - /// - /// - /// - /// ProgressNotification noti = new ProgressNotification(); - /// noti.Maximum = 200; - /// Log.Debug(LogTag, "Maximum: " + noti.Maximum); - /// - /// - /// Thrown when value of Maximum being set is less than 0 - public double Maximum - { - get - { - double size; - int ret = Interop.Notification.GetProgressSize(_handle, out size); - if(ret != (int)NotificationError.None) - { - Log.Warn(_logTag, "get progress size failed"); - return 100.0; - } - - return size; - } - set - { - if(value < 0) - { - throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "wrong value for progress size"); - } - - int ret = Interop.Notification.SetProgressSize(_handle, value); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "set progress size failed"); - } - } - } - - /// - /// gets and sets current progress value for ticker. Defaults to 0. - /// - /// - /// ProgressValue should not be less than 0 or greater than Maximum. - /// - /// - /// - /// ProgressNotification noti = new ProgressNotification(); - /// noti.Maximum = 200; - /// noti.ProgressValue = 100; - /// Log.Debug(LogTag, "Progress Value: " + noti.ProgressValue); - /// - /// - /// Thrown when value of ProgressValue being set is less than 0 or greater than value of Maximum - public double ProgressValue - { - get - { - double size; - int ret = Interop.Notification.GetProgress(_handle, out size); - if(ret != (int)NotificationError.None) - { - Log.Warn(_logTag, "get progress failed"); - return 0; - } - - return size; - } - set - { - if(value < 0 || value > Maximum) - { - throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "wrong value for progress value"); - } - - int ret = Interop.Notification.SetProgress(_handle, value); - if(ret != (int)NotificationError.None) - { - throw NotificationErrorFactory.GetException((NotificationError)ret, "set progress failed"); - } - } - } - } -}