2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 namespace Tizen.Applications.Notifications
19 using System.Collections.Generic;
22 /// Class containing common properties and methods of Notifications
25 /// A notification is a message that is displayed on the notification area.
26 /// It is created to notify information to the user through the application.
27 /// This class helps you to provide method and property for creating notification object.
29 public sealed partial class Notification
32 /// Class for generating Active style notification
34 public sealed class ActiveStyle : StyleBase
36 private IDictionary<ButtonIndex, ButtonAction> buttonDictionary;
37 private int hideTimeout = 0;
38 private int deleteTimeout = 0;
41 /// Initializes a new instance of the <see cref="ActiveStyle"/> class.
45 buttonDictionary = new Dictionary<ButtonIndex, ButtonAction>();
49 /// Gets or sets an absolute path for an image file to display on the background of active notification
51 public string BackgroundImage { get; set; }
54 /// Gets or sets a value indicating whether the active notification is removed automatically. Default value is true.
57 /// IsAutoRemove option lets the active notification be removed several seconds after it shows.
58 /// When 'IsAutoRemove' is set as false, the active notification will not be removed as long as the user removes
59 /// the active notification or the app which posted the active notification removes the active notification.
61 public bool IsAutoRemove { get; set; } = true;
64 /// Gets or sets the default button to display highlight on the active notification
67 /// The default button for display highlight is only reflected on Tizen TV.
68 /// If you use this Property on other profile, this value have no effect
70 public ButtonIndex DefaultButton { get; set; } = ButtonIndex.None;
73 /// Gets or sets a ReplyAction to this active notification style.
76 /// When you add a ReplyAction to the ActiveStyle, the notification UI will show a ReplyAction with button.
77 /// If you set null parameter, ReplyAction is disappeared.
82 /// ButtonAction button = new ButtonAction
84 /// Index = ButtonIndex.First,
86 /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
89 /// ReplyAction reply = new ReplyAction
91 /// ParentIndex = ButtonIndex.First;
92 /// PlaceHolderText = "Please write your reply."
94 /// Button = new ButtonAction
97 /// ImagePath = "image path"
98 /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
102 /// ActiveStyle active = new ActiveStyle
104 /// AutoRemove = true,
105 /// BackgroundImage = "image path",
106 /// ReplyAction = reply
109 /// active.AddButtonAction(button);
112 public ReplyAction ReplyAction { get; set; }
115 /// Gets the key of ActiveStyle
117 internal override string Key
126 /// Method to set times to hide or delete notification.
129 /// The time settings for hiding and deleting are only reflected on Tizen TV.
130 /// If you use this API on other profile, this time settings have no effect
132 /// <param name="hideTime">The value in second when the notification can be hidden from the notification viewer after notification is posted</param>
133 /// <param name="deleteTime">The value in second when the notification can be deleted from the notification list in setting application after notification is posted</param>
134 /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
135 public void SetRemoveTime(int hideTime, int deleteTime)
137 if (hideTime < 0 || deleteTime < 0)
139 throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument");
142 hideTimeout = hideTime;
143 deleteTimeout = deleteTime;
147 /// Method to get times to hide or delete notification.
149 /// <param name="hideTime">The value in second when the notification can be hidden from the notification viewer after notification is posted</param>
150 /// <param name="deleteTime">The value in second when the notification can be deleted from the notification list in setting application after notification is posted</param>
151 public void GetRemoveTime(out int hideTime, out int deleteTime)
153 hideTime = hideTimeout;
154 deleteTime = deleteTimeout;
158 /// Method to add a button to the active notification style.
159 /// Buttons are displayed on the notification.
162 /// If you add button that has same index, the button is replaced to latest adding button.
163 /// If you don't set an index on ButtonAction, the index is set sequentially from zero.
165 /// <param name="button">An ButtonAction for appear to the notification</param>
166 /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
170 /// ButtonAction button = new ButtonAction
174 /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
177 /// ActiveStyle active = new ActiveStyle
179 /// IsAutoRemove = true,
180 /// BackgroundImage = "image path",
183 /// active.AddButtonAction(button);
187 public void AddButtonAction(ButtonAction button)
191 throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid ButtonAction object");
194 if (button.Index == ButtonIndex.None)
196 button.Index = (ButtonIndex)buttonDictionary.Count;
197 buttonDictionary.Add(button.Index, button);
199 else if (button.Index >= ButtonIndex.First)
201 if (buttonDictionary.ContainsKey(button.Index))
203 buttonDictionary.Remove(button.Index);
206 buttonDictionary.Add(button.Index, button);
211 /// Remove the ButtonAction you already add.
213 /// <param name="index">The index to remove a button</param>
214 /// <returns>true if the element is successfully found and removed; otherwise, false</returns>
215 public bool RemoveButtonAction(ButtonIndex index)
217 bool ret = buttonDictionary.Remove(index);
221 Log.Debug(Notification.LogTag, "Invalid key, there is no button matched input index");
225 Log.Debug(Notification.LogTag, "The button was removed.");
232 /// Gets the ButtonAction of the active notification.
234 /// <param name="index">The index to get a button you already add</param>
235 /// <returns>The ButtonAction object which is you already add</returns>
236 /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
237 public ButtonAction GetButtonAction(ButtonIndex index)
239 ButtonAction button = null;
241 if (buttonDictionary.ContainsKey(index) == true)
243 buttonDictionary.TryGetValue(index, out button);
247 throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value is not existed.");
253 internal ICollection<ButtonAction> GetButtonAction()
255 return buttonDictionary.Values;
258 internal override void Make(Notification notification)
260 ActiveBinder.BindObject(notification);