/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Licensed under the Apache License, Version 2.0 (the License);
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
namespace Tizen.Applications
{
/// <summary>
- /// Immutable class for getting information of the badge.
+ /// The class containing common properties of the Badge.
/// </summary>
public class Badge
{
- private readonly string _appId;
- private readonly int _count;
- private readonly bool _isDisplay;
+ private int count = 0;
- internal Badge(string appid, int count, bool isDisplay)
+ /// <summary>
+ /// Initializes a new instance of the Badge class.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="appId">Application ID</param>
+ /// <param name="count">Count value</param>
+ /// <param name="visible">True if it should be displayed</param>
+ /// <exception cref="ArgumentException">Thrown when failed because of invalid argument</exception>
+ public Badge(string appId, int count = 1, bool visible = true)
{
- _appId = appid;
- _count = count;
- _isDisplay = isDisplay;
+ if (IsNegativeNumber(count))
+ {
+ throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number");
+ }
+ AppId = appId;
+ this.count = count;
+ Visible = visible;
}
/// <summary>
{
get
{
- return _count;
+ return count;
+ }
+ set
+ {
+ if (IsNegativeNumber(value))
+ {
+ throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number");
+ }
+
+ count = value;
}
}
/// Property for the application ID of the badge.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- public string AppId
- {
- get
- {
- return _appId;
- }
- }
+ public string AppId { get; set; }
/// <summary>
- /// Property for the flag of 'display'.
+ /// Property for display visibility. True if the badge display visible, otherwise false..
/// </summary>
/// <since_tizen> 3 </since_tizen>
- public bool IsDisplay
+ public bool Visible{ get; set; }
+
+ private bool IsNegativeNumber(int number)
{
- get
- {
- return _isDisplay;
- }
+ return number < 0;
}
}
}
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Licensed under the Apache License, Version 2.0 (the License);
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/// Event handler for receiving badge events.
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ /// <feature>http://tizen.org/feature/badge</feature>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
/// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
- /// <privilege>http://tizen.org/privilege/notification</privilege>
+ /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
public static event EventHandler<BadgeEventArgs> Changed
{
add
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="appId">Application ID.</param>
+ /// <returns>The Badge object with inputted application ID</returns>
+ /// <feature>http://tizen.org/feature/badge</feature>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
- /// <privilege>http://tizen.org/privilege/notification</privilege>
+ /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
public static Badge Find(string appId)
{
uint count;
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="appId">Application ID.</param>
+ /// <feature>http://tizen.org/feature/badge</feature>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
/// <exception cref="ArgumentException">Thrown when failed because of a an invalid argument.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
- /// <privilege>http://tizen.org/privilege/notification</privilege>
+ /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
public static void Remove(string appId)
{
BadgeError err = Interop.Badge.Remove(appId);
}
/// <summary>
- /// Adds the badge information.
+ /// Removes the badge information.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- /// <param name="appId">Application ID.</param>
- /// <param name="count">Count value.</param>
- /// <param name="isDisplay">True if it should be displayed.</param>
+ /// <param name="badge">The Badge object.</param>
+ /// <feature>http://tizen.org/feature/badge</feature>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
- /// <privilege>http://tizen.org/privilege/notification</privilege>
- public static void Add(string appId, int count = 1, bool isDisplay = true)
+ /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
+ public static void Remove(Badge badge)
{
- BadgeError err = Interop.Badge.Add(appId);
- if (err != BadgeError.None)
+ if (badge == null)
{
- throw BadgeErrorFactory.GetException(err, "Failed to add badge of " + appId);
+ throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object");
}
- try
- {
- Update(appId, count, isDisplay);
- }
- catch (Exception e)
- {
- Remove(appId);
- throw e;
- }
+ Remove(badge.AppId);
}
/// <summary>
- /// Updates the badge information.
+ /// Adds the badge information.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- /// <param name="appId">Application ID.</param>
- /// <param name="count">Count value.</param>
+ /// <param name="badge">The Badge object.</param>
+ /// <feature>http://tizen.org/feature/badge</feature>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
- /// <privilege>http://tizen.org/privilege/notification</privilege>
- public static void Update(string appId, int count)
+ /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
+ public static void Add(Badge badge)
{
- BadgeError err = Interop.Badge.SetCount(appId, (uint)count);
+ if (badge == null)
+ {
+ throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object");
+ }
+
+ BadgeError err = Interop.Badge.Add(badge.AppId);
if (err != BadgeError.None)
{
- throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + appId);
+ throw BadgeErrorFactory.GetException(err, "Failed to add badge of " + badge.AppId);
+ }
+
+ try
+ {
+ Update(badge);
+ }
+ catch (Exception e)
+ {
+ Remove(badge.AppId);
+ throw e;
}
}
/// Updates the badge information.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- /// <param name="appId">Application ID.</param>
- /// <param name="isDisplay">True if it should be displayed.</param>
+ /// <param name="badge">The Badge object.</param>
+ /// <feature>http://tizen.org/feature/badge</feature>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
/// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
- /// <privilege>http://tizen.org/privilege/notification</privilege>
- public static void Update(string appId, bool isDisplay)
+ /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
+ public static void Update(Badge badge)
{
- BadgeError err = Interop.Badge.SetDisplay(appId, isDisplay ? 1U : 0U);
+ if (badge == null)
+ {
+ throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object");
+ }
+
+ BadgeError err = Interop.Badge.SetCount(badge.AppId, (uint)badge.Count);
if (err != BadgeError.None)
{
- throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + appId);
+ throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + badge.AppId);
}
- }
- /// <summary>
- /// Updates the badge information.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <param name="appId">Application ID.</param>
- /// <param name="count">Count value.</param>
- /// <param name="isDisplay">True if it should be displayed.</param>
- /// <exception cref="ArgumentException">Thrown when failed because of invalid argument.</exception>
- /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
- /// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
- /// <privilege>http://tizen.org/privilege/notification</privilege>
- public static void Update(string appId, int count, bool isDisplay)
- {
- Update(appId, count);
- Update(appId, isDisplay);
+ err = Interop.Badge.SetDisplay(badge.AppId, badge.Visible ? 1U : 0U);
+ if (err != BadgeError.None)
+ {
+ throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + badge.AppId);
+ }
}
/// <summary>
/// Gets all the badge information.
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ /// <returns>List of all Badge instances.</returns>
+ /// <feature>http://tizen.org/feature/badge</feature>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
/// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access.</exception>
/// <exception cref="InvalidOperationException">Thrown in case of failed conditions.</exception>
- /// <privilege>http://tizen.org/privilege/notification</privilege>
+ /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception>
public static IEnumerable<Badge> GetBadges()
{
IList<Badge> list = new List<Badge>();
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Licensed under the Apache License, Version 2.0 (the License);
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
IoError = Tizen.Internals.Errors.ErrorCode.IoError,
+ NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,
DbError = -0x01120000 | 0x01,
AlreadyExists = -0x01120000 | 0x02,
DBusError = -0x01120000 | 0x03,
Log.Error(LogTag, msg);
return new ArgumentException(ret + " error occurred.");
case BadgeError.PermissionDenied:
+ Log.Error(LogTag, msg);
throw new UnauthorizedAccessException("Permission denied (http://tizen.org/privilege/notification)");
+ case BadgeError.NotSupported:
+ Log.Error(LogTag, msg);
+ throw new NotSupportedException("Not Supported (http://tizen.org/feature/badge)");
default:
Log.Error(LogTag, msg);
return new InvalidOperationException(ret + " error occurred.");