From: randeep ahlawat Date: Thu, 21 Apr 2016 10:33:34 +0000 (+0530) Subject: Introducing Notificaiton API X-Git-Tag: submit/trunk/20170823.075128~121^2~147 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b64ff76cf22e8d4b091c0d742957870496a50b4;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Introducing Notificaiton API Change-Id: I700172b81fdde76e1ebf5e11cb29b480c99e75d5 Signed-off-by: randeep ahlawat --- diff --git a/Tizen.Applications/Interop/Interop.Libraries.cs b/Tizen.Applications/Interop/Interop.Libraries.cs index 346cfdd..c0c9ad9 100755 --- a/Tizen.Applications/Interop/Interop.Libraries.cs +++ b/Tizen.Applications/Interop/Interop.Libraries.cs @@ -21,5 +21,6 @@ internal static partial class Interop public const string Bundle = "libbundle.so.0"; public const string Glib = "libglib-2.0.so.0"; public const string Libc = "libc.so.6"; + public const string Notification = "libnotification.so.0"; } } diff --git a/Tizen.Applications/Interop/Interop.Notification.cs b/Tizen.Applications/Interop/Interop.Notification.cs new file mode 100755 index 0000000..1af6e49 --- /dev/null +++ b/Tizen.Applications/Interop/Interop.Notification.cs @@ -0,0 +1,167 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Runtime.InteropServices; +using Tizen.Applications; +using Tizen.Applications.Notifications; + +internal static partial class Interop +{ + internal static class Notification + { + [DllImport(Libraries.Notification, EntryPoint = "notification_create")] + internal static extern SafeNotificationHandle Create(NotificationType type); + + [DllImport(Libraries.Notification, EntryPoint = "notification_free")] + internal static extern int Destroy(IntPtr handle); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_text")] + internal static extern int GetText(SafeNotificationHandle handle, NotiText 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); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_image")] + internal static extern int GetImage(SafeNotificationHandle handle, NotiImage type, out IntPtr text); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_image")] + internal static extern int SetImage(SafeNotificationHandle handle, NotiImage type, string text); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_time")] + internal static extern int GetTime(SafeNotificationHandle handle, out int time); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_time")] + internal static extern int SetTime(SafeNotificationHandle handle, int time); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_insert_time")] + internal static extern int GetInsertTime(SafeNotificationHandle handle, out long time); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_sound")] + internal static extern int GetSound(SafeNotificationHandle handle, out SoundOption type, out IntPtr path); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_sound")] + internal static extern int SetSound(SafeNotificationHandle handle, SoundOption type, string path); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_vibration")] + internal static extern int GetVibration(SafeNotificationHandle handle, out VibrationOption type, out IntPtr path); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_vibration")] + internal static extern int SetVibration(SafeNotificationHandle handle, VibrationOption type, string path); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_led")] + internal static extern int GetLed(SafeNotificationHandle handle, out LedOption type, out int color); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_led")] + internal static extern int SetLed(SafeNotificationHandle handle, LedOption 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); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_led_time_period")] + internal static extern int SetLedTimePeriod(SafeNotificationHandle handle, int on, int off); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_launch_option")] + internal static extern int GetAppControl(SafeNotificationHandle 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); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_event_handler")] + internal static extern int GetEventHandler(SafeNotificationHandle 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); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_property")] + internal static extern int GetProperties(SafeNotificationHandle handle, out int flags); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_property")] + internal static extern int SetProperties(SafeNotificationHandle handle, int flags); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_display_applist")] + internal static extern int GetApplist(SafeNotificationHandle handle, out int flags); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_display_applist")] + internal static extern int SetApplist(SafeNotificationHandle handle, int flags); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_size")] + internal static extern int GetProgressSize(SafeNotificationHandle handle, out double value); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_size")] + internal static extern int SetProgressSize(SafeNotificationHandle handle, double value); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_progress")] + internal static extern int GetProgress(SafeNotificationHandle handle, out double value); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_progress")] + internal static extern int SetProgress(SafeNotificationHandle handle, double value); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_layout")] + internal static extern int GetLayout(SafeNotificationHandle handle, out NotiLayout type); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_layout")] + internal static extern int SetLayout(SafeNotificationHandle handle, NotiLayout type); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_type")] + internal static extern int GetType(SafeNotificationHandle handle, out NotificationType type); + + [DllImport(Libraries.Notification, EntryPoint = "notification_update")] + internal static extern int Update(SafeNotificationHandle handle); + + [DllImport(Libraries.Notification, EntryPoint = "notification_delete")] + internal static extern int Delete(SafeNotificationHandle handle); + + [DllImport(Libraries.Notification, EntryPoint = "notification_delete_all")] + internal static extern int DeleteAll(int type); + + [DllImport(Libraries.Notification, EntryPoint = "notification_post")] + internal static extern int Post(SafeNotificationHandle handle); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_pkgname")] + internal static extern int GetPackageName(SafeNotificationHandle 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_remove_button")] + internal static extern int RemoveButton(SafeNotificationHandle handle, int index); + + [DllImport(Libraries.Notification, EntryPoint = "notification_set_tag")] + internal static extern int SetTag(SafeNotificationHandle handle, string tag); + + [DllImport(Libraries.Notification, EntryPoint = "notification_get_tag")] + internal static extern int GetTag(SafeNotificationHandle handle, out IntPtr tag); + + [DllImport(Libraries.Notification, EntryPoint = "notification_status_message_post")] + internal static extern int PostMessage(string text); + + [DllImport(Libraries.Notification, EntryPoint = "notification_load_by_tag")] + internal static extern SafeNotificationHandle Load(string text); + + internal sealed class SafeNotificationHandle : SafeHandle + { + public SafeNotificationHandle() + : base(IntPtr.Zero, true) + { + } + + public override bool IsInvalid + { + get { return this.handle == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + Notification.Destroy(this.handle); + this.SetHandle(IntPtr.Zero); + return true; + } + } + } +} diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj index b7757e8..209ab9e 100644 --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -60,6 +60,7 @@ + @@ -105,6 +106,12 @@ + + + + + + diff --git a/Tizen.Applications/Tizen.Applications/EventNotification.cs b/Tizen.Applications/Tizen.Applications/EventNotification.cs new file mode 100755 index 0000000..61eeb4f --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/EventNotification.cs @@ -0,0 +1,194 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Runtime.InteropServices; + +namespace Tizen.Applications.Notifications +{ + /// + /// Class for creating either SingleEvent notifications or MultiEvent notifications + /// + public class EventNotification : Notification + { + /// + /// Class contructor + /// + 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. + /// + 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.PtrToStringAuto(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. + /// + 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 + /// + /// Index of the Button to be added to notification + /// Path of Button image + /// Text of button + /// App control to be invoke on button click + 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 + /// + /// Index of button to be removed + public void RemoveButton(ButtonIndex index) + { + AppControl app = new AppControl(); + + 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"); + } + + ret = Interop.Notification.SetEventHandler(_handle, (int)index, app.SafeAppControlHandle); + if (ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set button event handler"); + } + } + } +} diff --git a/Tizen.Applications/Tizen.Applications/Notification.cs b/Tizen.Applications/Tizen.Applications/Notification.cs new file mode 100755 index 0000000..7a358e3 --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/Notification.cs @@ -0,0 +1,710 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using Tizen.UI; + +namespace Tizen.Applications.Notifications +{ + /// + /// Structure containing led on and off periods + /// + public struct LedBlinkPeriod + { + /// + /// Constructor + /// + /// On time of led in ms + /// Off time of led in ms + public LedBlinkPeriod(int on, int off) + { + OnTime = on; + OffTime = off; + } + + /// + /// On time of Led in milliseconds + /// + public int OnTime + { + get; + set; + } + + /// + /// Off time of Led in milliseconds + /// + public int OffTime + { + get; + set; + } + } + + /// + /// Class containing common properties and methods of Notifications + /// + public abstract class Notification + { + internal const string _logTag = "Tizen.Applications.Notification"; + + internal Interop.Notification.SafeNotificationHandle _handle; + + private const int DisableAppLaunchMask = 1 << 1; + + private const int DisableAutoDeleteMask = 1 << 2; + + private const int VolatileDisplayMask = 1 << 8; + + private string _soundPath = string.Empty; + + private string _vibrationPath = null; + + private Color _ledColor = new Color(0, 0, 0, 0); + + /// + /// Insert time of Notification. Default is 1 Jan 1970 9:00:00 until notification is posted. + /// + public DateTime InsertTime + { + get + { + long time; + int ret = Interop.Notification.GetInsertTime(_handle, out time); + if (ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get insert time"); + 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(); + } + } + + /// + /// Title of Notification. Defaults to empty string. + /// + public string Title + { + get + { + IntPtr titlePtr; + int ret = Interop.Notification.GetText(_handle, NotiText.Title, out titlePtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get title"); + return string.Empty; + } + + if (titlePtr == IntPtr.Zero) + return string.Empty; + + return Marshal.PtrToStringAuto(titlePtr); + } + set + { + int ret = Interop.Notification.SetText(_handle, NotiText.Title, value, null, -1); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set title"); + } + } + } + + /// + /// Content of Notification. Defaults to empty string. + /// + public string Content + { + get + { + IntPtr contentPtr; + int ret = Interop.Notification.GetText(_handle, NotiText.Content, out contentPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get content"); + return string.Empty; + } + + if (contentPtr == IntPtr.Zero) + return string.Empty; + + return Marshal.PtrToStringAuto(contentPtr); + } + set + { + int ret = Interop.Notification.SetText(_handle, NotiText.Content, value, null, -1); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set content"); + } + } + } + + /// + /// Gets and sets Icon image Path. Defaults to empty string. + /// + public string IconPath + { + get + { + IntPtr pathPtr; + int ret = Interop.Notification.GetImage(_handle, NotiImage.Icon, out pathPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get icon image path"); + return string.Empty; + } + + if (pathPtr == IntPtr.Zero) + return string.Empty; + + return Marshal.PtrToStringAuto(pathPtr); + } + set + { + int ret = Interop.Notification.SetImage(_handle, NotiImage.Icon, value); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set icon image path"); + } + } + } + + /// + /// Gets and sets Indicator icon image Path. Defaults to empty string. + /// + public string IndicatorIconPath + { + get + { + IntPtr pathPtr; + int ret = Interop.Notification.GetImage(_handle, NotiImage.Indicator, out pathPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get indicator icon image path"); + return string.Empty; + } + + if (pathPtr == IntPtr.Zero) + return string.Empty; + + return Marshal.PtrToStringAuto(pathPtr); + } + set + { + int ret = Interop.Notification.SetImage(_handle, NotiImage.Indicator, value); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set indicator icon image path"); + } + } + } + + /// + /// Gets and sets Background image Path. Defaults to string.Empty. + /// + public string BackgroundImagePath + { + get + { + IntPtr pathPtr; + int ret = Interop.Notification.GetImage(_handle, NotiImage.Background, out pathPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get background path"); + return string.Empty; + } + + if (pathPtr == IntPtr.Zero) + return string.Empty; + + return Marshal.PtrToStringAuto(pathPtr); + } + set + { + int ret = Interop.Notification.SetImage(_handle, NotiImage.Background, value); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set background path"); + } + } + } + + /// + /// Gets and sets SubIcon image Path. Defaults to empty string. + /// + public string SubIconPath + { + get + { + IntPtr pathPtr; + int ret = Interop.Notification.GetImage(_handle, NotiImage.SubIcon, out pathPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get sub icon path"); + return string.Empty; + } + + if (pathPtr == IntPtr.Zero) + return string.Empty; + + return Marshal.PtrToStringAuto(pathPtr); + } + set + { + int ret = Interop.Notification.SetImage(_handle, NotiImage.SubIcon, value); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set sub icon path"); + } + } + } + + /// + /// Gets and sets Tag. Defaults to empty string. + /// + public string Tag + { + get + { + IntPtr tagPtr; + int ret = Interop.Notification.GetTag(_handle, out tagPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get tag"); + return string.Empty; + } + + if (tagPtr == IntPtr.Zero) + return string.Empty; + + return Marshal.PtrToStringAuto(tagPtr); + } + set + { + int ret = Interop.Notification.SetTag(_handle, value); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set tag"); + } + } + } + + /// + /// Gets and sets Areas to display the notification. Defaults to NotificaitonTray | Ticker | Indicator. + /// + public NotificationArea NotificationArea + { + get + { + int appList; + int ret = Interop.Notification.GetApplist(_handle, out appList); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable get applist"); + return NotificationArea.None; + } + + return (NotificationArea)appList; + } + set + { + int ret = Interop.Notification.SetApplist(_handle, (int)value); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set applist"); + } + } + } + + /// + /// Gets the Notification Type. + /// + public NotificationType NotificationType + { + get; + protected set; + } + + /// + /// Gets and sets the Led on and off time. Defaults to 0 for both. + /// + public LedBlinkPeriod LedBlinkPeriod + { + get + { + int on; + int off; + int ret = Interop.Notification.GetLedTimePeriod(_handle, out on, out off); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get led time period"); + return new LedBlinkPeriod(0,0); + } + + return new LedBlinkPeriod(on, off); + } + set + { + int ret = Interop.Notification.SetLedTimePeriod(_handle, value.OnTime, value.OffTime); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set led time period"); + } + } + } + + /// + /// Gets and sets value to enable/disable sound for a notification. False by default. + /// + public bool SoundEnabled + { + get + { + SoundOption enabled; + IntPtr pathPtr; + + int ret = Interop.Notification.GetSound(_handle, out enabled, out pathPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get sound enabled"); + return false; + } + + if(enabled >= SoundOption.Default) + { + return true; + } + else + { + return false; + } + } + set + { + int ret; + if(value) + { + ret = Interop.Notification.SetSound(_handle, _soundPath == string.Empty || _soundPath == null ? SoundOption.Default : SoundOption.Custom, _soundPath); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set sound enabled "); + } + } + else + { + ret = Interop.Notification.SetSound(_handle, SoundOption.Off, null); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable disable sound"); + } + } + } + } + + /// + /// Get and set path of custom sound file to be played for notification.Defaults to string.Empty. + /// + public string SoundPath + { + get + { + SoundOption enabled; + IntPtr pathPtr; + int ret = Interop.Notification.GetSound(_handle, out enabled, out pathPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get sound path"); + return string.Empty; + } + + if(pathPtr != IntPtr.Zero) + _soundPath = Marshal.PtrToStringAuto(pathPtr); + + return _soundPath; + } + set + { + int ret; + IntPtr pathPtr; + SoundOption enabled; + + ret = Interop.Notification.GetSound(_handle, out enabled, out pathPtr); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to get sound enabled"); + } + + if(enabled >= SoundOption.Default) + { + ret = Interop.Notification.SetSound(_handle, value == string.Empty || _soundPath == null ? SoundOption.Default : SoundOption.Custom, value); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set sound path"); + } + } + + _soundPath = value; + } + } + + /// + /// Gets and sets value to enable/disable vibration for a notification. Defaults to false; + /// + public bool VibrationEnabled + { + get + { + VibrationOption enabled; + IntPtr pathPtr; + int ret = Interop.Notification.GetVibration(_handle, out enabled, out pathPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get vibration enabled"); + return false; + } + + if(enabled >= VibrationOption.Default) + { + return true; + } + else + { + return false; + } + } + set + { + int ret; + if(value) + { + ret = Interop.Notification.SetVibration(_handle, _vibrationPath == null ? VibrationOption.Default : VibrationOption.Custom, _vibrationPath); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set vibration enabled "); + } + } + else + { + ret = Interop.Notification.SetVibration(_handle, VibrationOption.Off, null); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable disable vibration"); + } + } + } + } + + /// + /// Get and sets value to enable/disable led. Defaults to false. + /// + public bool LedEnabled + { + get + { + LedOption enabled; + int c; + int ret = Interop.Notification.GetLed(_handle, out enabled, out c); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get led enabled"); + return false; + } + + if(enabled >= LedOption.On) + { + return true; + } + else + { + return false; + } + } + set + { + int ret; + if(value) + { + ret = Interop.Notification.SetLed(_handle, LedOption.On, _ledColor.Argb); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set led enabled"); + } + } + else + { + ret = Interop.Notification.SetLed(_handle, LedOption.Off, 0); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set led enabled"); + } + } + } + } + + /// + /// Gets and sets custom led color for led. Default to Color(0, 0, 0, 0). + /// + public Color LedColor + { + get + { + LedOption enabled; + int c; + int ret = Interop.Notification.GetLed(_handle, out enabled, out c); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get led color"); + return _ledColor; + } + + if(c != 0) + _ledColor = new Color(c >> 16 & 255, c >> 8 & 255, c >> 0 & 255, c >> 24 & 255); + + return _ledColor; + } + set + { + LedOption enabled; + int c; + int ret = Interop.Notification.GetLed(_handle, out enabled, out c); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to get led enabled"); + } + + if(enabled >= LedOption.On) + { + ret = Interop.Notification.SetLed(_handle, LedOption.On, value.Argb); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set led color"); + } + } + + _ledColor = value; + } + } + + /// + /// Gets and sets value to enable/disable Volatile Display property. Defaults to false. + /// + public bool VolatileDisplayEnabled + { + get + { + int result; + int ret = Interop.Notification.GetProperties(_handle, out result); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get disable app launch"); + return false; + } + + if((result & VolatileDisplayMask) != 0) + return true; + else + return false; + } + set + { + int result = 0; + + int ret = Interop.Notification.GetProperties(_handle, out result); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to get property values"); + } + + if(value) + result = result | VolatileDisplayMask; + else + result = result & ~VolatileDisplayMask; + + ret = Interop.Notification.SetProperties(_handle, result); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set properties"); + } + } + } + + /// + /// Gets and sets Thumbnail path for notification. Defaults to string.Empty. + /// + public string ThumbnailPath + { + get + { + IntPtr pathPtr; + string path; + int ret = Interop.Notification.GetImage(_handle, NotiImage.Thumbnail, out pathPtr); + if(ret != (int)NotificationError.None) + { + Log.Warn(_logTag, "unable to get thumbnail Path"); + return string.Empty; + } + + if(pathPtr == IntPtr.Zero) + return string.Empty; + + path = Marshal.PtrToStringAuto(pathPtr); + return path; + } + set + { + int ret = Interop.Notification.SetImage(_handle, NotiImage.Thumbnail, value); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set thumbnail path"); + } + } + } + + /// + /// Method for setting Notification Appcontrol which is invoked when notification is clicked + /// + /// AppControl object to set + public void SetLaunchAppControl(AppControl app) + { + if(app == null) + { + throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered"); + } + + int ret = Interop.Notification.SetAppControl(_handle, LaunchOption.AppControl, app.SafeAppControlHandle); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set app control"); + } + } + + /// + /// Method for getting Notification AppControl which will be invoked when notification is clicked + /// + /// AppControl object which was set + public AppControl GetLaunchAppControl() + { + SafeAppControlHandle app; + int ret = Interop.Notification.GetAppControl(_handle, LaunchOption.AppControl, out app); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to get app control"); + } + + if(app.IsInvalid) + return null; + + return new AppControl(app); + } + } +} diff --git a/Tizen.Applications/Tizen.Applications/NotificationEnumerations.cs b/Tizen.Applications/Tizen.Applications/NotificationEnumerations.cs new file mode 100755 index 0000000..b2e5461 --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/NotificationEnumerations.cs @@ -0,0 +1,126 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.Applications.Notifications +{ + /// + /// Enumeration for Notification Type + /// + public enum NotificationType : short + { + /// + /// Value representing thumbnail and event notifications + /// + Event = 0, + /// + /// Value representing progress notifications + /// + Progress + } + + /// + /// Enumeration for Notification applications + /// + [Flags] + public enum NotificationArea + { + /// + /// Value for applying no applist. Default + /// + None = 0, + /// + /// Value for notification tray app + /// + NotificationTray = 1, + /// + /// Value for ticker app + /// + Ticker = 1 << 1, + /// + /// Value for indicator app + /// + Indicator = 1 << 3, + /// + /// Value for active notification + /// + Active = 1 << 4 + } + + /// + /// Enumeration for Button indices for Base Notifications + /// + public enum ButtonIndex : short + { + /// + /// Value for first index + /// + Positive = 0, + /// + /// Value for second index + /// + Negative + } + + internal enum SoundOption + { + Off = -1, + Default, + Custom + } + + internal enum VibrationOption + { + Off = -1, + Default, + Custom + } + + internal enum LedOption + { + Off = -1, + On = 1 + } + + internal enum NotiLayout + { + SingleEvent = 1, + Thumbnail = 3, + Progress = 5 + } + + internal enum NotiText + { + Title = 0, + Content, + EventCount = 3, + FirstMainText, + FirstSubText, + SecondMainText, + SecondSubText, + PositiveButton = 13, + NegativeButton + } + + internal enum NotiImage + { + Icon = 0, + Indicator, + Thumbnail = 3, + SubIcon = 5, + Background, + PositiveButton = 12, + NegativeButton + } + + internal enum LaunchOption + { + AppControl = 1 + } +} diff --git a/Tizen.Applications/Tizen.Applications/NotificationErrorFactory.cs b/Tizen.Applications/Tizen.Applications/NotificationErrorFactory.cs new file mode 100755 index 0000000..240fdf3 --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/NotificationErrorFactory.cs @@ -0,0 +1,45 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.Applications.Notifications +{ + internal enum NotificationError + { + None = Tizen.Internals.Errors.ErrorCode.None, + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + IoError = Tizen.Internals.Errors.ErrorCode.IoError, + DbError = -0x01140000 | 0x01, + AlreadyExists = -0x01140000 | 0x02, + DBusError = -0x01140000 | 0x03, + DoesnotExist = -0x01140000 | 0x04, + ServiceError = -0x01140000 | 0x05, + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, + InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation + } + + internal static class NotificationErrorFactory + { + private const string _logTag = "Tizen.Applications.Notification"; + + internal static Exception GetException(NotificationError ret, string msg) + { + switch (ret) + { + case NotificationError.InvalidParameter: + Log.Error(_logTag, msg); + return new ArgumentException(ret + " error occurred."); + default: + Log.Error(_logTag, msg); + return new InvalidOperationException(ret + " error occurred."); + } + } + } +} diff --git a/Tizen.Applications/Tizen.Applications/NotificationManager.cs b/Tizen.Applications/Tizen.Applications/NotificationManager.cs new file mode 100755 index 0000000..e9b12ec --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/NotificationManager.cs @@ -0,0 +1,153 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +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 + 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 + 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 + 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 + 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. + /// + public static void DeleteAll() + { + DeleteAll(NotificationType.Progress); + + DeleteAll(NotificationType.Event); + } + + /// + /// Posts a message on a toast popup + /// + /// Text to display on popup + public static void PostToastMessage(string text) + { + int ret = Interop.Notification.PostMessage(text); + if(ret != (int)NotificationError.None) + { + throw NotificationErrorFactory.GetException((NotificationError)ret, "post toast message failed"); + } + } + + /// + /// Searches for a posted notification which has the inputted tag + /// + /// Type of notification to be queried + /// Tag used to query + /// Notification Object with inputted tag + 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/Tizen.Applications/Tizen.Applications/ProgressNotification.cs b/Tizen.Applications/Tizen.Applications/ProgressNotification.cs new file mode 100755 index 0000000..725c0e8 --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/ProgressNotification.cs @@ -0,0 +1,116 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +namespace Tizen.Applications.Notifications +{ + /// + /// Class for creating progress notifications + /// + public class ProgressNotification : Notification + { + /// + /// Class contructor + /// + 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. + /// + 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. + /// + 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"); + } + } + } + } +} diff --git a/packaging/csapi-application.spec b/packaging/csapi-application.spec index aaae180..48db9bb 100755 --- a/packaging/csapi-application.spec +++ b/packaging/csapi-application.spec @@ -20,12 +20,12 @@ BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(appcore-agent) BuildRequires: pkgconfig(message-port) -BuildRequires: pkgconfig(capi-appfw-package-manager) +BuildRequires: pkgconfig(notification) Requires: capi-appfw-application Requires: capi-message-port Requires: appcore-agent -Requires: capi-appfw-package-manager +Requires: notification %description Tizen API for C#