Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Notification / Tizen.Applications.Notifications / NotificationReplyAction.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.Notifications
18 {
19     /// <summary>
20     /// Class containing common properties and methods of Notifications
21     /// </summary>
22     /// <remarks>
23     /// A notification is a message that is displayed on the notification area.
24     /// It is created to notify information to the user through the application.
25     /// This class helps you to provide method and property for creating notification object.
26     /// </remarks>
27     public sealed partial class Notification
28     {
29         /// <summary>
30         ///  Class for displaying direct-reply at notification.
31         ///  You must set a ReplyMax and Button. Otherwise user can't send written text to application which is set by AppControl.
32         /// </summary>
33         public sealed class ReplyAction : MakerBase
34         {
35             /// <summary>
36             /// Gets or sets the Index of Button which is appeared at Notification.
37             /// If you set ParentIndex, ReplyAction is displayed when button matched with ParentIndex click by the user.
38             /// If you don't set ParentIndex, appeared to notification directly.
39             /// </summary>
40             public ButtonIndex ParentIndex { get; set; } = ButtonIndex.None;
41
42             /// <summary>
43             /// Gets or sets the PlaceHolderText of ReplyAction which is appeared at Notification.
44             /// If you set PlaceHolderText, it is displayed to placeholder in notification.
45             /// </summary>
46             public string PlaceHolderText { get; set; }
47
48             /// <summary>
49             /// Gets or sets the ReplyMax of ReplyAction which is appeared at Notification.
50             /// You must set a ReplyMax. Otherwise user don't write text to placeholder in notification.
51             /// </summary>
52             /// <value>
53             /// Default value is 160.
54             /// </value>
55             public int ReplyMax { get; set; } = 160;
56
57             /// <summary>
58             /// Gets or sets the Button which is appeared to ReplyAction in Notification.
59             /// You must set a Button. Otherwise user can't send written text to application which is set by AppControl.
60             /// </summary>
61             /// <remarks>
62             /// If you set it to null, the already set ButtonAction will be removed.
63             /// </remarks>
64             /// <example>
65             /// <code>
66             /// ReplyAction button = new ReplyAction
67             /// {
68             ///     ParentIndex = ButtonIndex.Second;
69             ///     PlaceHolderText = "Please write your reply."
70             ///     ReplyMax = 160,
71             ///     Button = new ButtonAction
72             ///     {
73             ///         text = "Yes",
74             ///         ImagePath = "image path",
75             ///         Action = new AppControl{ ApplicationId = "org.tizen.app" };
76             ///     };
77             /// };
78             /// </code>
79             /// </example>
80             public ButtonAction Button { get; set; }
81
82             internal override void Make(Notification notification)
83             {
84                 string replyKey = "__PARENT_INDEX__";
85
86                 if (Button != null)
87                 {
88                     Interop.Notification.SetText(notification.Handle, NotificationText.InputButton, Button.Text, null, -1);
89                     Interop.Notification.SetImage(notification.Handle, NotificationImage.TextInputButton, Button.ImagePath);
90
91                     if (this.Button.Action != null && this.Button.Action.SafeAppControlHandle.IsInvalid == false)
92                     {
93                         Interop.Notification.SetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, this.Button.Action.SafeAppControlHandle);
94
95                         if (this.ParentIndex != ButtonIndex.None)
96                         {
97                             Interop.Notification.SetEventHandler(notification.Handle, (int)this.ParentIndex, this.Button.Action.SafeAppControlHandle);
98                         }
99                     }
100                 }
101
102                 Bundle bundle = new Bundle();
103                 bundle.AddItem(replyKey, ((int)this.ParentIndex).ToString());
104                 Interop.Notification.SetExtentionData(notification.Handle, replyKey, bundle.SafeBundleHandle);
105
106                 Interop.Notification.SetPlaceHolderLength(notification.Handle, this.ReplyMax);
107                 Interop.Notification.SetText(notification.Handle, NotificationText.PlaceHolder, PlaceHolderText, null, -1);
108             }
109         }
110     }
111 }