Apply new design of Notification APIs
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.NotificationEventListener / Tizen.Applications.NotificationEventListener / NotificationEventArgs.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.NotificationEventListener
18 {
19     using System;
20     using System.Collections.Generic;
21     using System.ComponentModel;
22
23     public partial class NotificationEventArgs
24     {
25         private const string LogTag = "Tizen.Applications.NotificationEventListener";
26
27         internal IDictionary<string, StyleArgs> Style;
28         internal IDictionary<string, Bundle> Extender;
29         internal Interop.NotificationEventListener.SafeNotificationHandle Handle;
30
31         public NotificationEventArgs()
32         {
33             Style = new Dictionary<string, StyleArgs>();
34             Extender = new Dictionary<string, Bundle>();
35         }
36
37         /// <summary>
38         /// Gets the unique id of Notification.
39         /// </summary>
40         /// <example>
41         /// <code>
42         /// int uniqueNumber = NotificationEventArgs.UniqueNumber;
43         /// </code>
44         /// </example>
45         public int UniqueNumber { get; internal set; }
46
47         /// <summary>
48         /// Gets the appId of Notification.
49         /// </summary>
50         /// <example>
51         /// <code>
52         /// string appId = NotificationEventArgs.AppID;
53         /// </code>
54         /// </example>
55         public string AppID { get; internal set; }
56
57         /// <summary>
58         /// Gets the title of Notification.
59         /// </summary>
60         /// <example>
61         /// <code>
62         /// string title = NotificationEventArgs.Title;
63         /// </code>
64         /// </example>
65         public string Title { get; internal set; }
66
67         /// <summary>
68         /// Gets the content text of Notification.
69         /// </summary>
70         /// <example>
71         /// <code>
72         /// string content = NotificationEventArgs.Content;
73         /// </code>
74         /// </example>
75         public string Content { get; internal set; }
76
77         /// <summary>
78         /// Gets the icon's path of Notification.
79         /// </summary>
80         /// <example>
81         /// <code>
82         /// string icon = NotificationEventArgs.Icon;
83         /// </code>
84         /// </example>
85         public string Icon { get; internal set; }
86
87         /// <summary>
88         /// Gets the sub icon path of Notification.
89         /// </summary>
90         /// <example>
91         /// <code>
92         /// string subIcon = NotificationEventArgs.SubIcon;
93         /// </code>
94         /// </example>
95         public string SubIcon { get; internal set; }
96
97         /// <summary>
98         /// Gets the Timestamp of notification is visible or not.
99         /// </summary>
100         public bool IsTimeStampVisible { get; internal set; }
101
102         /// <summary>
103         /// Gets time of Notification.
104         /// </summary>
105         /// <example>
106         /// <code>
107         /// DateTime timeStamp = NotificationEventArgs.TimeStamp;
108         /// </code>
109         /// </example>
110         public DateTime TimeStamp { get; internal set; }
111
112         /// <summary>
113         /// Gets the count which is displayed at the right side of notification.
114         /// </summary>
115         /// <example>
116         /// <code>
117         /// int count = NotificationEventArgs.Count;
118         /// </code>
119         /// </example>
120         public int Count { get; internal set; }
121
122         /// <summary>
123         /// Gets the Tag of notification.
124         /// </summary>
125         /// <example>
126         /// <code>
127         /// string tag = NotificationEventArgs.Tag;
128         /// </code>
129         /// </example>
130         public string Tag { get; internal set; }
131
132         /// <summary>
133         /// Gets a value to check if it is an ongoing type.
134         /// </summary>
135         /// <example>
136         /// <code>
137         /// bool isongoing = NotificationEventArgs.IsOngoing;
138         /// </code>
139         /// </example>
140         [EditorBrowsable(EditorBrowsableState.Never)]
141         public bool IsOngoing { get; internal set; } = false;
142
143         /// <summary>
144         /// Gets a value that determines whether notification is displayed on the default viewer.
145         /// If you set false and add style, you can see only style notification.
146         /// </summary>
147         /// <example>
148         /// <code>
149         /// bool isDisplay = NotificationEventArgs.IsDisplay;
150         /// </code>
151         /// </example>
152         public bool IsDisplay { get; internal set; } = true;
153
154         /// <summary>
155         /// Gets the event flag.
156         /// </summary>
157         /// <example>
158         /// <code>
159         /// bool eventFlag = NotificationEventArgs.HasEventFlag;
160         /// </code>
161         /// </example>
162         [EditorBrowsable(EditorBrowsableState.Never)]
163         public bool HasEventFlag { get; internal set; } = false;
164
165         /// <summary>
166         /// Gets the AppControl which is invoked when notification is clicked.
167         /// </summary>
168         /// <example>
169         /// <code>
170         /// AppControl action = NotificationEventArgs.Action;
171         /// </code>
172         /// </example>
173         public AppControl Action { get; internal set; }
174
175         /// <summary>
176         /// Gets the object of the progress notification.
177         /// </summary>
178         /// <example>
179         /// <code>
180         /// ProgressCategory category = NotificationEventArgs.Progress.Category;
181         /// double current = NotificationEventArgs.Progress.Current;
182         /// double max = NotificationEventArgs.Progress.Max;
183         /// </code>
184         /// </example>
185         public ProgressArgs Progress { get; internal set; }
186
187         /// <summary>
188         /// Gets the AccessoryArgs which has option of Sound, Vibration, LED.
189         /// </summary>
190         /// <example>
191         /// <code>
192         /// string soundPath = NotificationEventArgs.Accessory.SountPath;
193         /// </code>
194         /// </example>
195         public AccessoryArgs Accessory { get; internal set; }
196
197         /// <summary>
198         /// Gets the key for extender.
199         /// </summary>
200         /// <example>
201         /// <code>
202         /// ICollection<string> extenderkey = NotificationEventArgs.ExtenderKey;
203         /// foreach (string key in extenderkey)
204         /// {
205         /// ...
206         /// }
207         /// </code>
208         /// </example>
209         public ICollection<string> ExtenderKey
210         {
211             get
212             {
213                 return Extender.Keys;
214             }
215         }
216
217         /// <summary>
218         /// Gets the property.
219         /// </summary>
220         /// <example>
221         /// <code>
222         /// int property = NotificationEventArgs.Property;
223         /// </code>
224         /// </example>
225         public NotificationProperty Property { get; internal set; }
226
227         /// <summary>
228         /// Gets the styleArgs of active, lock, indicator, bigpicture.
229         /// </summary>
230         /// <typeparam name="T">Type of notification style to be queried</typeparam>
231         /// <returns>The Notification.Style object associated with the given style</returns>
232         /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
233         /// <example>
234         /// <code>
235         /// NotificationEventArgs.ActiveStyleArgs style = NotificationEventArgs.GetStyle<NotificationEventArgs.ActiveStyleArgs>();
236         /// autoremove = style.IsAutoRemove;
237         /// </code>
238         /// </example>
239         public T GetStyle<T>() where T : StyleArgs, new()
240         {
241             T type = new T();
242             StyleArgs style = null;
243
244             Style.TryGetValue(type.Key, out style);
245
246             if (style == null)
247             {
248                 Log.Error(LogTag, "Invalid Style");
249                 throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "invalid parameter entered");
250             }
251             else
252             {
253                 return style as T;
254             }
255         }
256
257         /// <summary>
258         /// Gets the ExtenderArgs.
259         /// </summary>
260         /// <param name="key">The key that specifies which extender</param>
261         /// <returns>Returns the bundle for key</returns>
262         /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
263         /// <example>
264         /// <code>
265         /// Bundle extender = NotificationEventArgs.GetExtender("key");
266         /// </code>
267         /// </example>
268         public Bundle GetExtender(string key)
269         {
270             Bundle bundle;
271
272             if (string.IsNullOrEmpty(key))
273             {
274                 throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "invalid parameter entered");
275             }
276
277             if (Extender.TryGetValue(key, out bundle) == false)
278             {
279                 throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "invalid parameter entered : " + key);
280             }
281
282             return bundle;
283         }
284     }
285 }