Release 4.0.0-preview1-00051
[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     /// <summary>
24     /// This class provides the methods and properties to get information about the posted or updated notification.
25     /// </summary>
26     public partial class NotificationEventArgs : EventArgs
27     {
28         private const string LogTag = "Tizen.Applications.NotificationEventListener";
29
30         internal IDictionary<string, StyleArgs> Style;
31         internal IDictionary<string, Bundle> Extender;
32         internal Interop.NotificationEventListener.NotificationSafeHandle Handle;
33
34         /// <summary>
35         /// Initializes a new instance of the <see cref="NotificationEventArgs"/> class.
36         /// </summary>
37         public NotificationEventArgs()
38         {
39             Style = new Dictionary<string, StyleArgs>();
40             Extender = new Dictionary<string, Bundle>();
41         }
42
43         /// <summary>
44         /// Gets the unique id of Notification.
45         /// </summary>
46         public int UniqueNumber { get; internal set; }
47
48         /// <summary>
49         /// Gets the appId of Notification.
50         /// </summary>
51         public string AppID { get; internal set; }
52
53         /// <summary>
54         /// Gets the title of Notification.
55         /// </summary>
56         public string Title { get; internal set; }
57
58         /// <summary>
59         /// Gets the content text of Notification.
60         /// </summary>
61         public string Content { get; internal set; }
62
63         /// <summary>
64         /// Gets the icon's path of Notification.
65         /// </summary>
66         public string Icon { get; internal set; }
67
68         /// <summary>
69         /// Gets the sub icon path of Notification.
70         /// </summary>
71         public string SubIcon { get; internal set; }
72
73         /// <summary>
74         /// Gets the Timestamp of notification is visible or not.
75         /// </summary>
76         public bool IsTimeStampVisible { get; internal set; }
77
78         /// <summary>
79         /// Gets TimeStamp of Notification.
80         /// </summary>
81         /// <remarks>
82         /// If IsTimeStampVisible property is set false, this TimeStamp property is meanless.
83         /// </remarks>
84         public DateTime TimeStamp { get; internal set; }
85
86         /// <summary>
87         /// Gets the count which is displayed at the right side of notification.
88         /// </summary>
89         public int Count { get; internal set; }
90
91         /// <summary>
92         /// Gets the Tag of notification.
93         /// </summary>
94         public string Tag { get; internal set; }
95
96         [EditorBrowsable(EditorBrowsableState.Never)]
97         public bool IsOngoing { get; internal set; } = false;
98
99         /// <summary>
100         /// Gets a value that determines whether notification is displayed on the default viewer.
101         /// If IsDisplay property set false and add style, you can see only style notification.
102         /// </summary>
103         public bool IsDisplay { get; internal set; } = true;
104
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public bool HasEventFlag { get; internal set; } = false;
107
108         /// <summary>
109         /// Gets the AppControl which is invoked when notification is clicked.
110         /// </summary>
111         public AppControl Action { get; internal set; }
112
113         /// <summary>
114         /// Gets the object of the progress notification.
115         /// </summary>
116         public ProgressArgs Progress { get; internal set; }
117
118         /// <summary>
119         /// Gets the AccessoryArgs which has option of Sound, Vibration, LED.
120         /// </summary>
121         public AccessoryArgs Accessory { get; internal set; }
122
123         /// <summary>
124         /// Gets the key for extender.
125         /// </summary>
126         public ICollection<string> ExtenderKey
127         {
128             get
129             {
130                 return Extender.Keys;
131             }
132         }
133
134         /// <summary>
135         /// Gets the property.
136         /// </summary>
137         public NotificationProperty Property { get; internal set; }
138
139         /// <summary>
140         /// Gets the styleArgs of active, lock, indicator, bigpicture.
141         /// </summary>
142         /// <typeparam name="T">Type of notification style to be queried</typeparam>
143         /// <returns>The NotificationEventListener.StyleArgs object associated with the given style</returns>
144         /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
145         public T GetStyle<T>() where T : StyleArgs, new()
146         {
147             T type = new T();
148             StyleArgs style = null;
149
150             Style.TryGetValue(type.Key, out style);
151
152             if (style == null)
153             {
154                 Log.Error(LogTag, "Invalid Style");
155                 throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "invalid parameter entered");
156             }
157             else
158             {
159                 return style as T;
160             }
161         }
162
163         /// <summary>
164         /// Gets the ExtenderArgs.
165         /// </summary>
166         /// <param name="key">The key that specifies which extender</param>
167         /// <returns>Returns the bundle for key</returns>
168         public Bundle GetExtender(string key)
169         {
170             Bundle bundle;
171
172             if (string.IsNullOrEmpty(key))
173             {
174                 throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "invalid parameter entered");
175             }
176
177             if (Extender.TryGetValue(key, out bundle) == false)
178             {
179                 throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "invalid parameter entered : " + key);
180             }
181
182             return bundle;
183         }
184     }
185 }