From: Hyunho Kang Date: Thu, 10 Jun 2021 05:53:23 +0000 (+0900) Subject: Add Internal Notification Response Event handler (#3178) X-Git-Tag: submit/tizen_6.0/20210610.151833~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=223abc2813d2c9a972b435fded8e7a574be24d9c;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add Internal Notification Response Event handler (#3178) * Add ViewerEventReceived event handler Signed-off-by: Hyunho * Fix wrongly handled unmanaged codes Signed-off-by: Hyunho * Fix api name and wrongly managed handle Signed-off-by: Hyunho * Add missing files Signed-off-by: Hyunho * Add newline for the end of file Signed-off-by: Hyunho * Change throw -> Log for unmanaged callback Signed-off-by: Hyunho * Update since tag 9 to 8 Signed-off-by: Hyunho --- diff --git a/src/Tizen.Applications.Notification/Interop/Interop.Notification.cs b/src/Tizen.Applications.Notification/Interop/Interop.Notification.cs old mode 100755 new mode 100644 index 1d5651b34..aa900fd3c --- a/src/Tizen.Applications.Notification/Interop/Interop.Notification.cs +++ b/src/Tizen.Applications.Notification/Interop/Interop.Notification.cs @@ -23,6 +23,8 @@ internal static partial class Interop { internal static class Notification { + internal delegate void ResponseEventCallback(IntPtr ptr, int type, IntPtr userData); + [DllImport(Libraries.Notification, EntryPoint = "notification_create")] internal static extern IntPtr Create(NotificationType type); @@ -131,6 +133,9 @@ internal static partial class Interop [DllImport(Libraries.Notification, EntryPoint = "notification_post")] internal static extern NotificationError Post(NotificationSafeHandle handle); + [DllImport(Libraries.Notification, EntryPoint = "notification_post_with_event_cb")] + internal static extern NotificationError PostWithEventCallback(NotificationSafeHandle handle, ResponseEventCallback cb, IntPtr userdata); + [DllImport(Libraries.Notification, EntryPoint = "notification_get_pkgname")] internal static extern NotificationError GetPackageName(NotificationSafeHandle handle, out IntPtr name); @@ -224,6 +229,9 @@ internal static partial class Interop [DllImport(Libraries.Notification, EntryPoint = "notification_get_extension_event_handler")] internal static extern NotificationError GetExtensionAction(NotificationSafeHandle handle, NotificationEventType type, out SafeAppControlHandle appcontrol); + [DllImport(Libraries.Notification, EntryPoint = "notification_clone")] + internal static extern NotificationError Clone(IntPtr handle, out IntPtr cloned); + internal static NotificationError GetText(NotificationSafeHandle handle, NotificationText type, out string text) { NotificationError ret; diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs old mode 100755 new mode 100644 index 5ef8dd1f8..aadca4ec6 --- a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs @@ -25,6 +25,55 @@ namespace Tizen.Applications.Notifications /// 3 public static class NotificationManager { + private static event EventHandler ResponseEventHandler; + + private static Interop.Notification.ResponseEventCallback responseEventCallback; + + private static void ResponseEventCallback(IntPtr ptr, int type, IntPtr userData) + { + IntPtr cloned; + NotificationError ret = Interop.Notification.Clone(ptr, out cloned); + if (ret != NotificationError.None) + { + Log.Error(Notification.LogTag, "Fail to clone notification : " + ret.ToString()); + return; + } + + NotificationResponseEventArgs eventArgs = new NotificationResponseEventArgs(); + eventArgs.EventType = (NotificationResponseEventType)type; + eventArgs.Notification = new Notification + { + Handle = new NotificationSafeHandle(cloned, true) + }.Build(); + ResponseEventHandler?.Invoke(null, eventArgs); + } + + /// + /// The event handler for receiving a response event from the notification viewers + /// + /// 8 + [EditorBrowsable(EditorBrowsableState.Never)] + public static event EventHandler ResponseReceived + { + add + { + if (responseEventCallback == null) + { + responseEventCallback = new Interop.Notification.ResponseEventCallback(ResponseEventCallback); + } + + ResponseEventHandler += value; + } + + remove + { + if (ResponseEventHandler != null && ResponseEventHandler.GetInvocationList().Length > 0) + { + ResponseEventHandler -= value; + } + } + } + /// /// Posts a new notification. /// @@ -65,11 +114,22 @@ namespace Tizen.Applications.Notifications notification.Make(); - NotificationError ret = Interop.Notification.Post(notification.Handle); - if (ret != NotificationError.None) + if (ResponseEventHandler != null && ResponseEventHandler.GetInvocationList().Length > 0) { - throw NotificationErrorFactory.GetException(ret, "post notification failed"); + NotificationError ret = Interop.Notification.PostWithEventCallback(notification.Handle, responseEventCallback, IntPtr.Zero); + if (ret != NotificationError.None) + { + throw NotificationErrorFactory.GetException(ret, "post notification with event callback failed"); + } } + else + { + 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); diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationResponseEventArgs.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationResponseEventArgs.cs new file mode 100644 index 000000000..ccc632c24 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationResponseEventArgs.cs @@ -0,0 +1,25 @@ +using System; +using System.ComponentModel; + +namespace Tizen.Applications.Notifications +{ + /// + /// The EventArgs for the notification response + /// + /// 8 + [EditorBrowsable(EditorBrowsableState.Never)] + public class NotificationResponseEventArgs : EventArgs + { + /// + /// The type of response + /// + /// 8 + public NotificationResponseEventType EventType { get; internal set; } + + /// + /// The response's target notification + /// + /// 8 + public Notification Notification { get; internal set; } + } +} diff --git a/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationResponseEventType.cs b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationResponseEventType.cs new file mode 100644 index 000000000..b03f10ef3 --- /dev/null +++ b/src/Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationResponseEventType.cs @@ -0,0 +1,58 @@ + +using System.ComponentModel; + +namespace Tizen.Applications.Notifications +{ + /// + /// Enumeration for event type on notification. + /// + /// 8 + [EditorBrowsable(EditorBrowsableState.Never)] + public enum NotificationResponseEventType + { + /// + /// Event type : Click on button 1. + /// + ClickOnButton1 = 0, + + /// + /// Event type : Click on button 2. + /// + ClickOnButton2, + + /// + /// Event type : Click on button 3. + /// + ClickOnButton3, + + /// + /// Event type : Click on text_input button. + /// + ClickOnReplyButton = 8, + + /// + /// Event type : Hidden by user. + /// + HiddenByUser = 100, + + /// + /// Event type : Deleted by timer. + /// + HiddenByTimeout = 101, + + /// + /// Event type : Deleted by timer. + /// + HiddenByExternal = 102, + + /// + /// Event type : Clicked by user. + /// + ClickOnNotification = 200, + + /// + /// Event type : Deleted by user. + /// + DeleteNotification = 201, + } +}