Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Notification / Tizen.Applications.Notifications / NotificationButtonAction.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 to help you set button on Active style of Notification
31         /// </summary>
32         /// <remarks>
33         /// It must include a Text, an Index, an ImagePath, and an Action to be invoked when user select the button.
34         /// </remarks>>
35         public sealed class ButtonAction : MakerBase
36         {
37             /// <summary>
38             /// Gets or sets the index of Button which is appeared at Notification.
39             /// </summary>
40             public ButtonIndex Index { get; set; } = ButtonIndex.None;
41
42             /// <summary>
43             /// Gets or sets the text describing the button
44             /// </summary>
45             public string Text { get; set; }
46
47             /// <summary>
48             /// Gets or sets the image path that represent the button
49             /// </summary>
50             public string ImagePath { get; set; }
51
52             /// <summary>
53             /// Gets or sets the action which is invoked when button is clicked
54             /// </summary>
55             /// <value>
56             /// If you don't set Action, nothing happens when button is clicked.
57             /// </value>
58             /// <example>
59             /// <code>
60             /// ButtonAction button = new ButtonAction
61             /// {
62             ///     Index = ButtonIndex.First,
63             ///     text = "Yes",
64             ///     ImagePath = "image path",
65             ///     Action = new AppControl{ ApplicationId = "org.tizen.app" };
66             /// };
67             /// </code>
68             /// </example>
69             /// <seealso cref="Tizen.Applications.AppControl"></seealso>
70             public AppControl Action { get; set; }
71
72             internal override void Make(Notification notification)
73             {
74                 int enumIndex = (int)NotificationText.FirstButton + (int)Index;
75
76                 Interop.Notification.SetText(notification.Handle, (NotificationText)enumIndex, Text, null, -1);
77                 enumIndex = (int)NotificationImage.FirstButton + (int)Index;
78                 Interop.Notification.SetImage(notification.Handle, (NotificationImage)enumIndex, ImagePath);
79                 if (Action != null && Action.SafeAppControlHandle.IsInvalid == false)
80                 {
81                     Interop.Notification.SetEventHandler(notification.Handle, (int)Index, Action.SafeAppControlHandle);
82                 }
83             }
84         }
85     }
86 }