From 05f8b6089ad0f0e2a4aa3c5dae7f2d4928e0c169 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Wed, 31 Mar 2021 17:35:11 +0900 Subject: [PATCH] [NUI] Add a method to create a toast in Notification and etc. (#2800) * Add a method to create a toast in Notification class. * Fix wrong argument exception usage. * Add mroe description in Post method. Signed-off-by: Jiyun Yang --- src/Tizen.NUI.Components/Controls/Notification.cs | 94 ++++++++++++++++++++- .../Theme/DefaultThemeCommon.cs | 15 ++++ src/Tizen.NUI.Components/res/IoT_Toast_1.png | Bin 0 -> 5177 bytes 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/Tizen.NUI.Components/res/IoT_Toast_1.png diff --git a/src/Tizen.NUI.Components/Controls/Notification.cs b/src/Tizen.NUI.Components/Controls/Notification.cs index 403059e..fd2568e 100755 --- a/src/Tizen.NUI.Components/Controls/Notification.cs +++ b/src/Tizen.NUI.Components/Controls/Notification.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * Copyright(c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,36 @@ namespace Tizen.NUI.Components /// 8 public class Notification : Disposable { + /// + /// Toast will appear at the top of the screen. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly Position ToastTop = ParentOrigin.TopCenter; + + /// + /// Toast will appear at the center of the screen. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly Position ToastCenter = ParentOrigin.Center; + + /// + /// Toast will appear at the bottom of the screen. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly Position ToastBottom = ParentOrigin.BottomCenter; + + /// + /// Show the notification for a short period of time. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly uint ToastShort = 2000; + + /// + /// Show the notification for a long period of time. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly uint ToastLong = ToastShort * 2; + private static HashSet instanceSet; private Window notificationWindow; @@ -45,15 +75,20 @@ namespace Tizen.NUI.Components private NotificationState state = NotificationState.Ready; + static Notification() + { + ThemeManager.AddPackageTheme(DefaultThemeCreator.Instance); + } + /// /// Create a notification with a content View. /// /// The content view instance to display in the notification window. - /// Thrown when a given contentView is invalid. + /// Thrown when a given contentView is null. /// 8 public Notification(View contentView) : base() { - ContentView = contentView ?? throw new ArgumentException("Input contentView should not be null."); + ContentView = contentView ?? throw new ArgumentNullException(nameof(contentView)); } private enum NotificationState @@ -117,9 +152,60 @@ namespace Tizen.NUI.Components } /// + /// Create a simple text notification called toast. + /// + /// The string content. + /// The location at which the toast should appear. It's one of the notification constants: ToastTop, ToastCenter and ToastBottom. + /// The created Notification instance. + /// Thrown when the given text or gravity is null. + /// Application need to set http://tizen.org/privilege/window.priority.set to post a notification. + /// + /// The following example demonstrates how to make a toast at the bottom and show it for a short period time. + /// + /// Notification.MakeToast("Hello World!", Notification.ToastBottom).Post(Notification.ToastShort); + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static Notification MakeToast(string text, Position gravity) + { + var textLabel = new TextLabel(text ?? throw new ArgumentNullException(nameof(text))) + { + Opacity = 0.0f + }; + + if (gravity == null) throw new ArgumentNullException(nameof(gravity)); + + var style = ThemeManager.GetStyle("NotificationToast"); + if (style != null) + { + textLabel.ApplyStyle(style); + } + + textLabel.ParentOrigin = gravity; + textLabel.PivotPoint = gravity; + + if (gravity == ToastCenter) + { + textLabel.PositionY = 0; + } + else if (gravity == ToastBottom) + { + textLabel.PositionY = -textLabel.PositionY; + } + + var postAnimation = new Animation(700); + postAnimation.AnimateTo(textLabel, "Opacity", 1.0f); + + var dismissAnimation = new Animation(500); + dismissAnimation.AnimateTo(textLabel, "Opacity", 0.0f); + + return new Notification(textLabel).SetAnimationOnPost(postAnimation).SetAnimationOnDismiss(dismissAnimation); + } + + /// /// Post a notification window with the content view. /// - /// Dismiss the notification window after given time. The value 0 won't dismiss the notification. + /// Dismiss the notification window after given time in millisecond. The value 0 won't dismiss the notification. /// The current Notification instance. /// http://tizen.org/privilege/window.priority.set /// Thrown when the application does not have proper privilege. diff --git a/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs b/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs index 181be2d..d444f66 100755 --- a/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs +++ b/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs @@ -488,6 +488,21 @@ namespace Tizen.NUI.Components }, }); + theme.AddStyleWithoutClone("NotificationToast", new TextLabelStyle() + { + BackgroundImage = FrameworkInformation.ResourcePath + "IoT_Toast_1.png", + BackgroundImageBorder = new Rectangle(28, 28, 28, 28), + TextColor = new Color("#000C2B"), + PixelSize = 32, + WidthResizePolicy = ResizePolicyType.UseNaturalSize, + HeightResizePolicy = ResizePolicyType.UseNaturalSize, + PositionUsesPivotPoint = true, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Padding = new Extents(40, 40, 24, 24), + PositionY = 120, + }); + return theme; } } diff --git a/src/Tizen.NUI.Components/res/IoT_Toast_1.png b/src/Tizen.NUI.Components/res/IoT_Toast_1.png new file mode 100644 index 0000000000000000000000000000000000000000..d923619df58f5fc9b05caf8b34a0aae6465381b3 GIT binary patch literal 5177 zcmeHLYdBl!+IFVV7E`H~I<(zthHB|l?T&Mu=~Nw-#3|C6HU!0}QzH&_m^xKEBxdT^ zb}*6g2>M7Z_hQ|v;6#i?)+F;*Sgkv-ur!?`+na0ebX*q zvfT$!hKPuW?6bGCauE@cAPetNGE%~8C+Es3;h#kK1$#Fc;V)L^yE`Hx2RQat7H-i9 z_6O`e_aUrwXr7Nd-rC|j#pho_eymU3E1p(U6A*C^Ig}jsw5}rf%&=Kdj{XBfh#%oF zO2X2Tw5BPAsy=bRz&;??|7y^qRAuLOB`arn=m9HvB}u%G`3RfOHb%{?R4<)o;rR=_ zKhKQL#4I+=#P#v#jatKRbX?hyk=HO!5D^u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