2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 namespace Tizen.Applications.NotificationEventListener
21 internal static class NotificationEventArgsBinder
23 private const string LogTag = "Tizen.Applications.NotificationEventListener";
25 internal static NotificationEventArgs BindObject(IntPtr notification, bool data)
27 Interop.NotificationEventListener.ErrorCode err;
29 int uniqueNumber = -1;
32 int doNotShowTimeStamp = -1;
34 bool eventFlag = false;
35 NotificationLayout layout;
36 NotificationType type;
38 IntPtr extension = IntPtr.Zero;
39 IntPtr dummy = IntPtr.Zero;
40 SafeAppControlHandle appcontrol = null;
42 NotificationEventArgs eventargs = new NotificationEventArgs();
44 eventargs.Handle = new Interop.NotificationEventListener.NotificationSafeHandle(notification, data);
46 err = Interop.NotificationEventListener.GetID(eventargs.Handle, out groupNumber, out uniqueNumber);
47 if (err != Interop.NotificationEventListener.ErrorCode.None)
49 Log.Error(LogTag, "unable to get UniqueNumber");
52 eventargs.UniqueNumber = uniqueNumber;
54 Interop.NotificationEventListener.GetAppId(eventargs.Handle, out text);
55 if (string.IsNullOrEmpty(text) == false)
57 eventargs.AppID = text;
60 Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.Title, out text);
61 if (string.IsNullOrEmpty(text) == false)
63 eventargs.Title = text;
66 Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.Content, out text);
67 if (string.IsNullOrEmpty(text) == false)
69 eventargs.Content = text;
72 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Icon, out text);
73 if (string.IsNullOrEmpty(text) == false)
75 eventargs.Icon = text;
78 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.SubIcon, out text);
79 if (string.IsNullOrEmpty(text) == false)
81 eventargs.SubIcon = text;
84 err = Interop.NotificationEventListener.GetTime(eventargs.Handle, out time);
85 if (err != Interop.NotificationEventListener.ErrorCode.None)
87 Log.Info(LogTag, "unable to get TimeStamp");
90 if (time == doNotShowTimeStamp)
92 eventargs.IsTimeStampVisible = false;
96 eventargs.IsTimeStampVisible = true;
100 err = Interop.NotificationEventListener.GetInsertTime(eventargs.Handle, out time);
101 if (err != Interop.NotificationEventListener.ErrorCode.None)
103 Log.Info(LogTag, "unable to get InsertTime");
107 eventargs.TimeStamp = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(time).ToLocalTime();
110 err = Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.EventCount, out text);
111 if (err != Interop.NotificationEventListener.ErrorCode.None)
113 Log.Info(LogTag, "unable to get Event Count");
116 if (string.IsNullOrEmpty(text) == false)
120 eventargs.Count = int.Parse(text);
124 Log.Error(LogTag, ex.ToString());
128 err = Interop.NotificationEventListener.GetAppControl(eventargs.Handle, LaunchOption.AppControl, out appcontrol);
129 if (err != Interop.NotificationEventListener.ErrorCode.None)
131 Log.Info(LogTag, "unable to get Action");
134 if (appcontrol != null && appcontrol.IsInvalid == false)
136 eventargs.Action = new AppControl(appcontrol);
139 Interop.NotificationEventListener.GetTag(eventargs.Handle, out text);
140 if (string.IsNullOrEmpty(text) == false)
142 eventargs.Tag = text;
145 err = Interop.NotificationEventListener.GetProperties(eventargs.Handle, out property);
146 if (err != Interop.NotificationEventListener.ErrorCode.None)
148 Log.Info(LogTag, "unable to get Property");
152 eventargs.Property = (NotificationProperty)property;
155 Interop.NotificationEventListener.GetStyleList(eventargs.Handle, out displayList);
156 if ((displayList & (int)NotificationDisplayApplist.Tray) == 0)
158 eventargs.IsVisible = false;
161 err = Interop.NotificationEventListener.GetExtensionBundle(eventargs.Handle, out extension, out dummy);
162 if (err != Interop.NotificationEventListener.ErrorCode.None)
164 Log.Info(LogTag, "unable to get Extender");
167 if (extension != IntPtr.Zero)
169 Bundle bundle = new Bundle(new SafeBundleHandle(extension, false));
170 foreach (string key in bundle.Keys)
172 if (key.StartsWith("_NOTIFICATION_EXTENSION_EVENT_"))
175 SafeBundleHandle sbh;
176 Interop.NotificationEventListener.GetExtender(eventargs.Handle, key, out sbh);
177 eventargs.ExtraData.Add(key, new Bundle(sbh));
181 err = Interop.NotificationEventListener.GetLayout(eventargs.Handle, out layout);
182 if (err != Interop.NotificationEventListener.ErrorCode.None)
184 Log.Info(LogTag, "unable to get layout");
187 err = Interop.NotificationEventListener.GetType(eventargs.Handle, out type);
188 if (err != Interop.NotificationEventListener.ErrorCode.None)
190 Log.Info(LogTag, "unable to get type");
193 if (layout == NotificationLayout.OngoingEvent && type == NotificationType.Ongoing)
195 eventargs.IsOngoing = true;
198 err = Interop.NotificationEventListener.GetEventFlag(eventargs.Handle, out eventFlag);
199 if (err != Interop.NotificationEventListener.ErrorCode.None)
201 Log.Info(LogTag, "unable to get event flag");
204 eventargs.HasEventFlag = eventFlag;
206 NotificationAccessoryAgsBinder.BindObject(eventargs);
207 NotificationStyleArgBinder.BindObject(eventargs);
208 NotificationProgressArgBinder.BindObject(eventargs);