/// <summary> /// Removes the badge information. /// </summary> /// <since_tizen> 4 </since_tizen> /// <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> /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception> public static void Remove(Badge badge) { if (badge == null) { throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object"); } Remove(badge.AppId); }
/// <summary> /// Removes the badge information. /// </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> /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception> public static void Remove(string appId) { BadgeError err = Interop.Badge.Remove(appId); if (err != BadgeError.None) { throw BadgeErrorFactory.GetException(err, "Failed to Remove badge of " + appId); } }
/// <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) { if (IsNegativeNumber(count)) { throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number"); } AppId = appId; this.count = count; Visible = visible; }
/// <summary> /// Gets the badge information from the application ID. /// </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> /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception> public static Badge Find(string appId) { uint count; uint display; BadgeError err = Interop.Badge.GetCount(appId, out count); if (err != BadgeError.None) { throw BadgeErrorFactory.GetException(err, "Failed to find badge count of " + appId); } err = Interop.Badge.GetDisplay(appId, out display); if (err != BadgeError.None) { throw BadgeErrorFactory.GetException(err, "Failed to find badge display of " + appId); } return(new Badge(appId, (int)count, display == 0 ? false : true)); }
/// <summary> /// Updates the badge information. /// </summary> /// <since_tizen> 4 </since_tizen> /// <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> /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception> public static void Update(Badge badge) { 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 " + badge.AppId); } 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> /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception> public static IEnumerable <Badge> GetBadges() { IList <Badge> list = new List <Badge>(); BadgeError err = Interop.Badge.Foreach((appId, count, userData) => { uint display = 0; BadgeError errGetDisplay = Interop.Badge.GetDisplay(appId, out display); if (errGetDisplay != BadgeError.None) { throw BadgeErrorFactory.GetException(errGetDisplay, "Failed to get badges "); } list.Add(new Badge(appId, (int)count, display == 0 ? false : true)); }, IntPtr.Zero); if (err != BadgeError.None) { throw BadgeErrorFactory.GetException(err, "Failed to get badges"); } return(list); }
/// <summary> /// Adds the badge information. /// </summary> /// <since_tizen> 4 </since_tizen> /// <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> /// <exception cref="NotSupportedException">Thrown when Badge is not supported.</exception> public static void Add(Badge badge) { 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 add badge of " + badge.AppId); } try { Update(badge); } catch (Exception e) { Remove(badge.AppId); throw e; } }