Add check box for notification (#5342)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.NotificationEventListener / Tizen.Applications.NotificationEventListener / NotificationEventArgsBinder.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 namespace Tizen.Applications.NotificationEventListener
18 {
19     using System;
20
21     internal static class NotificationEventArgsBinder
22     {
23         private const string LogTag = "Tizen.Applications.NotificationEventListener";
24
25         internal static NotificationEventArgs BindObject(IntPtr notification, bool data)
26         {
27             Interop.NotificationEventListener.ErrorCode err;
28             int time;
29             int uniqueNumber = -1;
30             int groupNumber = -1;
31             int property;
32             int doNotShowTimeStamp = -1;
33             int displayList;
34             bool eventFlag = false;
35             NotificationLayout layout;
36             NotificationType type;
37             string text;
38             IntPtr extension = IntPtr.Zero;
39             IntPtr dummy = IntPtr.Zero;
40             SafeAppControlHandle appcontrol = null;
41
42             bool checkBoxFlag = false;
43             bool checkedValue = false;
44
45             NotificationEventArgs eventargs = new NotificationEventArgs();
46
47             eventargs.Handle = new Interop.NotificationEventListener.NotificationSafeHandle(notification, data);
48
49             err = Interop.NotificationEventListener.GetID(eventargs.Handle, out groupNumber, out uniqueNumber);
50             if (err != Interop.NotificationEventListener.ErrorCode.None)
51             {
52                 Log.Error(LogTag, "unable to get UniqueNumber");
53             }
54
55             eventargs.UniqueNumber = uniqueNumber;
56
57             Interop.NotificationEventListener.GetAppId(eventargs.Handle, out text);
58             if (string.IsNullOrEmpty(text) == false)
59             {
60                 eventargs.AppID = text;
61             }
62
63             Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.Title, out text);
64             if (string.IsNullOrEmpty(text) == false)
65             {
66                 eventargs.Title = text;
67             }
68
69             Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.Content, out text);
70             if (string.IsNullOrEmpty(text) == false)
71             {
72                 eventargs.Content = text;
73             }
74
75             Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Icon, out text);
76             if (string.IsNullOrEmpty(text) == false)
77             {
78                 eventargs.Icon = text;
79             }
80
81             Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.SubIcon, out text);
82             if (string.IsNullOrEmpty(text) == false)
83             {
84                 eventargs.SubIcon = text;
85             }
86
87             err = Interop.NotificationEventListener.GetTime(eventargs.Handle, out time);
88             if (err != Interop.NotificationEventListener.ErrorCode.None)
89             {
90                 Log.Info(LogTag, "unable to get TimeStamp");
91             }
92
93             if (time == doNotShowTimeStamp)
94             {
95                 eventargs.IsTimeStampVisible = false;
96             }
97             else
98             {
99                 eventargs.IsTimeStampVisible = true;
100
101                 if (time == 0)
102                 {
103                     err = Interop.NotificationEventListener.GetInsertTime(eventargs.Handle, out time);
104                     if (err != Interop.NotificationEventListener.ErrorCode.None)
105                     {
106                         Log.Info(LogTag, "unable to get InsertTime");
107                     }
108                 }
109
110                 eventargs.TimeStamp = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(time).ToLocalTime();
111             }
112
113             err = Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.EventCount, out text);
114             if (err != Interop.NotificationEventListener.ErrorCode.None)
115             {
116                 Log.Info(LogTag, "unable to get Event Count");
117             }
118
119             if (string.IsNullOrEmpty(text) == false)
120             {
121                 try
122                 {
123                     eventargs.Count = int.Parse(text);
124                 }
125                 catch (Exception ex)
126                 {
127                     Log.Error(LogTag, ex.ToString());
128                 }
129             }
130
131             err = Interop.NotificationEventListener.GetAppControl(eventargs.Handle, LaunchOption.AppControl, out appcontrol);
132             if (err != Interop.NotificationEventListener.ErrorCode.None)
133             {
134                 Log.Info(LogTag, "unable to get Action");
135             }
136
137             if (appcontrol != null && appcontrol.IsInvalid == false)
138             {
139                 eventargs.Action = new AppControl(appcontrol);
140             }
141
142             Interop.NotificationEventListener.GetTag(eventargs.Handle, out text);
143             if (string.IsNullOrEmpty(text) == false)
144             {
145                 eventargs.Tag = text;
146             }
147
148             err = Interop.NotificationEventListener.GetProperties(eventargs.Handle, out property);
149             if (err != Interop.NotificationEventListener.ErrorCode.None)
150             {
151                 Log.Info(LogTag, "unable to get Property");
152             }
153             else
154             {
155                 eventargs.Property = (NotificationProperty)property;
156             }
157
158             Interop.NotificationEventListener.GetStyleList(eventargs.Handle, out displayList);
159             if ((displayList & (int)NotificationDisplayApplist.Tray) == 0)
160             {
161                 eventargs.IsVisible = false;
162             }
163
164             err = Interop.NotificationEventListener.GetExtensionBundle(eventargs.Handle, out extension, out dummy);
165             if (err != Interop.NotificationEventListener.ErrorCode.None)
166             {
167                 Log.Info(LogTag, "unable to get Extender");
168             }
169
170             if (extension != IntPtr.Zero)
171             {
172                 Bundle bundle = new Bundle(new SafeBundleHandle(extension, false));
173                 foreach (string key in bundle.Keys)
174                 {
175                     if (key.StartsWith("_NOTIFICATION_EXTENSION_EVENT_"))
176                         continue;
177
178                     SafeBundleHandle sbh;
179                     Interop.NotificationEventListener.GetExtender(eventargs.Handle, key, out sbh);
180                     eventargs.ExtraData.Add(key, new Bundle(sbh));
181                 }
182             }
183
184             err = Interop.NotificationEventListener.GetLayout(eventargs.Handle, out layout);
185             if (err != Interop.NotificationEventListener.ErrorCode.None)
186             {
187                 Log.Info(LogTag, "unable to get layout");
188             }
189
190             err = Interop.NotificationEventListener.GetType(eventargs.Handle, out type);
191             if (err != Interop.NotificationEventListener.ErrorCode.None)
192             {
193                 Log.Info(LogTag, "unable to get type");
194             }
195
196             if (layout == NotificationLayout.OngoingEvent && type == NotificationType.Ongoing)
197             {
198                 eventargs.IsOngoing = true;
199             }
200
201             err = Interop.NotificationEventListener.GetEventFlag(eventargs.Handle, out eventFlag);
202             if (err != Interop.NotificationEventListener.ErrorCode.None)
203             {
204                 Log.Info(LogTag, "unable to get event flag");
205             }
206
207             eventargs.HasEventFlag = eventFlag;
208
209             err = Interop.NotificationEventListener.GetCheckBox(eventargs.Handle, out checkBoxFlag, out checkedValue);
210             if (err != Interop.NotificationEventListener.ErrorCode.None)
211             {
212                 Log.Error(LogTag, "unable to get checkbox flag");
213             }
214
215             eventargs.CheckBox = checkBoxFlag;
216             eventargs.CheckedValue = checkedValue;
217
218             NotificationAccessoryAgsBinder.BindObject(eventargs);
219             NotificationStyleArgBinder.BindObject(eventargs);
220             NotificationProgressArgBinder.BindObject(eventargs);
221
222             return eventargs;
223         }
224     }
225 }