Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.NotificationEventListener / Tizen.Applications.NotificationEventListener / NotificationReplyActionArgsBinder.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 NotificationReplyActionArgBinder
22     {
23         private const string LogTag = "Tizen.Applications.NotificationEventListener";
24
25         internal static void BindObject(NotificationEventArgs eventargs)
26         {
27             string text;
28             int max;
29             bool isExisted = false;
30             SafeAppControlHandle appcontrol = null;
31             Bundle bundle;
32             NotificationEventArgs.ReplyActionArgs reply = new NotificationEventArgs.ReplyActionArgs();
33             NotificationEventArgs.ButtonActionArgs button = new NotificationEventArgs.ButtonActionArgs();
34             string replyKey = "__PARENT_INDEX__";
35
36             Interop.NotificationEventListener.GetImage(eventargs.Handle, NotificationImage.TextInputButton, out text);
37             if (string.IsNullOrEmpty(text) == false)
38             {
39                 isExisted = true;
40                 button.ImagePath = text;
41             }
42
43             Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.InputButton, out text);
44             if (string.IsNullOrEmpty(text) == false)
45             {
46                 isExisted = true;
47                 button.Text = text;
48             }
49
50             Interop.NotificationEventListener.GetEventHandler(eventargs.Handle, (int)ClickEventType.InputButton, out appcontrol);
51
52             if (appcontrol != null && appcontrol.IsInvalid == false)
53             {
54                 button.Action = new AppControl(appcontrol);
55                 isExisted = true;
56             }
57
58             reply.Button = button;
59
60             Interop.NotificationEventListener.GetText(eventargs.Handle, NotificationText.PlaceHolder, out text);
61
62             if (string.IsNullOrEmpty(text) == false)
63             {
64                 isExisted = true;
65                 reply.PlaceHolderText = text;
66             }
67
68             Interop.NotificationEventListener.GetPlaceHolderLength(eventargs.Handle, out max);
69             reply.ReplyMax = max;
70             if (max > 0)
71             {
72                 isExisted = true;
73             }
74
75             if (eventargs.Extender.TryGetValue(replyKey, out bundle))
76             {
77                 if (bundle.Contains(replyKey))
78                 {
79                     string parentIndex;
80                     if (bundle.TryGetItem(replyKey, out parentIndex))
81                     {
82                         try
83                         {
84                             reply.ParentIndex = (ButtonIndex)int.Parse(parentIndex);
85                             isExisted = true;
86                         }
87                         catch (Exception ex)
88                         {
89                             Log.Error(LogTag, "unable to get ParentIndex " + ex.Message);
90                         }
91                     }
92                 }
93             }
94
95             if (isExisted)
96             {
97                 (eventargs.Style["Active"] as NotificationEventArgs.ActiveStyleArgs).Reply = reply;
98             }
99         }
100     }
101 }