Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Notification / Tizen.Applications.Notifications / NotificationProgress.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.Notifications
18 {
19     /// <summary>
20     /// Class containing common properties and methods of Notifications
21     /// </summary>
22     /// <remarks>
23     /// A notification is a message that is displayed on the notification area.
24     /// It is created to notify information to the user through the application.
25     /// This class helps you to provide method and property for creating notification object.
26     /// </remarks>
27     public sealed partial class Notification
28     {
29         /// <summary>
30         ///  Class for displaying progress notification
31         ///  You must initialize progress category, current, max value when you create object.
32         /// </summary>
33         public sealed class ProgressType : MakerBase
34         {
35             private double progressCurrent;
36             private double progressMax;
37
38             /// <summary>
39             /// Initializes a new instance of the <see cref="ProgressType"/> class.
40             /// You must initialize category, current, max value of progress.
41             /// </summary>
42             /// <param name="category">The category of progress that appeared on Notification</param>
43             /// <param name="current">The current value of the progress</param>
44             /// <param name="max">The max value of the progress</param>
45             /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
46             public ProgressType(ProgressCategory category, double current, double max)
47             {
48                 if (IsNegativeNumber(current))
49                 {
50                     throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The current must be a positive integer.");
51                 }
52
53                 if (IsNegativeNumber(max))
54                 {
55                     throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The max must be a positive integer.");
56                 }
57
58                 Category = category;
59                 ProgressCurrent = current;
60                 ProgressMax = max;
61             }
62
63             /// <summary>
64             /// Gets or sets category of ProgressType.
65             /// </summary>
66             /// <seealso cref="Tizen.Applications.Notifications.ProgressCategory"></seealso>
67             public ProgressCategory Category { get; set; }
68
69             /// <summary>
70             /// Gets or sets current value of ProgressType
71             /// </summary>
72             /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
73             public double ProgressCurrent
74             {
75                 get
76                 {
77                     return progressCurrent;
78                 }
79
80                 set
81                 {
82                     if (IsNegativeNumber(value))
83                     {
84                         throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value must be a positive integer.");
85                     }
86
87                     progressCurrent = value;
88                 }
89             }
90
91             /// <summary>
92             /// Gets or sets max value of ProgressType
93             /// </summary>
94             /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
95             public double ProgressMax
96             {
97                 get
98                 {
99                     return progressMax;
100                 }
101
102                 set
103                 {
104                     if (IsNegativeNumber(value))
105                     {
106                         throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value must be a positive integer.");
107                     }
108
109                     progressMax = value;
110                 }
111             }
112
113             internal override void Make(Notification notification)
114             {
115                 ProgressBinder.BindObject(notification);
116             }
117
118             private bool IsNegativeNumber(double number)
119             {
120                 return number < 0;
121             }
122         }
123     }
124 }