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
20 using System.Collections.Generic;
23 /// This class contains common properties and methods of notifications.
26 /// A notification is a message that is displayed on the notification area.
27 /// It is created to notify information to the user through the application.
28 /// This class helps you to provide method and property for creating notification object.
30 public sealed partial class Notification
33 /// Class for generating active style notification.
35 public sealed class ActiveStyle : StyleBase
37 private IDictionary<ButtonIndex, ButtonAction> buttonDictionary;
38 private int hideTimeout = 0;
39 private int deleteTimeout = 0;
42 /// Initializes a new instance of the <see cref="ActiveStyle"/> class.
46 buttonDictionary = new Dictionary<ButtonIndex, ButtonAction>();
50 /// Gets or sets an absolute path for an image file to display on the background of active notification.
52 public string BackgroundImage { get; set; }
55 /// Gets or sets a value indicating whether the active notification is removed automatically. Default value is true.
58 /// IsAutoRemove option lets the active notification to be removed several seconds after it shows.
59 /// When 'IsAutoRemove' is set as false, the active notification will not be removed as long as the user removes
60 /// it or the application, which posted the active notification.
62 public bool IsAutoRemove { get; set; } = true;
65 /// Gets or sets the default button to display highlight on the active notification.
68 /// The default button for display highlight is only reflected on the Tizen TV.
69 /// If you use this property on other profile, this value has no effect.
71 public ButtonIndex DefaultButton { get; set; } = ButtonIndex.None;
74 /// Gets or sets a ReplyAction to this active notification style.
77 /// When you add a ReplyAction to the ActiveStyle, the notification UI will show a ReplyAction with button.
78 /// If you set null parameter, ReplyAction is not displayed.
83 /// ButtonAction button = new ButtonAction
85 /// Index = ButtonIndex.First,
87 /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
90 /// ReplyAction reply = new ReplyAction
92 /// ParentIndex = ButtonIndex.First;
93 /// PlaceHolderText = "Please write your reply."
95 /// Button = new ButtonAction
98 /// ImagePath = "image path"
99 /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
103 /// ActiveStyle active = new ActiveStyle
105 /// AutoRemove = true,
106 /// BackgroundImage = "image path",
107 /// ReplyAction = reply
110 /// active.AddButtonAction(button);
113 public ReplyAction ReplyAction { get; set; }
116 /// Gets or sets Action which is invoked when notification is hidden by user.
119 /// If you set it to null, the already set AppControl will be removed and nothing will happen when notification is hidden by user.
120 /// The property is only reflected on Tizen TV.
121 /// If you use this API on other profile, this action have no effect
123 /// <seealso cref="Tizen.Applications.AppControl"></seealso>
124 public AppControl HiddenByUserAction { get; set; }
127 /// Gets or sets Action which is invoked when there is no any response by user until hide timeout.
130 /// This action occurs when there is no response to the notification until the delete timeout set by SetRemoveTime().
131 /// If you set it to null, the already set AppControl will be removed and nothing will happen when notification is hidden by timeout.
132 /// The property is only reflected on Tizen TV.
133 /// If you use this API on other profile, this action settings have no effect
135 /// <seealso cref="Tizen.Applications.AppControl"></seealso>
136 public AppControl HiddenByTimeoutAction { get; set; }
139 /// Gets or sets Action which is invoked when the notification is hidden by external factor.
142 /// If you set it to null, the already set AppControl will be removed and nothing will happen when notification is hidden by external factor.
143 /// The property is only reflected on Tizen TV.
144 /// If you use this API on other profile, this action settings have no effect
146 /// <seealso cref="Tizen.Applications.AppControl"></seealso>
147 public AppControl HiddenByExternalAction { get; set; }
150 /// Gets the key of ActiveStyle.
152 internal override string Key
161 /// Method to set time to hide or delete notification.
164 /// The time settings for hiding and deleting are only reflected on the Tizen TV.
165 /// If you use this API on other profile, this time settings have no effect.
167 /// <param name="hideTime">The value in seconds when the notification can be hidden from the notification viewer after the notification is posted.</param>
168 /// <param name="deleteTime">The value in seconds when the notification can be deleted from the notification list in setting application after notification is posted.</param>
169 /// <exception cref="ArgumentException">Thrown when argument is invalid.</exception>
170 public void SetRemoveTime(int hideTime, int deleteTime)
172 if (hideTime < 0 || deleteTime < 0)
174 throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument");
177 hideTimeout = hideTime;
178 deleteTimeout = deleteTime;
182 /// Method to get time set to hide or delete notification.
184 /// <param name="hideTime">The value in seconds when the notification can be hidden from the notification viewer after notification is posted.</param>
185 /// <param name="deleteTime">The value in seconds when the notification can be deleted from the notification list in setting application after notification is posted.</param>
186 public void GetRemoveTime(out int hideTime, out int deleteTime)
188 hideTime = hideTimeout;
189 deleteTime = deleteTimeout;
193 /// Method to add a button to the active notification style.
194 /// Buttons are displayed on the notification.
197 /// If you add button that has same index, the button is replaced to latest adding button.
198 /// If you don't set an index on ButtonAction, the index is set sequentially from zero.
200 /// <param name="button">A ButtonAction for appear to the notification.</param>
201 /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
205 /// ButtonAction button = new ButtonAction
209 /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
212 /// ActiveStyle active = new ActiveStyle
214 /// IsAutoRemove = true,
215 /// BackgroundImage = "image path",
218 /// active.AddButtonAction(button);
222 public void AddButtonAction(ButtonAction button)
226 throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid ButtonAction object");
229 if (button.Index == ButtonIndex.None)
231 button.Index = (ButtonIndex)buttonDictionary.Count;
232 buttonDictionary.Add(button.Index, button);
234 else if (button.Index >= ButtonIndex.First)
236 if (buttonDictionary.ContainsKey(button.Index))
238 buttonDictionary.Remove(button.Index);
241 buttonDictionary.Add(button.Index, button);
246 /// Removes the ButtonAction you already added.
248 /// <param name="index">The index to remove a button.</param>
249 /// <returns>true if the element is successfully found and removed; otherwise, false.</returns>
250 public bool RemoveButtonAction(ButtonIndex index)
252 bool ret = buttonDictionary.Remove(index);
256 Log.Debug(Notification.LogTag, "Invalid key, there is no button matched input index");
260 Log.Debug(Notification.LogTag, "The button was removed.");
267 /// Gets the ButtonAction of the active notification.
269 /// <param name="index">The index to get a button you already added.</param>
270 /// <returns>The ButtonAction object, which you already added.</returns>
271 /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
272 public ButtonAction GetButtonAction(ButtonIndex index)
274 ButtonAction button = null;
276 if (buttonDictionary.ContainsKey(index) == true)
278 buttonDictionary.TryGetValue(index, out button);
282 throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value is not existed.");
288 internal ICollection<ButtonAction> GetButtonAction()
290 return buttonDictionary.Values;
293 internal override void Make(Notification notification)
295 ActiveBinder.BindObject(notification);