summaryrefslogtreecommitdiff
path: root/Tizen.Applications.NotificationEventListener/Tizen.Applications.NotificationEventListener/NotificationEventArgsBinder.cs
blob: e38f331c887aa24585650b75b6318de367625064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Tizen.Applications.NotificationEventListener
{
    using System;

    internal static class NotificationEventArgsBinder
    {
        private const string LogTag = "Tizen.Applications.NotificationEventListener";

        internal static NotificationEventArgs BindObject(IntPtr notification, bool data)
        {
            Interop.NotificationEventListener.ErrorCode err;
            int time;
            int uniqueNumber = -1;
            int groupNumber = -1;
            int property;
            int doNotShowTimeStamp = -1;
            int displayList;
            bool eventFlag = false;
            NotificationLayout layout;
            NotificationType type;
            string text;
            IntPtr extention = IntPtr.Zero;
            IntPtr dummy = IntPtr.Zero;
            SafeAppControlHandle appcontrol = null;

            NotificationEventArgs eventargs = new NotificationEventArgs();

            eventargs.Handle = new Interop.NotificationEventListener.NotificationSafeHandle(notification, data);

            err = Interop.NotificationEventListener.GetID(eventargs.Handle, out groupNumber, out uniqueNumber);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Error(LogTag, "unable to get UniqueNumber");
            }

            eventargs.UniqueNumber = uniqueNumber;

            Interop.NotificationEventListener.GetAppId(eventargs.Handle, out text);
            if (string.IsNullOrEmpty(text) == false)
            {
                eventargs.AppID = text;
            }

            Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.Title, out text);
            if (string.IsNullOrEmpty(text) == false)
            {
                eventargs.Title = text;
            }

            Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.Content, out text);
            if (string.IsNullOrEmpty(text) == false)
            {
                eventargs.Content = text;
            }

            Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Icon, out text);
            if (string.IsNullOrEmpty(text) == false)
            {
                eventargs.Icon = text;
            }

            Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.SubIcon, out text);
            if (string.IsNullOrEmpty(text) == false)
            {
                eventargs.SubIcon = text;
            }

            err = Interop.NotificationEventListener.GetTime(eventargs.Handle, out time);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Info(LogTag, "unable to get TimeStamp");
            }

            if (time == doNotShowTimeStamp)
            {
                eventargs.IsTimeStampVisible = false;
            }
            else
            {
                eventargs.IsTimeStampVisible = true;

                if (time == 0)
                {
                    err = Interop.NotificationEventListener.GetInsertTime(eventargs.Handle, out time);
                    if (err != Interop.NotificationEventListener.ErrorCode.None)
                    {
                        Log.Info(LogTag, "unable to get InsertTime");
                    }
                }

                eventargs.TimeStamp = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(time).ToLocalTime();
            }

            err = Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.EventCount, out text);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Info(LogTag, "unable to get Event Count");
            }

            if (string.IsNullOrEmpty(text) == false)
            {
                try
                {
                    eventargs.Count = int.Parse(text);
                }
                catch (Exception ex)
                {
                    Log.Error(LogTag, ex.ToString());
                }
            }

            err = Interop.NotificationEventListener.GetAppControl(eventargs.Handle, LaunchOption.AppControl, out appcontrol);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Info(LogTag, "unable to get Action");
            }

            if (appcontrol != null && appcontrol.IsInvalid == false)
            {
                eventargs.Action = new AppControl(appcontrol);
            }

            Interop.NotificationEventListener.GetTag(eventargs.Handle, out text);
            if (string.IsNullOrEmpty(text) == false)
            {
                eventargs.Tag = text;
            }

            err = Interop.NotificationEventListener.GetProperties(eventargs.Handle, out property);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Info(LogTag, "unable to get Property");
            }
            else
            {
                eventargs.Property = (NotificationProperty)property;
            }

            Interop.NotificationEventListener.GetStyleList(eventargs.Handle, out displayList);
            if ((displayList & (int)NotificationDisplayApplist.Tray) == 0)
            {
                eventargs.IsDisplay = false;
            }

            err = Interop.NotificationEventListener.GetExtentionBundle(eventargs.Handle, out extention, out dummy);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Info(LogTag, "unable to get Extender");
            }

            if (extention != IntPtr.Zero)
            {
                Bundle bundle = new Bundle(new SafeBundleHandle(extention, false));
                foreach (string key in bundle.Keys)
                {
                    SafeBundleHandle sbh;
                    Interop.NotificationEventListener.GetExtender(eventargs.Handle, key, out sbh);
                    eventargs.Extender.Add(key, new Bundle(sbh));
                }
            }

            err = Interop.NotificationEventListener.GetLayout(eventargs.Handle, out layout);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Info(LogTag, "unable to get layout");
            }

            err = Interop.NotificationEventListener.GetType(eventargs.Handle, out type);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Info(LogTag, "unable to get type");
            }

            if (layout == NotificationLayout.OngoingEvent && type == NotificationType.Ongoing)
            {
                eventargs.IsOngoing = true;
            }

            err = Interop.NotificationEventListener.GetEventFlag(eventargs.Handle, out eventFlag);
            if (err != Interop.NotificationEventListener.ErrorCode.None)
            {
                Log.Info(LogTag, "unable to get event flag");
            }

            eventargs.HasEventFlag = eventFlag;

            NotificationAccessoryAgsBinder.BindObject(eventargs);
            NotificationStyleArgBinder.BindObject(eventargs);
            NotificationProgressArgBinder.BindObject(eventargs);

            return eventargs;
        }
    }
}