From: Shivam Varshney/Core S/W Group /SRI-Delhi/Engineer/Samsung Electronics Date: Fri, 1 Mar 2024 13:44:03 +0000 (+0530) Subject: Fixing Theme Change Issues for all components. X-Git-Tag: accepted/tizen/unified/20240412.141505^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c205c012713f96984a4c376f70b79d1d669b681;p=profile%2Fiot%2Fapps%2Fdotnet%2Fnotifications.git Fixing Theme Change Issues for all components. Change-Id: I06792f6ea4e466d86a4b677e9d2a93c38b967468 Signed-off-by: Shivam Varshney/Core S/W Group /SRI-Delhi/Engineer/Samsung Electronics --- diff --git a/Notifications/Common/AppConstants.cs b/Notifications/Common/AppConstants.cs index 501c7f1..4131ae5 100644 --- a/Notifications/Common/AppConstants.cs +++ b/Notifications/Common/AppConstants.cs @@ -4,23 +4,36 @@ namespace Notifications.Common { static class AppConstants { + + private static bool IsLightTheme => ThemeManager.PlatformThemeId == LightPlatformThemeId; + public const string LogTag = "Notifications"; public const string LightPlatformThemeId = "org.tizen.default-light-theme"; public const string DarkPlatformThemeId = "org.tizen.default-dark-theme"; - public static Color LightBorderColor = new Color(0.9804f, 0.9804f, 0.9804f, 0.35f); - public static Color DarkBorderColor = new Color(0.0863f, 0.0745f, 0.0980f, 0.50f); + public static Color BaseViewBackgroundColor => IsLightTheme ? new Color("#FAFAFA") : new Color("#16131A"); + public static Color BorderBackgroundColor => IsLightTheme ? new Color("rgba(250, 250, 250, 0.35)") : new Color("rgba(22, 19, 25, 0.5)"); + public static Color NotificationsTextColor => IsLightTheme ? new Color("#090E21") : new Color("#FDFDFD"); + public static Color DisabledButtonTextColor => IsLightTheme ? new Color("#CACACA") : new Color("#666666"); + public static Color NormalButtonTextColor => IsLightTheme ? new Color("#FF6200") : new Color("#FF8A00"); + public static Color PressedButtonTextColor => IsLightTheme ? new Color("#FFA166") : new Color("#CC6E00"); + + public static string BackButtonIconUrl => Resources.GetImagePath() + (IsLightTheme ? "light" : "dark") + "/back.png"; + public static string ClearBinIconUrl => Resources.GetImagePath() + (IsLightTheme ? "light" : "dark") + "/clear.png"; public static Size2D DefaultWindowSize = new Size2D(960, 540); + public static Size2D BackButtonSize = new Size2D(48, 48); + public static Size2D ClearBinSize = new Size2D(32, 32); + public static Size2D ClearAllButtonSize = new Size2D(150, 48); public static Position2D DefaultWindowPosition = new Position2D(480, 170); public const int BorderHeight = 52; public const int HeaderHeight = 64; public const int NotificationItemHeight = 80; - - public static Vector4 BorderCornerRadius = new Vector4(24, 24, 24, 24); - public static Vector4 BaseViewCornerRadius = new Vector4(24, 24, 24, 24); + public const int BorderCornerRadius = 24; + public const int BaseViewCornerRadius = 24; + public const int TextPixelSize = 24; public static Extents BaseViewPadding = new Extents(0, 0, 20, 20); public static Extents HeaderPadding = new Extents(16, 16, 8, 8); diff --git a/Notifications/Common/MultiResourceManager.cs b/Notifications/Common/MultiResourceManager.cs deleted file mode 100644 index d14121b..0000000 --- a/Notifications/Common/MultiResourceManager.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Globalization; -using System.Reflection; -using System.Resources; - -namespace Notifications.Common -{ - public class MultiResourceManager : ResourceManager - { - public MultiResourceManager(string baseName, Assembly assembly) - : base(baseName, assembly) - { - } - - public override string GetString(string name) - { - return base.GetString(name) - ?? TextResources.Resources.ResourceManager.GetString(name); - } - - public override string GetString(string name, CultureInfo culture) - { - return base.GetString(name, culture) - ?? TextResources.Resources.ResourceManager.GetString(name, culture); - } - } -} diff --git a/Notifications/CustomBorder.cs b/Notifications/CustomBorder.cs index ce04e58..2661908 100644 --- a/Notifications/CustomBorder.cs +++ b/Notifications/CustomBorder.cs @@ -44,7 +44,7 @@ namespace Notifications { if (borderView != null) { - borderView.BackgroundColor = ThemeManager.PlatformThemeId == AppConstants.LightPlatformThemeId ? AppConstants.LightBorderColor : AppConstants.DarkBorderColor; + borderView.BackgroundColor = AppConstants.BorderBackgroundColor; } } } @@ -56,14 +56,14 @@ namespace Notifications this.borderView = borderView; ThemeManager.ThemeChanged += OnThemeChanged; - borderView.BackgroundColor = ThemeManager.PlatformThemeId == AppConstants.LightPlatformThemeId ? AppConstants.LightBorderColor : AppConstants.DarkBorderColor; + borderView.BackgroundColor = AppConstants.BorderBackgroundColor; } public override void OnCreated(View borderView) { base.OnCreated(borderView); } - + public override bool CreateBottomBorderView(View bottomView) { if (bottomView == null) @@ -175,7 +175,7 @@ namespace Notifications } base.OnResized(width, height); - borderView.BackgroundColor = ThemeManager.PlatformThemeId == AppConstants.LightPlatformThemeId ? AppConstants.LightBorderColor : AppConstants.DarkBorderColor; + borderView.BackgroundColor = AppConstants.BorderBackgroundColor; UpdateIcons(); } diff --git a/Notifications/Notifications.cs b/Notifications/Notifications.cs index 20fd029..9bb2686 100644 --- a/Notifications/Notifications.cs +++ b/Notifications/Notifications.cs @@ -17,12 +17,9 @@ using System; using System.Collections.Generic; using System.Globalization; -using Tizen.Applications; using Tizen.NUI; using Notifications.Common; -using Tizen.NUI.BaseComponents; - namespace Notifications { class Program : NUIApplication @@ -112,23 +109,17 @@ namespace Notifications } catch (Exception e) { - Tizen.Log.Debug(AppConstants.LogTag, "Setting Language failed" + e.Message); + Tizen.Log.Error(AppConstants.LogTag, "Setting Language failed" + e.Message); } } - MultilingualResourceManager = new MultiResourceManager("Notifications.TextResources.Resources", typeof(Resources).Assembly); + MultilingualResourceManager = TextResources.Resources.ResourceManager; Tizen.System.SystemSettings.LocaleLanguageChanged += (s, e) => SetLanguage(); SetLanguage(); } - protected override void OnAppControlReceived(AppControlReceivedEventArgs e) - { - base.OnAppControlReceived(e); - Tizen.Log.Info(AppConstants.LogTag, "AppControl Received"); - } protected override void OnTerminate() { - Tizen.Log.Info(AppConstants.LogTag, "On App Terminate"); viewManager.Dispose(); base.OnTerminate(); } diff --git a/Notifications/Notifications.csproj b/Notifications/Notifications.csproj index e9d8331..e0102f0 100644 --- a/Notifications/Notifications.csproj +++ b/Notifications/Notifications.csproj @@ -37,14 +37,5 @@ - - - MSBuild:Compile - - - MSBuild:Compile - - - diff --git a/Notifications/ViewManager.cs b/Notifications/ViewManager.cs index f346678..e370b03 100644 --- a/Notifications/ViewManager.cs +++ b/Notifications/ViewManager.cs @@ -15,10 +15,8 @@ */ using System; -using System.IO; using Tizen.Applications.NotificationEventListener; using Tizen.NUI; -using Tizen.NUI.Xaml; using Notifications.Common; using Notifications.ViewModels; using Notifications.Views; @@ -34,10 +32,11 @@ namespace Notifications { notificationsViewModel = new NotificationsViewModel(); notificationsViewModel.NotificationSelected += OnNotificationSelected; - UpdateTheme(ThemeManager.PlatformThemeId); + baseView = new BaseView(); baseView.BindingContext = notificationsViewModel; baseView.BackKeyPressed += OnBackKeyPressed; + Window.Instance.Add(baseView); Window.Instance.Resized += OnWindowResized; @@ -64,6 +63,7 @@ namespace Notifications baseView.BindingContext = null; baseView.BackKeyPressed -= OnBackKeyPressed; baseView.Dispose(); + baseView = null; } private void OnThemeChanged(object sender, ThemeChangedEventArgs e) @@ -71,7 +71,7 @@ namespace Notifications if (e.IsPlatformThemeChanged) { Tizen.Log.Info(AppConstants.LogTag, "Theme Changed: " + e.ThemeId); - UpdateTheme(e.PlatformThemeId); + baseView.UpdateTheme(); } } @@ -97,46 +97,5 @@ namespace Notifications baseView.BindingContext = notificationsViewModel; baseView.UpdateContent(); } - - private void SetTheme(string path) - { - try - { - Theme theme = new Theme(path); - ThemeManager.ApplyTheme(theme); - } - catch (ArgumentNullException e) - { - Tizen.Log.Error(AppConstants.LogTag, "ArgumentNullException: " + e.ParamName); - } - catch (IOException e) - { - Tizen.Log.Error(AppConstants.LogTag, "IOException: " + e.Message); - } - catch (XamlParseException e) - { - Tizen.Log.Error(AppConstants.LogTag, "XamlParseException: " + e.Message); - if (e.XmlInfo != null) - { - Tizen.Log.Error(AppConstants.LogTag, "XamlParseException, LineNo." + e.XmlInfo.LineNumber + " Pos: " + e.XmlInfo.LinePosition + " HasInfo: " + e.XmlInfo.HasLineInfo().ToString()); - } - } - } - private void UpdateTheme(string platformThemeId) - { - if (platformThemeId == null) - { - Tizen.Log.Error(AppConstants.LogTag, "Platform theme id is null"); - return; - } - if (platformThemeId.Equals(AppConstants.LightPlatformThemeId)) - { - SetTheme(Resources.GetThemePath() + "light.xaml"); - } - else if (platformThemeId.Equals(AppConstants.DarkPlatformThemeId)) - { - SetTheme(Resources.GetThemePath() + "dark.xaml"); - } - } } } diff --git a/Notifications/Views/BaseView.cs b/Notifications/Views/BaseView.cs index 3dcc331..6cd0d18 100644 --- a/Notifications/Views/BaseView.cs +++ b/Notifications/Views/BaseView.cs @@ -48,7 +48,7 @@ namespace Notifications.Views public BaseView() : base() { - StyleName = "BaseView"; + ThemeChangeSensitive = true; Size2D = Window.Instance.Size; CornerRadius = AppConstants.BaseViewCornerRadius; Layout = new LinearLayout() @@ -76,6 +76,7 @@ namespace Notifications.Views { AddNoNotificationsText(); } + UpdateTheme(); } public void AddDetailContentView() @@ -84,12 +85,24 @@ namespace Notifications.Views RemoveContent(); if (detailContentView == null) { - detailContentView = new Button() + ButtonStyle buttonStyle = new ButtonStyle() + { + BackgroundColor = Color.Transparent, + Text = new TextLabelStyle() + { + BackgroundColor = Color.Transparent, + MultiLine = true, + FontFamily = "BreezeSans", + HorizontalAlignment = HorizontalAlignment.Begin, + }, + Margin = AppConstants.DetailContentMargin.SpToPx(), + IsEnabled = true, + IsSelectable = false, + }; + detailContentView = new Button(buttonStyle) { - StyleName = "DetailContentView", WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = LayoutParamPolicies.WrapContent, - Margin = AppConstants.DetailContentMargin.SpToPx(), }; detailContentView.SetBinding(Button.TextProperty, "DetailContent"); detailContentView.SetBinding(Control.CommandProperty, "AppLaunchCommand"); @@ -103,6 +116,30 @@ namespace Notifications.Views UpdateNotificationsViewItemTemplate(); } + public void UpdateTheme() + { + BackgroundColor = AppConstants.BaseViewBackgroundColor; + if (detailContentView != null) + { + detailContentView.TextColor = AppConstants.NotificationsTextColor; + } + backButton.Icon.ResourceUrl = AppConstants.BackButtonIconUrl; + titleText.TextColor = AppConstants.NotificationsTextColor; + if (noNotificationsText != null) + { + noNotificationsText.TextColor = AppConstants.NotificationsTextColor; + } + if (clearAllButton != null) + { + clearAllButton.TextColorSelector = new ColorSelector() + { + Normal = AppConstants.NormalButtonTextColor, + Pressed = AppConstants.PressedButtonTextColor, + Disabled = AppConstants.DisabledButtonTextColor, + }; + } + } + public bool BackKeyEventEmitted() { if (detailContentView != null && detailContentView.GetParent() == this) @@ -117,6 +154,7 @@ namespace Notifications.Views { topView = new View() { + ThemeChangeSensitive = true, WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = AppConstants.HeaderHeight.SpToPx(), Layout = new RelativeLayout() @@ -130,7 +168,19 @@ namespace Notifications.Views private void AddTopViewElements() { - backButton = new Button("BackButton"); + ButtonStyle buttonStyle = new ButtonStyle() + { + BackgroundColor = Color.Transparent, + Size = AppConstants.BackButtonSize.SpToPx(), + Icon = new ImageViewStyle() + { + BackgroundColor = Color.Transparent, + Size = AppConstants.BackButtonSize.SpToPx(), + }, + IsEnabled = true, + IsSelectable = false, + }; + backButton = new Button(buttonStyle); RelativeLayout.SetVerticalAlignment(backButton, RelativeLayout.Alignment.Center); RelativeLayout.SetHorizontalAlignment(backButton, RelativeLayout.Alignment.Start); backButton.SetBinding(Control.CommandProperty, "BackCommand"); @@ -138,10 +188,12 @@ namespace Notifications.Views titleText = new TextLabel() { - StyleName = "TitleText", + ThemeChangeSensitive = true, TranslatableText = "IDS_ST_HEADER_NOTIFICATIONS", HeightSpecification = LayoutParamPolicies.MatchParent, VerticalAlignment = VerticalAlignment.Center, + PixelSize = AppConstants.TextPixelSize.SpToPx(), + FontFamily = "BreezeSans", }; RelativeLayout.SetLeftTarget(titleText, backButton); RelativeLayout.SetLeftRelativeOffset(titleText, 1.0f); @@ -184,18 +236,9 @@ namespace Notifications.Views notificationsView.SizeWidth = Window.Instance.Size.Width; notificationsView.ItemTemplate = new DataTemplate(() => { - DefaultLinearItem item = new DefaultLinearItem(); - item.WidthSpecification = LayoutParamPolicies.MatchParent; - item.HeightSpecification = AppConstants.NotificationItemHeight.SpToPx(); - item.Label.StyleName = "TitleText"; + ItemLayout item = new ItemLayout(); item.Label.SetBinding(TextLabel.TextProperty, "Title"); - item.Label.HorizontalAlignment = HorizontalAlignment.Begin; - item.Label.VerticalAlignment = VerticalAlignment.Bottom; - item.SubLabel.StyleName = "TitleText"; item.SubLabel.SetBinding(TextLabel.TextProperty, "SubTitle"); - item.SubLabel.HorizontalAlignment = HorizontalAlignment.Begin; - item.SubLabel.VerticalAlignment = VerticalAlignment.Top; - item.Extra = new Button("ClearButton"); item.Extra.SetBinding(Control.CommandProperty, "ClearNotificationCommand"); return item; }); @@ -205,8 +248,21 @@ namespace Notifications.Views { if (clearAllButton == null) { - clearAllButton = new Button("ClearAllButton"); - clearAllButton.TextLabel.TranslatableText = "IDS_ST_BUTTON_CLEAR_ALL"; + ButtonStyle buttonStyle = new ButtonStyle() + { + Size = AppConstants.ClearAllButtonSize.SpToPx(), + BackgroundColor = Color.Transparent, + Text = new TextLabelStyle() + { + BackgroundColor = Color.Transparent, + TranslatableText = "IDS_ST_BUTTON_CLEAR_ALL", + FontFamily = "BreezeSans", + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Center, + }, + }; + clearAllButton = new Button(buttonStyle); + RelativeLayout.SetVerticalAlignment(clearAllButton, RelativeLayout.Alignment.Center); RelativeLayout.SetHorizontalAlignment(clearAllButton, RelativeLayout.Alignment.End); clearAllButton.SetBinding(Control.CommandProperty, "ClearAllNotificationsCommand"); @@ -220,19 +276,18 @@ namespace Notifications.Views { noNotificationsText = new TextLabel() { - StyleName = "TitleText", TranslatableText = "IDS_ST_BODY_NO_NOTIFICATIONS_MSG", WidthSpecification = LayoutParamPolicies.MatchParent, HeightSpecification = LayoutParamPolicies.MatchParent, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, + FontFamily = "BreezeSans", + PixelSize = AppConstants.TextPixelSize.SpToPx(), }; } Add(noNotificationsText); } - - private bool isContentAvailable; public bool IsContentAvailable { diff --git a/Notifications/Views/ItemLayout.cs b/Notifications/Views/ItemLayout.cs new file mode 100644 index 0000000..392e04b --- /dev/null +++ b/Notifications/Views/ItemLayout.cs @@ -0,0 +1,69 @@ +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; +using Notifications.Common; + +namespace Notifications.Views +{ + class ItemLayout : DefaultLinearItem + { + public ItemLayout() : base() + { + WidthSpecification = LayoutParamPolicies.MatchParent; + HeightSpecification = AppConstants.NotificationItemHeight.SpToPx(); + + Label.HorizontalAlignment = HorizontalAlignment.Begin; + Label.VerticalAlignment = VerticalAlignment.Bottom; + Label.FontFamily = "BreezeSans"; + Label.PixelSize = AppConstants.TextPixelSize.SpToPx(); + + SubLabel.HorizontalAlignment = HorizontalAlignment.Begin; + SubLabel.VerticalAlignment = VerticalAlignment.Top; + SubLabel.FontFamily = "BreezeSans"; + SubLabel.PixelSize = AppConstants.TextPixelSize.SpToPx(); + + ButtonStyle buttonStyle = new ButtonStyle() + { + Size = AppConstants.ClearBinSize.SpToPx(), + BackgroundColor = Color.Transparent, + Icon = new ImageViewStyle() + { + BackgroundColor = Color.Transparent, + Size = AppConstants.ClearBinSize.SpToPx(), + }, + IsEnabled = true, + IsSelectable = false, + }; + Extra = new Button(buttonStyle); + + UpdateTheme(); + ThemeManager.ThemeChanged += OnItemThemeChanged; + } + + private void OnItemThemeChanged(object sender, ThemeChangedEventArgs e) + { + UpdateTheme(); + } + + private void UpdateTheme() + { + Label.TextColor = AppConstants.NotificationsTextColor; + SubLabel.TextColor = AppConstants.NotificationsTextColor; + ((Button)Extra).IconURL = AppConstants.ClearBinIconUrl; + } + + protected override void Dispose(DisposeTypes type) + { + if (Disposed) + { + return; + } + if (type == DisposeTypes.Explicit) + { + ThemeManager.ThemeChanged -= OnItemThemeChanged; + } + Tizen.Log.Info(AppConstants.LogTag, "Dispose ItemLayout"); + base.Dispose(type); + } + } +} diff --git a/Notifications/res/themes/dark.xaml b/Notifications/res/themes/dark.xaml deleted file mode 100644 index c36f331..0000000 --- a/Notifications/res/themes/dark.xaml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Notifications/res/themes/light.xaml b/Notifications/res/themes/light.xaml deleted file mode 100644 index 672c5b0..0000000 --- a/Notifications/res/themes/light.xaml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packaging/org.tizen.notifications-1.0.0.tpk b/packaging/org.tizen.notifications-1.0.0.tpk index 78ce3f8..9bfe92a 100644 Binary files a/packaging/org.tizen.notifications-1.0.0.tpk and b/packaging/org.tizen.notifications-1.0.0.tpk differ