From 948d0eb9c684d817324bcba6154ae2661877714d Mon Sep 17 00:00:00 2001 From: Shivam Varshney/Core S/W Group /SRI-Delhi/Engineer/Samsung Electronics Date: Thu, 30 Nov 2023 14:40:57 +0530 Subject: [PATCH] Updating Theme Individually on Theme Change. Change-Id: I1249cea7f04ed97f0104a16acc867d377739a5b2 Signed-off-by: Shivam Varshney/Core S/W Group /SRI-Delhi/Engineer/Samsung Electronics --- TaskBar/Common/Resources.cs | 37 +++++--- TaskBar/TaskBar.csproj | 9 -- TaskBar/Views/AppItemView.cs | 76 ++++++++++++----- TaskBar/Views/MainView.cs | 130 ++++++++++++++--------------- TaskBar/Views/UninstallConfirmationView.cs | 84 ++++++++++++++----- TaskBar/res/themes/dark.xaml | 51 ----------- TaskBar/res/themes/light.xaml | 51 ----------- packaging/org.tizen.taskbar-1.0.0.tpk | Bin 268018 -> 267152 bytes 8 files changed, 209 insertions(+), 229 deletions(-) delete mode 100644 TaskBar/res/themes/dark.xaml delete mode 100644 TaskBar/res/themes/light.xaml diff --git a/TaskBar/Common/Resources.cs b/TaskBar/Common/Resources.cs index 500547a..acf0d20 100644 --- a/TaskBar/Common/Resources.cs +++ b/TaskBar/Common/Resources.cs @@ -23,15 +23,37 @@ namespace TaskBar.Common public const string LogTag = "TaskBar"; public const string LightPlatformThemeId = "org.tizen.default-light-theme"; public const string DarkPlatformThemeId = "org.tizen.default-dark-theme"; - public static readonly Color LightTaskBarBackground = new Color(1.0f, 1.0f, 1.0f, 0.3f); - public static readonly Color DarkTaskBarBackground = new Color(0.0863f, 0.0745f, 0.098f, 0.3f); - public static readonly Color LightMenuBackground = new Color(0.98f, 0.98f, 0.98f, 0.5f); - public static readonly Color DarkMenuBackground = new Color(0.0863f, 0.0745f, 0.1020f, 0.5f); + private static bool IsLightTheme => ThemeManager.PlatformThemeId == LightPlatformThemeId; + + public static Color TaskbarBackgroundColor => IsLightTheme ? new Color("rgba(255, 254, 254, 0.3)") : new Color("rgba(22, 19, 26, 0.3)"); + public static Color MenuBackgroundColor => IsLightTheme ? new Color("rgba(250, 250, 250, 0.5)") : new Color("rgba(22, 19, 26, 0.5)"); + public static Color PopupBackgroundColor => IsLightTheme ? new Color("#FAFAFA") : new Color("#16131A"); + public static Color TaskbarTextColor => IsLightTheme ? new Color("#090E21") : new Color("#FDFDFD"); + public static Color FillButtonTextColor => IsLightTheme ? new Color("#16131A") : new Color("#FDFDFD"); + public static Color FillButtonColor => IsLightTheme ? new Color("#FF6200") : new Color("#FF8A00"); + 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 Color NormalMenuItemTextColor => IsLightTheme ? new Color("#090E21") : new Color("#FDFDFD"); + public static Color PressedMenuItemTextColor => new Color("#1473E6"); + public static Color UninstallMenuItemTextColor => new Color("#A40404"); + public static Color DisabledMenuItemTextColor => IsLightTheme ? new Color("#CACACA") : new Color("#666666"); + + public static string AddButtonIconURL => GetImagePath() + (IsLightTheme ? "light" : "dark") + "/add.png"; + public static string AppIndicatorURL => GetImagePath() + (IsLightTheme ? "light" : "dark") + "/indicator.png"; public const int TaskbarHeight = 64; public const int MenuItemWidth = 220; public const int MenuItemHeight = 44; - public static readonly Vector4 SingleItemCornerRadius = new Vector4(8, 8, 8, 8); + public const int TextPixelSize = 24; + public const int MenuItemTextPixelSize = 20; + public const int SingleItemCornerRadius = 8; + public const int ButtonBorderlineWidth = 2; + + public static Size2D PopupButtonSize = new Size2D(252, 48); + public static Size2D IndicatorSize = new Size2D(20, 4); + public static Size2D MenuItemSize = new Size2D(220, 44); + public static readonly Vector4 TopItemCornerRadius = new Vector4(8, 8, 0, 0); public static readonly Vector4 BottomItemCornerRadius = new Vector4(0, 0, 8, 8); @@ -50,11 +72,6 @@ namespace TaskBar.Common return GetImagePath() + "dark/"; } - public static string GetThemePath() - { - return Tizen.Applications.Application.Current.DirectoryInfo.Resource + "themes/"; - } - public static string GetCurrentThemePath() { return (ThemeManager.PlatformThemeId == LightPlatformThemeId) ? GetLightImagePath() : GetDarkImagePath(); diff --git a/TaskBar/TaskBar.csproj b/TaskBar/TaskBar.csproj index 12c0045..b025d51 100644 --- a/TaskBar/TaskBar.csproj +++ b/TaskBar/TaskBar.csproj @@ -22,13 +22,4 @@ - - - MSBuild:Compile - - - MSBuild:Compile - - - diff --git a/TaskBar/Views/AppItemView.cs b/TaskBar/Views/AppItemView.cs index 9af2229..25638ed 100644 --- a/TaskBar/Views/AppItemView.cs +++ b/TaskBar/Views/AppItemView.cs @@ -75,6 +75,7 @@ namespace TaskBar.Views Layout = new RelativeLayout(); AddButton(); AddIndicator(); + UpdateTheme(); longPressGestureDetector = new LongPressGestureDetector(); longPressGestureDetector.Attach(this); @@ -90,12 +91,38 @@ namespace TaskBar.Views private void OnAppItemViewThemeChanged(object sender, ThemeChangedEventArgs e) { - if (moreMenu?.Items != null) + UpdateTheme(); + } + + private void UpdateTheme() + { + UpdateMenuTheme(); + if (RunningAppIndicator != null) + { + RunningAppIndicator.BackgroundImage = Resources.AppIndicatorURL; + } + } + + private void UpdateMenuTheme() + { + if (moreMenu?.Items == null) + { + return; + } + var menuItems = moreMenu.Items as List; + foreach (MenuItem item in menuItems) { - var menuItems = moreMenu.Items as List; - foreach (MenuItem item in menuItems) + item.BackgroundColor = Resources.MenuBackgroundColor; + ColorSelector colors = new ColorSelector() + { + Pressed = Resources.PressedMenuItemTextColor, + Disabled = Resources.DisabledMenuItemTextColor, + Normal = Resources.NormalMenuItemTextColor, + }; + item.TextColorSelector = colors; + if (item.Text == "Uninstall app") { - item.BackgroundColor = ThemeManager.PlatformThemeId == Resources.LightPlatformThemeId ? Resources.LightMenuBackground : Resources.DarkMenuBackground; + item.TextColor = Resources.UninstallMenuItemTextColor; } } } @@ -126,6 +153,7 @@ namespace TaskBar.Views { ButtonStyle buttonStyle = new ButtonStyle() { + Size = new Size2D(IconSize, IconSize).SpToPx(), Icon = new ImageViewStyle() { MaximumSize = new Size2D(IconSize, IconSize).SpToPx(), @@ -133,10 +161,7 @@ namespace TaskBar.Views IsEnabled = true, IsSelectable = true, }; - AppIcon = new Button(buttonStyle) - { - Size2D = new Size2D(IconSize, IconSize).SpToPx(), - }; + AppIcon = new Button(buttonStyle); Add(AppIcon); RelativeLayout.SetVerticalAlignment(AppIcon, RelativeLayout.Alignment.Center); } @@ -145,7 +170,7 @@ namespace TaskBar.Views { RunningAppIndicator = new View() { - StyleName = "AppIndicatorStyle", + Size2D = Resources.IndicatorSize.SpToPx(), }; Add(RunningAppIndicator); RunningAppIndicator.Hide(); @@ -184,11 +209,12 @@ namespace TaskBar.Views moreMenuPositionY = DeviceInfo.Instance.DisplayHeight - Resources.TaskbarHeight.SpToPx() - moreMenuHeight; if (moreMenu == null) { - Tizen.Log.Info(Resources.LogTag, "Custom Menu"); - moreMenu = new CustomMenu("MoreMenu") + MenuStyle moreMenuStyle = new MenuStyle() { - CornerRadius = Resources.SingleItemCornerRadius, + BackgroundColor = Color.Transparent, }; + Tizen.Log.Info(Resources.LogTag, "Custom Menu"); + moreMenu = new CustomMenu(moreMenuStyle); } moreMenu.Position2D = new Position2D(moreMenuPositionX, moreMenuPositionY); moreMenu.VisibilityChanged += (object sender, VisibilityChangedEventArgs e) => @@ -211,20 +237,26 @@ namespace TaskBar.Views { foreach (string menuItemName in menuItemNames) { - MenuItem item = new MenuItem("MenuItems") + ButtonStyle buttonStyle = new ButtonStyle() { + Size = Resources.MenuItemSize.SpToPx(), Padding = new Extents(10, 10, 0, 0).SpToPx(), - Text = menuItemName, + Text = new TextLabelStyle() + { + PixelSize = Resources.MenuItemTextPixelSize.SpToPx(), + FontFamily = "BreezeSans", + HorizontalAlignment = HorizontalAlignment.Begin, + VerticalAlignment = VerticalAlignment.Center, + Text = menuItemName, + }, + IsSelectable = false, }; - if (menuItemName == "Uninstall app") - { - item.TextColor = new Color("#A40404"); - } - else if (menuItemName == "Close") + MenuItem item = new MenuItem(buttonStyle); + + if (menuItemName == "Close") { item.IsEnabled = showIndicator; } - item.BackgroundColor = ThemeManager.PlatformThemeId == Resources.LightPlatformThemeId ? Resources.LightMenuBackground : Resources.DarkMenuBackground; item.Clicked += OnItemClicked; menuItemsList.Add(item); Tizen.Log.Info(Resources.LogTag, "more menu Item: " + menuItemName); @@ -237,12 +269,13 @@ namespace TaskBar.Views } else if (menuItemsList.Count == 1) { - menuItemsList[0].CornerRadius = Resources.SingleItemCornerRadius; + menuItemsList[0].CornerRadius = Resources.SingleItemCornerRadius.SpToPx(); } if (moreMenu != null) { moreMenu.Items = menuItemsList; } + UpdateMenuTheme(); } private void OnItemClicked(object sender, ClickedEventArgs e) @@ -285,6 +318,7 @@ namespace TaskBar.Views } if (type == DisposeTypes.Explicit) { + ThemeManager.ThemeChanged -= OnAppItemViewThemeChanged; DisposeMenuItems(); DisposeMoreMenu(); diff --git a/TaskBar/Views/MainView.cs b/TaskBar/Views/MainView.cs index 48d210a..588fc41 100644 --- a/TaskBar/Views/MainView.cs +++ b/TaskBar/Views/MainView.cs @@ -14,14 +14,11 @@ * limitations under the License. */ -using System; using System.Collections.Generic; -using System.IO; using Tizen.NUI; using Tizen.NUI.BaseComponents; using Tizen.NUI.Binding; using Tizen.NUI.Components; -using Tizen.NUI.Xaml; using TaskBar.Common; using TaskBar.Core; using TaskBar.ViewModels; @@ -43,6 +40,8 @@ namespace TaskBar.Views private LongPressGestureDetector addAppsLongPressDetector; private QuickAccessView quickAccessView; + private const int AddButtonSize = 48; + public MainView() : base() { WidthSpecification = DeviceInfo.Instance.DisplayWidth; @@ -56,7 +55,6 @@ namespace TaskBar.Views VerticalAlignment = VerticalAlignment.Center, CellPadding = new Size2D(8, 0).SpToPx(), }; - UpdateTheme(ThemeManager.PlatformThemeId); applicationsViewModel = new ApplicationsViewModel(); applicationsView = new ApplicationsView(); Add(applicationsView); @@ -71,7 +69,7 @@ namespace TaskBar.Views Add(quickAccessView); quickAccessView.BindingContext = quickAccessViewModel; quickAccessView.SetBinding(BaseView.AppListProperty, "ButtonsInfo"); - + UpdateTheme(); ThemeManager.ThemeChanged += OnThemeUpdated; } @@ -87,24 +85,53 @@ namespace TaskBar.Views private void OnThemeUpdated(object sender, ThemeChangedEventArgs e) { - if (e.IsPlatformThemeChanged) + UpdateTheme(); + } + + private void UpdateTheme() + { + BackgroundColor = Resources.TaskbarBackgroundColor; + if (addPinnedAppsButton != null) + { + addPinnedAppsButton.IconURL = Resources.AddButtonIconURL; + } + UpdateMenuTheme(); + } + + private void UpdateMenuTheme() + { + if (addButtonMoreMenu?.Items == null) { - Tizen.Log.Info(Resources.LogTag, "Theme Changed: " + e.ThemeId); - if (addButtonMoreMenu?.Items != null) + return; + } + var menuItems = addButtonMoreMenu.Items as List; + foreach (MenuItem item in menuItems) + { + item.BackgroundColor = Resources.MenuBackgroundColor; + ColorSelector colors = new ColorSelector() { - var menuItems = addButtonMoreMenu.Items as List; - foreach (MenuItem item in menuItems) - { - item.BackgroundColor = ThemeManager.PlatformThemeId == Resources.LightPlatformThemeId ? Resources.LightMenuBackground : Resources.DarkMenuBackground; - } - } - UpdateTheme(e.PlatformThemeId); + Pressed = Resources.PressedMenuItemTextColor, + Disabled = Resources.DisabledMenuItemTextColor, + Normal = Resources.NormalMenuItemTextColor, + }; + item.TextColorSelector = colors; } } private void CreateAddPinnedAppsView() { - addPinnedAppsButton = new Button("AddPinnedAppsButton"); + ButtonStyle buttonStyle = new ButtonStyle() + { + Size = new Size2D(AddButtonSize, AddButtonSize).SpToPx(), + BackgroundColor = Color.Transparent, + Icon = new ImageViewStyle() + { + Size = new Size2D(AddButtonSize, AddButtonSize).SpToPx(), + }, + IsSelectable = false, + IsEnabled = true, + }; + addPinnedAppsButton = new Button(buttonStyle); addPinnedAppsButton.Clicked += (object sender, ClickedEventArgs e) => { TaskBarAppsLauncher.LaunchAppsApplicationPinMode(applicationsViewModel.GetPinnedAppsList()); @@ -112,7 +139,7 @@ namespace TaskBar.Views addPinnedAppsView = new View() { - WidthSpecification = 48.SpToPx(), + WidthSpecification = AddButtonSize.SpToPx(), HeightSpecification = LayoutParamPolicies.MatchParent, BackgroundColor = Color.Transparent, Layout = new RelativeLayout(), @@ -151,12 +178,13 @@ namespace TaskBar.Views if (addButtonMoreMenu == null) { Tizen.Log.Info(Resources.LogTag, "Custom Menu"); - addButtonMoreMenu = new CustomMenu("MoreMenu") + MenuStyle moreMenuStyle = new MenuStyle() { - CornerRadius = Resources.SingleItemCornerRadius, + Position = new Position2D(moreMenuPositionX, moreMenuPositionY), + BackgroundColor = Color.Transparent, }; + addButtonMoreMenu = new CustomMenu(moreMenuStyle); } - addButtonMoreMenu.Position2D = new Position2D(moreMenuPositionX, moreMenuPositionY); addButtonMoreMenu.VisibilityChanged += (object sender, VisibilityChangedEventArgs e) => { // when more menu is dismissed, its visibilty state changes to false, and input region is updated again. @@ -165,62 +193,30 @@ namespace TaskBar.Views DeviceInfo.Instance.SetTaskbarInputRegion(); } }; - MenuItem item = new MenuItem("MenuItems") + ButtonStyle buttonStyle = new ButtonStyle() { + Size = Resources.MenuItemSize.SpToPx(), Padding = new Extents(10, 10, 0, 0).SpToPx(), - CornerRadius = Resources.SingleItemCornerRadius, - Text = "Add Apps", + Text = new TextLabelStyle() + { + PixelSize = Resources.MenuItemTextPixelSize.SpToPx(), + FontFamily = "BreezeSans", + HorizontalAlignment = HorizontalAlignment.Begin, + VerticalAlignment = VerticalAlignment.Center, + Text = "Add Apps", + }, + CornerRadius = Resources.SingleItemCornerRadius.SpToPx(), + IsSelectable = false, }; - item.BackgroundColor = ThemeManager.PlatformThemeId == Resources.LightPlatformThemeId ? Resources.LightMenuBackground : Resources.DarkMenuBackground; + MenuItem item = new MenuItem(buttonStyle); + item.Clicked += (object sender, ClickedEventArgs e) => { TaskBarAppsLauncher.LaunchAppsApplicationPinMode(applicationsViewModel.GetPinnedAppsList()); DisposeMoreMenu(); }; addButtonMoreMenu.Items = new List() { item }; - } - - private void SetTheme(string path) - { - try - { - Theme theme = new Theme(path); - ThemeManager.ApplyTheme(theme); - } - catch (ArgumentNullException e) - { - Tizen.Log.Error(Resources.LogTag, "ArgumentNullException: " + e.ParamName); - } - catch (IOException e) - { - Tizen.Log.Error(Resources.LogTag, "IOException: " + e.Message); - } - catch (XamlParseException e) - { - Tizen.Log.Error(Resources.LogTag, "XamlParseException: " + e.Message); - if (e.XmlInfo != null) - { - Tizen.Log.Error(Resources.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(Resources.LogTag, "Platform theme id is null"); - return; - } - if (platformThemeId.Equals(Resources.LightPlatformThemeId)) - { - BackgroundColor = Resources.LightTaskBarBackground; - SetTheme(Resources.GetThemePath() + "light.xaml"); - } - else if (platformThemeId.Equals(Resources.DarkPlatformThemeId)) - { - BackgroundColor = Resources.DarkTaskBarBackground; - SetTheme(Resources.GetThemePath() + "dark.xaml"); - } + UpdateMenuTheme(); } private void DisposeMoreMenu() diff --git a/TaskBar/Views/UninstallConfirmationView.cs b/TaskBar/Views/UninstallConfirmationView.cs index dd46790..70b1fb1 100644 --- a/TaskBar/Views/UninstallConfirmationView.cs +++ b/TaskBar/Views/UninstallConfirmationView.cs @@ -33,29 +33,44 @@ namespace TaskBar.Views baseView = new View() { BackgroundColor = new Color(0, 0, 0, 0.3f), + AllowOnlyOwnTouch = true, }; Window.Instance.Add(baseView); - Button cancelButton = new Button("CancelButton"); + Button cancelButton = new Button() + { + Size2D = Resources.PopupButtonSize.SpToPx(), + BackgroundColor = Color.Transparent, + BorderlineWidth = Resources.ButtonBorderlineWidth.SpToPx(), + }; + cancelButton.TextLabel.PixelSize = Resources.TextPixelSize.SpToPx(); + cancelButton.TextLabel.Text = "Cancel"; Button deleteButton = new Button() { - Size2D = new Size2D(252, 48).SpToPx(), - Text = "Delete", + Size2D = Resources.PopupButtonSize.SpToPx(), }; - deleteButton.PointSize = 16.SpToPx(); + deleteButton.TextLabel.PixelSize = Resources.TextPixelSize.SpToPx(); + deleteButton.TextLabel.Text = "Delete"; confirmationPopup = new AlertDialog() { - StyleName = "AlertDialogBackground", Title = "Delete App from the Device", Message = "Do you want to delete this app from the device?", Actions = new List