/* * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace Tizen.Applications.Notifications { using System; using System.Collections.Generic; /// /// This class contains common properties and methods of notifications. /// /// /// A notification is a message that is displayed on the notification area. /// It is created to notify information to the user through the application. /// This class helps you to provide method and property for creating notification object. /// /// 3 public sealed partial class Notification { /// /// Class for generating active style notification. /// /// 3 public sealed class ActiveStyle : StyleBase { private IDictionary buttonDictionary; private int hideTimeout = 0; private int deleteTimeout = 0; /// /// Initializes a new instance of the class. /// /// 3 public ActiveStyle() { buttonDictionary = new Dictionary(); } /// /// Gets or sets an absolute path for an image file to display on the background of active notification. /// /// 3 public string BackgroundImage { get; set; } /// /// Gets or sets a value indicating whether the active notification is removed automatically. Default value is true. /// /// /// IsAutoRemove option lets the active notification to be removed several seconds after it shows. /// When 'IsAutoRemove' is set as false, the active notification will not be removed as long as the user removes /// it or the application, which posted the active notification. /// > /// 3 public bool IsAutoRemove { get; set; } = true; /// /// Gets or sets the default button to display highlight on the active notification. /// /// /// The default button for display highlight is only reflected on the Tizen TV. /// If you use this property on other profile, this value has no effect. /// /// 3 public ButtonIndex DefaultButton { get; set; } = ButtonIndex.None; /// /// Gets or sets a ReplyAction to this active notification style. /// /// /// When you add a ReplyAction to the ActiveStyle, the notification UI will show a ReplyAction with button. /// If you set null parameter, ReplyAction is not displayed. /// /// /// /// /// ButtonAction button = new ButtonAction /// { /// Index = ButtonIndex.First, /// Text = "Yes" /// Action = new AppControl{ ApplicationId = "org.tizen.app" }; /// }; /// /// ReplyAction reply = new ReplyAction /// { /// ParentIndex = ButtonIndex.First; /// PlaceHolderText = "Please write your reply." /// ReplyMax = 160, /// Button = new ButtonAction /// { /// Text = "Yes", /// ImagePath = "image path" /// Action = new AppControl{ ApplicationId = "org.tizen.app" }; /// }; /// }; /// /// ActiveStyle active = new ActiveStyle /// { /// AutoRemove = true, /// BackgroundImage = "image path", /// ReplyAction = reply /// }; /// /// active.AddButtonAction(button); /// /// /// 3 public ReplyAction ReplyAction { get; set; } /// /// Gets or sets Action which is invoked when notification is hidden by user. /// /// /// If you set it to null, the already set AppControl will be removed and nothing will happen when notification is hidden by user. /// The property is only reflected on Tizen TV. /// If you use this API on other profile, this action have no effect /// /// /// 4 public AppControl HiddenByUserAction { get; set; } /// /// Gets or sets Action which is invoked when there is no any response by user until hide timeout. /// /// /// This action occurs when there is no response to the notification until the delete timeout set by SetRemoveTime(). /// If you set it to null, the already set AppControl will be removed and nothing will happen when notification is hidden by timeout. /// The property is only reflected on Tizen TV. /// If you use this API on other profile, this action settings have no effect /// /// /// 4 public AppControl HiddenByTimeoutAction { get; set; } /// /// Gets or sets Action which is invoked when the notification is hidden by external factor. /// /// /// If you set it to null, the already set AppControl will be removed and nothing will happen when notification is hidden by external factor. /// The property is only reflected on Tizen TV. /// If you use this API on other profile, this action settings have no effect /// /// /// 4 public AppControl HiddenByExternalAction { get; set; } /// /// Gets the key of ActiveStyle. /// internal override string Key { get { return "Active"; } } /// /// Method to set time to hide or delete notification. /// /// /// The time settings for hiding and deleting are only reflected on the Tizen TV. /// If you use this API on other profile, this time settings have no effect. /// /// The value in seconds when the notification can be hidden from the notification viewer after the notification is posted. /// The value in seconds when the notification can be deleted from the notification list in setting application after notification is posted. /// Thrown when argument is invalid. /// 3 public void SetRemoveTime(int hideTime, int deleteTime) { if (hideTime < 0 || deleteTime < 0) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument"); } hideTimeout = hideTime; deleteTimeout = deleteTime; } /// /// Method to get time set to hide or delete notification. /// /// The value in seconds when the notification can be hidden from the notification viewer after notification is posted. /// The value in seconds when the notification can be deleted from the notification list in setting application after notification is posted. /// 3 public void GetRemoveTime(out int hideTime, out int deleteTime) { hideTime = hideTimeout; deleteTime = deleteTimeout; } /// /// Method to add a button to the active notification style. /// Buttons are displayed on the notification. /// /// /// If you add button that has same index, the button is replaced to latest adding button. /// If you don't set an index on ButtonAction, the index is set sequentially from zero. /// /// A ButtonAction for appear to the notification. /// Thrown when an argument is invalid. /// /// /// /// ButtonAction button = new ButtonAction /// { /// Index = 0, /// Text = "Yes" /// Action = new AppControl{ ApplicationId = "org.tizen.app" }; /// }; /// /// ActiveStyle active = new ActiveStyle /// { /// IsAutoRemove = true, /// BackgroundImage = "image path", /// }; /// /// active.AddButtonAction(button); /// /// /// /// 3 public void AddButtonAction(ButtonAction button) { if (button == null) { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid ButtonAction object"); } if (button.Index == ButtonIndex.None) { button.Index = (ButtonIndex)buttonDictionary.Count; buttonDictionary.Add(button.Index, button); } else if (button.Index >= ButtonIndex.First) { if (buttonDictionary.ContainsKey(button.Index)) { buttonDictionary.Remove(button.Index); } buttonDictionary.Add(button.Index, button); } } /// /// Removes the ButtonAction you already added. /// /// The index to remove a button. /// true if the element is successfully found and removed; otherwise, false. /// 3 public bool RemoveButtonAction(ButtonIndex index) { bool ret = buttonDictionary.Remove(index); if (ret == false) { Log.Debug(Notification.LogTag, "Invalid key, there is no button matched input index"); } else { Log.Debug(Notification.LogTag, "The button was removed."); } return ret; } /// /// Gets the ButtonAction of the active notification. /// /// The index to get a button you already added. /// The ButtonAction object, which you already added. /// Thrown when an argument is invalid. /// 3 public ButtonAction GetButtonAction(ButtonIndex index) { ButtonAction button = null; if (buttonDictionary.ContainsKey(index) == true) { buttonDictionary.TryGetValue(index, out button); } else { throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value is not existed."); } return button; } internal ICollection GetButtonAction() { return buttonDictionary.Values; } internal override void Make(Notification notification) { ActiveBinder.BindObject(notification); } } } }