{
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);
[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);
[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;
/// <since_tizen> 3 </since_tizen>
public static class NotificationManager
{
+ private static event EventHandler<NotificationResponseEventArgs> 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);
+ }
+
+ /// <summary>
+ /// The event handler for receiving a response event from the notification viewers
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static event EventHandler<NotificationResponseEventArgs> ResponseReceived
+ {
+ add
+ {
+ if (responseEventCallback == null)
+ {
+ responseEventCallback = new Interop.Notification.ResponseEventCallback(ResponseEventCallback);
+ }
+
+ ResponseEventHandler += value;
+ }
+
+ remove
+ {
+ if (ResponseEventHandler != null && ResponseEventHandler.GetInvocationList().Length > 0)
+ {
+ ResponseEventHandler -= value;
+ }
+ }
+ }
+
/// <summary>
/// Posts a new notification.
/// </summary>
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);
--- /dev/null
+using System;
+using System.ComponentModel;
+
+namespace Tizen.Applications.Notifications
+{
+ /// <summary>
+ /// The EventArgs for the notification response
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class NotificationResponseEventArgs : EventArgs
+ {
+ /// <summary>
+ /// The type of response
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public NotificationResponseEventType EventType { get; internal set; }
+
+ /// <summary>
+ /// The response's target notification
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public Notification Notification { get; internal set; }
+ }
+}
--- /dev/null
+
+using System.ComponentModel;
+
+namespace Tizen.Applications.Notifications
+{
+ /// <summary>
+ /// Enumeration for event type on notification.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public enum NotificationResponseEventType
+ {
+ /// <summary>
+ /// Event type : Click on button 1.
+ /// </summary>
+ ClickOnButton1 = 0,
+
+ /// <summary>
+ /// Event type : Click on button 2.
+ /// </summary>
+ ClickOnButton2,
+
+ /// <summary>
+ /// Event type : Click on button 3.
+ /// </summary>
+ ClickOnButton3,
+
+ /// <summary>
+ /// Event type : Click on text_input button.
+ /// </summary>
+ ClickOnReplyButton = 8,
+
+ /// <summary>
+ /// Event type : Hidden by user.
+ /// </summary>
+ HiddenByUser = 100,
+
+ /// <summary>
+ /// Event type : Deleted by timer.
+ /// </summary>
+ HiddenByTimeout = 101,
+
+ /// <summary>
+ /// Event type : Deleted by timer.
+ /// </summary>
+ HiddenByExternal = 102,
+
+ /// <summary>
+ /// Event type : Clicked by user.
+ /// </summary>
+ ClickOnNotification = 200,
+
+ /// <summary>
+ /// Event type : Deleted by user.
+ /// </summary>
+ DeleteNotification = 201,
+ }
+}