From 0866dcd7dd9c219ac528268ae1bbe9c825ff17f8 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Wed, 1 Jul 2020 11:56:00 +0900 Subject: [PATCH] [NUI] Make Notification APIs public and fix CA warnings. (#1747) Signed-off-by: Jiyun Yang --- src/Tizen.NUI.Components/Controls/Notification.cs | 92 ++++++++++++++--------- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Notification.cs b/src/Tizen.NUI.Components/Controls/Notification.cs index 46e50af..b60284d 100644 --- a/src/Tizen.NUI.Components/Controls/Notification.cs +++ b/src/Tizen.NUI.Components/Controls/Notification.cs @@ -24,9 +24,8 @@ namespace Tizen.NUI.Components /// /// Notification helps to raise a notification window with a content View. /// - /// http://tizen.org/privilege/window.priority.set - [EditorBrowsable(EditorBrowsableState.Never)] - public class Notification + /// 8 + public class Notification : Disposable { private static HashSet instanceSet; @@ -49,16 +48,12 @@ namespace Tizen.NUI.Components /// /// Create a notification with a content View. /// + /// The content view instance to display in the notification window. /// Thrown when a given contentView is invalid. - [EditorBrowsable(EditorBrowsableState.Never)] - public Notification(View contentView) + /// 8 + public Notification(View contentView) : base() { - if (contentView == null) - { - throw (new ArgumentException("Input contentView should not be null.")); - } - - ContentView = contentView; + ContentView = contentView ?? throw new ArgumentException("Input contentView should not be null."); } private enum NotificationState @@ -71,7 +66,7 @@ namespace Tizen.NUI.Components /// /// The content view received in a constructor. /// - [EditorBrowsable(EditorBrowsableState.Never)] + /// 8 public View ContentView { get; private set; } private Window NotificationWindow @@ -80,8 +75,10 @@ namespace Tizen.NUI.Components { if (notificationWindow == null) { - notificationWindow = new Window(null, true); - notificationWindow.Type = WindowType.Notification; + notificationWindow = new Window(null, true) + { + Type = WindowType.Notification, + }; notificationWindow.Show(); } @@ -108,6 +105,11 @@ namespace Tizen.NUI.Components { timer.Stop(); timer.Tick -= OnTimeOut; + + if (value == null) + { + timer.Dispose(); + } } timer = value; @@ -119,7 +121,9 @@ namespace Tizen.NUI.Components /// /// Dismiss the notification window after given time. The value 0 won't dismiss the notification. /// The current Notification instance. - [EditorBrowsable(EditorBrowsableState.Never)] + /// http://tizen.org/privilege/window.priority.set + /// Thrown when the application does not have proper privilege. + /// 8 public void Post(uint duration = 0) { if (state != NotificationState.Ready) @@ -127,9 +131,10 @@ namespace Tizen.NUI.Components return; } - var window = NotificationWindow; - - ApplyLevel(level); + if (!ApplyLevel(level)) + { + throw new UnauthorizedAccessException("Cannot post a Notification: Permission Denied"); + } ApplyPositionSize(positionSize); @@ -151,17 +156,20 @@ namespace Tizen.NUI.Components /// /// Sets a priority level for the specified notification window. + /// The default level is NotificationLevel.Base. /// /// The notification window level. /// The current Notification instance. - [EditorBrowsable(EditorBrowsableState.Never)] + /// http://tizen.org/privilege/window.priority.set + /// Thrown when the application does not have proper privilege. + /// 8 public Notification SetLevel(NotificationLevel level) { this.level = level; - if (state == NotificationState.Post) + if (state == NotificationState.Post && !ApplyLevel(level)) { - ApplyLevel(level); + throw new UnauthorizedAccessException("Cannot set notification level: Permission Denied"); } return this; @@ -173,15 +181,10 @@ namespace Tizen.NUI.Components /// The position and size information in rectangle. /// The current Notification instance. /// Thrown when a given positionSize is invalid. - [EditorBrowsable(EditorBrowsableState.Never)] + /// 8 public Notification SetPositionSize(Rectangle positionSize) { - if (positionSize == null) - { - throw (new ArgumentException("Input positionSize should not be null.")); - } - - this.positionSize = positionSize; + this.positionSize = positionSize ?? throw (new ArgumentException("Input positionSize should not be null.")); if (state == NotificationState.Post || state == NotificationState.Dismiss) { @@ -219,7 +222,7 @@ namespace Tizen.NUI.Components /// The Notification will play the given animation right after the notification window pops up. /// /// The animation to play. - [EditorBrowsable(EditorBrowsableState.Never)] + /// 8 public Notification SetAnimationOnPost(Animation animation) { this.onPostAnimation = animation; @@ -232,7 +235,7 @@ namespace Tizen.NUI.Components /// On dismiss, the given animation is played, and after the playback is completed the notification window is undisplayed. /// /// The animation to play. - [EditorBrowsable(EditorBrowsableState.Never)] + /// 8 public Notification SetAnimationOnDismiss(Animation animation) { this.onDismissAnimation = animation; @@ -243,7 +246,7 @@ namespace Tizen.NUI.Components /// /// Dismiss the notification window. /// - [EditorBrowsable(EditorBrowsableState.Never)] + /// 8 public void Dismiss() { if (state != NotificationState.Post) @@ -272,7 +275,7 @@ namespace Tizen.NUI.Components /// /// Dismiss the notification window directly without waiting the onDismissAnimation finished. /// - [EditorBrowsable(EditorBrowsableState.Never)] + /// 8 public void ForceQuit() { if (state != NotificationState.Post && state != NotificationState.Dismiss) @@ -283,6 +286,27 @@ namespace Tizen.NUI.Components ClearAll(); } + /// + /// 8 + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + ClearAll(); + + positionSize?.Dispose(); + onPostAnimation?.Dispose(); + onDismissAnimation?.Dispose(); + } + + base.Dispose(type); + } + private static void RegisterInstance(Notification instance) { if (instanceSet == null) @@ -317,9 +341,9 @@ namespace Tizen.NUI.Components notificationWindow = null; } - private void ApplyLevel(NotificationLevel level) + private bool ApplyLevel(NotificationLevel level) { - NotificationWindow.SetNotificationLevel(level); + return NotificationWindow.SetNotificationLevel(level); } private void ApplyPositionSize(Rectangle positionSize) -- 2.7.4