Release 4.0.0-preview1-00051
[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
30             Interop.NotificationEventListener.GetStyleList(eventargs.Handle, out styleList);
31
32             if ((styleList & (int)NotificationDisplayApplist.Active) != 0)
33             {
34                 NotificationEventArgs.ActiveStyleArgs activeStyle = new NotificationEventArgs.ActiveStyleArgs();
35                 eventargs.Style.Add(activeStyle.Key, activeStyle);
36
37                 for (int i = (int)ClickEventType.FirstButton; i <= (int)ClickEventType.ThirdButton; i++)
38                 {
39                     NotificationButtonActionArgBinder.BindObject(eventargs, i);
40                 }
41
42                 Interop.NotificationEventListener.GetAutoRemove(eventargs.Handle, out autoRemove);
43                 activeStyle.IsAutoRemove = autoRemove;
44
45                 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Background, out path);
46                 activeStyle.BackgroundImage = path;
47
48                 int index;
49                 Interop.NotificationEventListener.GetDefaultButton(eventargs.Handle, out index);
50                 activeStyle.DefaultButton = (ButtonIndex)(index - 1);
51
52                 Interop.NotificationEventListener.GetHideTimeout(eventargs.Handle, out timeout);
53                 activeStyle.HideTimeout = timeout;
54
55                 try
56                 {
57                     Interop.NotificationEventListener.GetDeleteTimeout(eventargs.Handle, out timeout);
58                 }
59                 catch (TypeLoadException)
60                 {
61                     //To support in API version 3.0
62                     timeout = 60;
63                 }
64                 activeStyle.DeleteTimeout = timeout;
65
66                 NotificationReplyActionArgBinder.BindObject(eventargs);
67             }
68
69             if ((styleList & (int)NotificationDisplayApplist.Lock) != 0)
70             {
71                 NotificationEventArgs.LockStyleArgs lockStyle = new NotificationEventArgs.LockStyleArgs();
72                 eventargs.Style.Add(lockStyle.Key, lockStyle);
73
74                 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Lockscreen, out path);
75                 lockStyle.IconPath = path;
76
77                 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.ThumbnailLockscreen, out path);
78                 lockStyle.Thumbnail = path;
79             }
80
81             if ((styleList & (int)NotificationDisplayApplist.Ticker) != 0 || (styleList & (int)NotificationDisplayApplist.Indicator) != 0)
82             {
83                 NotificationEventArgs.IndicatorStyleArgs indicatorStyle = new NotificationEventArgs.IndicatorStyleArgs();
84                 eventargs.Style.Add(indicatorStyle.Key, indicatorStyle);
85
86                 Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.Indicator, out path);
87                 indicatorStyle.IconPath = path;
88
89                 Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.FirstMainText, out path);
90                 indicatorStyle.SubText = path;
91             }
92        }
93     }
94 }