Release 4.0.0-preview1-00083
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.NotificationEventListener / Tizen.Applications.NotificationEventListener / NotificationStyleArgsBinder.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 NotificationStyleArgBinder
22     {
23         internal static void BindObject(NotificationEventArgs eventargs)
24         {
25             bool autoRemove;
26             string path;
27             int styleList;
28             int timeout;
29             SafeAppControlHandle appcontrol = null;
30
31             Interop.NotificationEventListener.GetStyleList(eventargs.Handle, out styleList);
32
33             if ((styleList & (int)NotificationDisplayApplist.Active) != 0)
34             {
35                 NotificationEventArgs.ActiveStyleArgs activeStyle = new NotificationEventArgs.ActiveStyleArgs();
36                 eventargs.Style.Add(activeStyle.Key, activeStyle);
37
38                 for (int i = (int)ClickEventType.FirstButton; i <= (int)ClickEventType.ThirdButton; i++)
39                 {
40                     NotificationButtonActionArgBinder.BindObject(eventargs, i);
41                 }
42
43                 Interop.NotificationEventListener.GetAutoRemove(eventargs.Handle, out autoRemove);
44                 activeStyle.IsAutoRemove = autoRemove;
45
46                 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Background, out path);
47                 activeStyle.BackgroundImage = path;
48
49                 int index;
50                 Interop.NotificationEventListener.GetDefaultButton(eventargs.Handle, out index);
51                 activeStyle.DefaultButton = (ButtonIndex)(index - 1);
52
53                 Interop.NotificationEventListener.GetHideTimeout(eventargs.Handle, out timeout);
54                 activeStyle.HideTimeout = timeout;
55
56                 try
57                 {
58                     Interop.NotificationEventListener.GetDeleteTimeout(eventargs.Handle, out timeout);
59                 }
60                 catch (TypeLoadException)
61                 {
62                     //To support in API version 3.0
63                     timeout = 60;
64                 }
65                 activeStyle.DeleteTimeout = timeout;
66
67                 appcontrol = null;
68                 Interop.NotificationEventListener.GetExtensionAction(eventargs.Handle, UserEventType.HiddenByUser, out appcontrol);
69                 if (appcontrol != null && appcontrol.IsInvalid == false)
70                 {
71                     activeStyle.HiddenByUserAction = new AppControl(appcontrol);
72                 }
73
74                 appcontrol = null;
75                 Interop.NotificationEventListener.GetExtensionAction(eventargs.Handle, UserEventType.HiddenByTimeout, out appcontrol);
76                 if (appcontrol != null && appcontrol.IsInvalid == false)
77                 {
78                     activeStyle.HiddenByTimeoutAction = new AppControl(appcontrol);
79                 }
80
81                 appcontrol = null;
82                 Interop.NotificationEventListener.GetExtensionAction(eventargs.Handle, UserEventType.HiddenByExternal, out appcontrol);
83                 if (appcontrol != null && appcontrol.IsInvalid == false)
84                 {
85                     activeStyle.HiddenByExternalAction = new AppControl(appcontrol);
86                 }
87
88                 NotificationReplyActionArgBinder.BindObject(eventargs);
89             }
90
91             if ((styleList & (int)NotificationDisplayApplist.Lock) != 0)
92             {
93                 NotificationEventArgs.LockStyleArgs lockStyle = new NotificationEventArgs.LockStyleArgs();
94                 eventargs.Style.Add(lockStyle.Key, lockStyle);
95
96                 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Lockscreen, out path);
97                 lockStyle.IconPath = path;
98
99                 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.ThumbnailLockscreen, out path);
100                 lockStyle.Thumbnail = path;
101             }
102
103             if ((styleList & (int)NotificationDisplayApplist.Ticker) != 0 || (styleList & (int)NotificationDisplayApplist.Indicator) != 0)
104             {
105                 NotificationEventArgs.IndicatorStyleArgs indicatorStyle = new NotificationEventArgs.IndicatorStyleArgs();
106                 eventargs.Style.Add(indicatorStyle.Key, indicatorStyle);
107
108                 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Indicator, out path);
109                 indicatorStyle.IconPath = path;
110
111                 Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.FirstMainText, out path);
112                 indicatorStyle.SubText = path;
113             }
114        }
115     }
116 }