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