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 bool checkBoxFlag = false;
43 bool checkedValue = false;
45 NotificationEventArgs eventargs = new NotificationEventArgs();
47 eventargs.Handle = new Interop.NotificationEventListener.NotificationSafeHandle(notification, data);
49 err = Interop.NotificationEventListener.GetID(eventargs.Handle, out groupNumber, out uniqueNumber);
50 if (err != Interop.NotificationEventListener.ErrorCode.None)
52 Log.Error(LogTag, "unable to get UniqueNumber");
55 eventargs.UniqueNumber = uniqueNumber;
57 Interop.NotificationEventListener.GetAppId(eventargs.Handle, out text);
58 if (string.IsNullOrEmpty(text) == false)
60 eventargs.AppID = text;
63 Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.Title, out text);
64 if (string.IsNullOrEmpty(text) == false)
66 eventargs.Title = text;
69 Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.Content, out text);
70 if (string.IsNullOrEmpty(text) == false)
72 eventargs.Content = text;
75 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Icon, out text);
76 if (string.IsNullOrEmpty(text) == false)
78 eventargs.Icon = text;
81 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.SubIcon, out text);
82 if (string.IsNullOrEmpty(text) == false)
84 eventargs.SubIcon = text;
87 err = Interop.NotificationEventListener.GetTime(eventargs.Handle, out time);
88 if (err != Interop.NotificationEventListener.ErrorCode.None)
90 Log.Info(LogTag, "unable to get TimeStamp");
93 if (time == doNotShowTimeStamp)
95 eventargs.IsTimeStampVisible = false;
99 eventargs.IsTimeStampVisible = true;
103 err = Interop.NotificationEventListener.GetInsertTime(eventargs.Handle, out time);
104 if (err != Interop.NotificationEventListener.ErrorCode.None)
106 Log.Info(LogTag, "unable to get InsertTime");
110 eventargs.TimeStamp = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(time).ToLocalTime();
113 err = Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.EventCount, out text);
114 if (err != Interop.NotificationEventListener.ErrorCode.None)
116 Log.Info(LogTag, "unable to get Event Count");
119 if (string.IsNullOrEmpty(text) == false)
123 eventargs.Count = int.Parse(text);
127 Log.Error(LogTag, ex.ToString());
131 err = Interop.NotificationEventListener.GetAppControl(eventargs.Handle, LaunchOption.AppControl, out appcontrol);
132 if (err != Interop.NotificationEventListener.ErrorCode.None)
134 Log.Info(LogTag, "unable to get Action");
137 if (appcontrol != null && appcontrol.IsInvalid == false)
139 eventargs.Action = new AppControl(appcontrol);
142 Interop.NotificationEventListener.GetTag(eventargs.Handle, out text);
143 if (string.IsNullOrEmpty(text) == false)
145 eventargs.Tag = text;
148 err = Interop.NotificationEventListener.GetProperties(eventargs.Handle, out property);
149 if (err != Interop.NotificationEventListener.ErrorCode.None)
151 Log.Info(LogTag, "unable to get Property");
155 eventargs.Property = (NotificationProperty)property;
158 Interop.NotificationEventListener.GetStyleList(eventargs.Handle, out displayList);
159 if ((displayList & (int)NotificationDisplayApplist.Tray) == 0)
161 eventargs.IsVisible = false;
164 err = Interop.NotificationEventListener.GetExtensionBundle(eventargs.Handle, out extension, out dummy);
165 if (err != Interop.NotificationEventListener.ErrorCode.None)
167 Log.Info(LogTag, "unable to get Extender");
170 if (extension != IntPtr.Zero)
172 Bundle bundle = new Bundle(new SafeBundleHandle(extension, false));
173 foreach (string key in bundle.Keys)
175 if (key.StartsWith("_NOTIFICATION_EXTENSION_EVENT_"))
178 SafeBundleHandle sbh;
179 Interop.NotificationEventListener.GetExtender(eventargs.Handle, key, out sbh);
180 eventargs.ExtraData.Add(key, new Bundle(sbh));
184 err = Interop.NotificationEventListener.GetLayout(eventargs.Handle, out layout);
185 if (err != Interop.NotificationEventListener.ErrorCode.None)
187 Log.Info(LogTag, "unable to get layout");
190 err = Interop.NotificationEventListener.GetType(eventargs.Handle, out type);
191 if (err != Interop.NotificationEventListener.ErrorCode.None)
193 Log.Info(LogTag, "unable to get type");
196 if (layout == NotificationLayout.OngoingEvent && type == NotificationType.Ongoing)
198 eventargs.IsOngoing = true;
201 err = Interop.NotificationEventListener.GetEventFlag(eventargs.Handle, out eventFlag);
202 if (err != Interop.NotificationEventListener.ErrorCode.None)
204 Log.Info(LogTag, "unable to get event flag");
207 eventargs.HasEventFlag = eventFlag;
209 err = Interop.NotificationEventListener.GetCheckBox(eventargs.Handle, out checkBoxFlag, out checkedValue);
210 if (err != Interop.NotificationEventListener.ErrorCode.None)
212 Log.Error(LogTag, "unable to get checkbox flag");
215 eventargs.CheckBox = checkBoxFlag;
216 eventargs.CheckedValue = checkedValue;
218 NotificationAccessoryAgsBinder.BindObject(eventargs);
219 NotificationStyleArgBinder.BindObject(eventargs);
220 NotificationProgressArgBinder.BindObject(eventargs);