Release 4.0.0-preview1-00224
[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         public sealed class ProgressType : MakerBase
36         {
37             private double progressCurrent;
38             private double progressMax;
39
40             /// <summary>
41             /// Initializes a new instance of the <see cref="ProgressType"/> class.
42             /// You must initialize category, current, and max value of the progress.
43             /// </summary>
44             /// <param name="category">The category of progress that appeared on notification.</param>
45             /// <param name="current">The current value of the progress.</param>
46             /// <param name="max">The max value of the progress.</param>
47             /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
48             public ProgressType(ProgressCategory category, double current, double max)
49             {
50                 if (IsNegativeNumber(current))
51                 {
52                     throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The current must be a positive integer.");
53                 }
54
55                 if (IsNegativeNumber(max))
56                 {
57                     throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The max must be a positive integer.");
58                 }
59
60                 Category = category;
61                 ProgressCurrent = current;
62                 ProgressMax = max;
63             }
64
65             /// <summary>
66             /// Gets or sets category of ProgressType.
67             /// </summary>
68             /// <seealso cref="Tizen.Applications.Notifications.ProgressCategory"></seealso>
69             public ProgressCategory Category { get; set; }
70
71             /// <summary>
72             /// Gets or sets current value of ProgressType.
73             /// </summary>
74             /// <exception cref="ArgumentException">Thrown when argument is invalid.</exception>
75             public double ProgressCurrent
76             {
77                 get
78                 {
79                     return progressCurrent;
80                 }
81
82                 set
83                 {
84                     if (IsNegativeNumber(value))
85                     {
86                         throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value must be a positive integer.");
87                     }
88
89                     progressCurrent = value;
90                 }
91             }
92
93             /// <summary>
94             /// Gets or sets max value of ProgressType.
95             /// </summary>
96             /// <exception cref="ArgumentException">Thrown when argument is invalid.</exception>
97             public double ProgressMax
98             {
99                 get
100                 {
101                     return progressMax;
102                 }
103
104                 set
105                 {
106                     if (IsNegativeNumber(value))
107                     {
108                         throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value must be a positive integer.");
109                     }
110
111                     progressMax = value;
112                 }
113             }
114
115             internal override void Make(Notification notification)
116             {
117                 ProgressBinder.BindObject(notification);
118             }
119
120             private bool IsNegativeNumber(double number)
121             {
122                 return number < 0;
123             }
124         }
125     }
126 }