Release 4.0.0-preview1-00224
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Badge / Tizen.Applications / Badge.cs
1 /*
2  * Copyright (c) 2016 - 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 using System;
18
19 namespace Tizen.Applications
20 {
21     /// <summary>
22     /// The class containing common properties of the Badge.
23     /// </summary>
24     public class Badge
25     {
26         private int count = 0;
27
28         /// <summary>
29         /// Initializes a new instance of the Badge class.
30         /// </summary>
31         /// <since_tizen> 3 </since_tizen>
32         /// <param name="appId">Application ID</param>
33         /// <param name="count">Count value</param>
34         /// <param name="visible">True if it should be displayed</param>
35         /// <exception cref="ArgumentException">Thrown when failed because of invalid argument</exception>
36         public Badge(string appId, int count = 1, bool visible = true)
37         {
38             if (IsNegativeNumber(count))
39             {
40                 throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number");
41             }
42             AppId = appId;
43             this.count = count;
44             Visible = visible;
45         }
46
47         /// <summary>
48         /// Property for the count value of the badge.
49         /// </summary>
50         /// <since_tizen> 3 </since_tizen>
51         /// <exception cref="ArgumentException">Thrown when set negative number</exception>
52         public int Count
53         {
54             get
55             {
56                 return count;
57             }
58             set
59             {
60                 if (IsNegativeNumber(value))
61                 {
62                     throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number");
63                 }
64
65                 count = value;
66             }
67         }
68
69         /// <summary>
70         /// Property for the application ID of the badge.
71         /// </summary>
72         /// <since_tizen> 3 </since_tizen>
73         public string AppId { get; set; }
74
75         /// <summary>
76         /// Property for display visibility. True if the badge display visible, otherwise false..
77         /// </summary>
78         /// <since_tizen> 3 </since_tizen>
79         public bool Visible{ get; set; }
80
81         private bool IsNegativeNumber(int number)
82         {
83             return number < 0;
84         }
85     }
86 }