From b2f1329584031b81fadc79f8f0e8e992590c4c76 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Tue, 25 May 2021 22:39:08 +0900 Subject: [PATCH] [NUI] Update theme system * Add platform theme: the theme from tizen-theme-manager using xaml. * Separate base theme from the user theme: the base theme is not used when update view according to theme change. * Add new NUIApplication constructor with theme option. * Compact theme data in View. * Remove unused dark themes. * Remove unused xaml theme files. --- .../Controls/Button.Internal.cs | 4 +- src/Tizen.NUI.Components/Controls/Button.cs | 3 +- src/Tizen.NUI.Components/Controls/Control.cs | 9 +- src/Tizen.NUI.Components/Controls/Notification.cs | 2 +- src/Tizen.NUI.Components/Style/TabButtonStyle.cs | 6 +- src/Tizen.NUI.Components/Theme/DefaultTheme.cs | 209 +------ .../Theme/DefaultThemeCommon.cs | 181 +++--- src/Tizen.NUI.Components/Theme/ThemeDark.cs | 611 --------------------- src/Tizen.NUI.Components/Utils/StyleManager.cs | 57 +- src/Tizen.NUI.Components/res/IoT_Toast_1.png | Bin 5177 -> 0 bytes ...izen.NUI.Components_Tizen.NUI.Theme.Common.xaml | 172 ------ ...en.NUI.Components_Tizen.NUI.Theme.Wearable.xaml | 60 -- .../Tizen.NUI.Wearable_Tizen.NUI.Theme.Common.xaml | 28 - .../src/internal/Theme/DefaultTheme.cs | 2 - .../Theme/Tizen.NUI_Tizen.NUI.Theme.Common.xaml | 3 - .../Theme/Tizen.NUI_Tizen.NUI.Theme.Wearable.xaml | 6 - .../src/public/Application/NUIApplication.cs | 74 ++- .../src/public/BaseComponents/Style/ViewStyle.cs | 9 + src/Tizen.NUI/src/public/BaseComponents/View.cs | 21 +- .../public/BaseComponents/ViewBindableProperty.cs | 23 +- .../src/public/BaseComponents/ViewInternal.cs | 103 +++- src/Tizen.NUI/src/public/Theme/DefaultTheme.cs | 2 - .../src/public/Theme/DefaultThemeCommon.cs | 6 +- .../src/public/Theme/DictionaryExternalTheme.cs | 49 -- .../src/public/Theme/ExternalThemeKeyList.cs | 288 ---------- .../src/public/Theme/ExternalThemeManager.cs | 218 +++----- src/Tizen.NUI/src/public/Theme/IExternalTheme.cs | 29 - src/Tizen.NUI/src/public/Theme/IThemeCreator.cs | 3 - src/Tizen.NUI/src/public/Theme/Theme.cs | 31 +- .../src/public/Theme/ThemeChangedEventArgs.cs | 19 +- src/Tizen.NUI/src/public/Theme/ThemeDark.cs | 82 --- src/Tizen.NUI/src/public/Theme/ThemeManager.cs | 415 ++++++++++---- .../src/public/Theme/TizenExternalTheme.cs | 67 --- .../MarkupExtensions/ThemeResourcePathExtension.cs | 51 ++ 34 files changed, 810 insertions(+), 2033 deletions(-) delete mode 100755 src/Tizen.NUI.Components/Theme/ThemeDark.cs delete mode 100644 src/Tizen.NUI.Components/res/IoT_Toast_1.png delete mode 100755 src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Common.xaml delete mode 100755 src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Wearable.xaml delete mode 100644 src/Tizen.NUI.Wearable/res/Theme/Tizen.NUI.Wearable_Tizen.NUI.Theme.Common.xaml delete mode 100644 src/Tizen.NUI/res/Theme/Tizen.NUI_Tizen.NUI.Theme.Common.xaml delete mode 100644 src/Tizen.NUI/res/Theme/Tizen.NUI_Tizen.NUI.Theme.Wearable.xaml delete mode 100644 src/Tizen.NUI/src/public/Theme/DictionaryExternalTheme.cs delete mode 100755 src/Tizen.NUI/src/public/Theme/ExternalThemeKeyList.cs delete mode 100644 src/Tizen.NUI/src/public/Theme/IExternalTheme.cs delete mode 100644 src/Tizen.NUI/src/public/Theme/ThemeDark.cs delete mode 100755 src/Tizen.NUI/src/public/Theme/TizenExternalTheme.cs create mode 100755 src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ThemeResourcePathExtension.cs diff --git a/src/Tizen.NUI.Components/Controls/Button.Internal.cs b/src/Tizen.NUI.Components/Controls/Button.Internal.cs index 77388ca..178f572 100644 --- a/src/Tizen.NUI.Components/Controls/Button.Internal.cs +++ b/src/Tizen.NUI.Components/Controls/Button.Internal.cs @@ -67,7 +67,7 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] protected virtual TextLabel CreateText() { - return new TextLabel + return new TextLabel(new TextLabelStyle()) { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, @@ -82,7 +82,7 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] protected virtual ImageView CreateIcon() { - return new ImageView + return new ImageView() { AccessibilityHighlightable = false }; diff --git a/src/Tizen.NUI.Components/Controls/Button.cs b/src/Tizen.NUI.Components/Controls/Button.cs index 4b56556..aee49a8 100755 --- a/src/Tizen.NUI.Components/Controls/Button.cs +++ b/src/Tizen.NUI.Components/Controls/Button.cs @@ -340,7 +340,7 @@ namespace Tizen.NUI.Components } /// - /// Return currently applied style. + /// The last applied style object copy. /// /// /// Modifying contents in style may cause unexpected behaviour. @@ -799,6 +799,7 @@ namespace Tizen.NUI.Components if (buttonStyle.Text != null) { + buttonText.ThemeChangeSensitive = false; buttonText.ApplyStyle(buttonStyle.Text); } diff --git a/src/Tizen.NUI.Components/Controls/Control.cs b/src/Tizen.NUI.Components/Controls/Control.cs index 70a29e2..9e2da96 100755 --- a/src/Tizen.NUI.Components/Controls/Control.cs +++ b/src/Tizen.NUI.Components/Controls/Control.cs @@ -87,14 +87,11 @@ namespace Tizen.NUI.Components /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] - public Control(string styleName) : this(new ControlStyle() /* Apply empty style */) + public Control(string styleName) : base(ThemeManager.GetInitialStyleWithoutClone(styleName) ?? throw new InvalidOperationException($"There is no style {styleName}")) { - if (ThemeManager.GetStyle(styleName) == null) - { - throw new InvalidOperationException($"There is no style {styleName}"); - } + this.styleName = styleName; - StyleName = styleName; + SetThemeApplied(); } /// diff --git a/src/Tizen.NUI.Components/Controls/Notification.cs b/src/Tizen.NUI.Components/Controls/Notification.cs index 04c88ff..0c3e515 100755 --- a/src/Tizen.NUI.Components/Controls/Notification.cs +++ b/src/Tizen.NUI.Components/Controls/Notification.cs @@ -189,7 +189,7 @@ namespace Tizen.NUI.Components if (gravity == null) throw new ArgumentNullException(nameof(gravity)); - var style = ThemeManager.GetStyle("NotificationToast"); + var style = ThemeManager.GetInitialStyleWithoutClone("NotificationToast"); if (style != null) { textLabel.ApplyStyle(style); diff --git a/src/Tizen.NUI.Components/Style/TabButtonStyle.cs b/src/Tizen.NUI.Components/Style/TabButtonStyle.cs index 8745cc1..8ca5748 100755 --- a/src/Tizen.NUI.Components/Style/TabButtonStyle.cs +++ b/src/Tizen.NUI.Components/Style/TabButtonStyle.cs @@ -49,12 +49,14 @@ namespace Tizen.NUI.Components /// /// Gets or Sets the Line Style at the top of TabButton. /// - internal ViewStyle TopLine { get; set; } = new ViewStyle(); + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewStyle TopLine { get; set; } = new ViewStyle(); /// /// Gets or Sets the Line Style at the bottom of TabButton. /// - internal ViewStyle BottomLine { get; set; } = new ViewStyle(); + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewStyle BottomLine { get; set; } = new ViewStyle(); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Tizen.NUI.Components/Theme/DefaultTheme.cs b/src/Tizen.NUI.Components/Theme/DefaultTheme.cs index cdfd732..d97433a 100755 --- a/src/Tizen.NUI.Components/Theme/DefaultTheme.cs +++ b/src/Tizen.NUI.Components/Theme/DefaultTheme.cs @@ -15,221 +15,28 @@ * */ -using System.Collections.Generic; -using Tizen.NUI.BaseComponents; +#if !PROFILE_TV +#define ExternalThemeEnabled +#endif namespace Tizen.NUI.Components { internal partial class DefaultThemeCreator { - private HashSet actionSet; - private DefaultThemeCreator() { } public static IThemeCreator Instance { get; set; } = new DefaultThemeCreator(); - public HashSet GetExternalThemeKeyListSet() - { - if (actionSet != null) - { - return actionSet; - } - - actionSet = new HashSet() - { - // Button - (new ExternalThemeKeyList(typeof(Button), typeof(ButtonStyle))) - .AddBackgroundSelector("/Background", SetBackgroundColor, SetBackgroundImage) - .Add("/BackgroundImageBorder", SetBackgroundBorder) - .AddSelector("/Text/TextColor", SetButtonTextColor) - .AddSelector("/Text/PixelSize", SetButtonTextPixelSize), - - // CheckBox - (new ExternalThemeKeyList(typeof(CheckBox), typeof(ButtonStyle))) - .AddSelector("/Icon/ResourceUrl", SetButtonIconResourceUrl, ControlState.Selected, ControlState.DisabledSelected) - .Add("/Icon/Border", SetButtonIconBorder) - .AddSelector("/Text/TextColor", SetButtonTextColor, ControlState.Selected, ControlState.DisabledSelected) - .AddSelector("/Text/PixelSize", SetButtonTextPixelSize, ControlState.Selected, ControlState.DisabledSelected), - - // RadioButton - (new ExternalThemeKeyList(typeof(RadioButton), typeof(ButtonStyle))) - .AddSelector("/Icon/ResourceUrl", SetButtonIconResourceUrl, ControlState.Selected, ControlState.DisabledSelected) - .Add("/Icon/Border", SetButtonIconBorder) - .AddSelector("/Text/TextColor", SetButtonTextColor, ControlState.Selected, ControlState.DisabledSelected) - .AddSelector("/Text/PixelSize", SetButtonTextPixelSize, ControlState.Selected, ControlState.DisabledSelected), - - // Switch - (new ExternalThemeKeyList(typeof(Switch), typeof(SwitchStyle))) - .AddSelector("/Track/ResourceUrl", (ViewStyle style, Selector value) => ((SwitchStyle)style).Track.ResourceUrl = value, ControlState.Selected, ControlState.DisabledSelected) - .AddSelector("/Thumb/ResourceUrl", (ViewStyle style, Selector value) => ((SwitchStyle)style).Thumb.ResourceUrl = value, ControlState.Selected, ControlState.DisabledSelected) - .Add("/Track/Border", (ViewStyle style, Rectangle value) => ((SwitchStyle)style).Track.Border = value) - .Add("/Thumb/Border", (ViewStyle style, Rectangle value) => ((SwitchStyle)style).Thumb.Border = value) - .AddSelector("/Text/TextColor", SetButtonTextColor, ControlState.Selected, ControlState.DisabledSelected) - .AddSelector("/Text/PixelSize", SetButtonTextPixelSize, ControlState.Selected, ControlState.DisabledSelected), - - // Progress - (new ExternalThemeKeyList(typeof(Progress), typeof(ProgressStyle))) - .AddSelector("/Track/Background", (ViewStyle style, Selector value) => ((ProgressStyle)style).Track.BackgroundColor = value) - .AddSelector("/Buffer/Background", (ViewStyle style, Selector value) => ((ProgressStyle)style).Buffer.BackgroundColor = value) - .AddSelector("/Progress/Background", (ViewStyle style, Selector value) => ((ProgressStyle)style).Progress.BackgroundColor = value) - .AddSelector("/Track/ResourceUrl", (ViewStyle style, Selector value) => ((ProgressStyle)style).Track.ResourceUrl = value) - .AddSelector("/Buffer/ResourceUrl", (ViewStyle style, Selector value) => ((ProgressStyle)style).Buffer.ResourceUrl = value) - .AddSelector("/Progress/ResourceUrl", (ViewStyle style, Selector value) => ((ProgressStyle)style).Progress.ResourceUrl = value) - .Add("/IndeterminateImageUrl", (ViewStyle style, string value) => ((ProgressStyle)style).IndeterminateImageUrl = value), - - // Slider - (new ExternalThemeKeyList(typeof(Slider), typeof(SliderStyle))) - .AddSelector("/Track/Background", (ViewStyle style, Selector value) => ((SliderStyle)style).Track.BackgroundColor = value) - .AddSelector("/Progress/Background", (ViewStyle style, Selector value) => ((SliderStyle)style).Progress.BackgroundColor = value) - .AddSelector("/Thumb/Background", (ViewStyle style, Selector value) => ((SliderStyle)style).Thumb.BackgroundColor = value) - .AddSelector("/Thumb/ResourceUrl", (ViewStyle style, Selector value) => ((SliderStyle)style).Thumb.ResourceUrl = value) - .AddSelector("/ValueIndicatorImage/ResourceUrl", (ViewStyle style, Selector value) => ((SliderStyle)style).ValueIndicatorImage.ResourceUrl = value), - - // Pagination - (new ExternalThemeKeyList(typeof(Pagination), typeof(PaginationStyle))) - .AddSelector("/IndicatorImageUrl", (ViewStyle style, Selector value) => ((PaginationStyle)style).IndicatorImageUrl = value), - - // Scrollbar - (new ExternalThemeKeyList(typeof(Scrollbar), typeof(ScrollbarStyle))) - .Add("/TrackColor", (ViewStyle style, Color value) => ((ScrollbarStyle)style).TrackColor = value) - .Add("/ThumbColor", (ViewStyle style, Color value) => ((ScrollbarStyle)style).ThumbColor = value), - - // RecyclerViewItem - (new ExternalThemeKeyList(typeof(RecyclerViewItem), typeof(RecyclerViewItemStyle))) - .AddBackgroundSelector("/Background", SetBackgroundColor, SetBackgroundImage, ControlState.Selected) - .Add("/BackgroundImageBorder", SetBackgroundBorder), - - // DefaultTitleItem - (new ExternalThemeKeyList(typeof(DefaultTitleItem), typeof(DefaultTitleItemStyle))) - .AddBackgroundSelector("/Background", SetBackgroundColor, SetBackgroundImage) - .Add("/BackgroundImageBorder", SetBackgroundBorder), - - // AppBar - (new ExternalThemeKeyList(typeof(AppBar), typeof(AppBarStyle))), - - // Picker - (new ExternalThemeKeyList(typeof(Picker), typeof(PickerStyle))) - .Add("/Size", (ViewStyle style, Size value) => ((ViewStyle)style).Size = value) - .AddSelector("/ItemTextLabel/PixelSize", (ViewStyle style, Selector value) => ((PickerStyle)style).ItemTextLabel.PixelSize = value, ControlState.Selected) - .Add("/ItemTextLabel/Size", (ViewStyle style, Size value) => ((PickerStyle)style).ItemTextLabel.Size = value) - .AddSelector("/ItemTextLabel/TextColor", (ViewStyle style, Selector value) => ((PickerStyle)style).ItemTextLabel.TextColor = value, ControlState.Selected) - .AddSelector("/ItemTextLabel/BackgroundColor", (ViewStyle style, Selector value) => ((PickerStyle)style).ItemTextLabel.BackgroundColor = value, ControlState.Selected) - .Add("/Divider/SizeHeight", (ViewStyle style, float? value) => ((PickerStyle)style).Divider.SizeHeight = value) - .Add("/Divider/Position", (ViewStyle style, Position value) => ((PickerStyle)style).Divider.Position = value) - .AddSelector("/Divider/BackgroundColor", (ViewStyle style, Selector value) => ((PickerStyle)style).Divider.BackgroundColor = value, ControlState.Selected) - .Add("/StartScrollOffset", (ViewStyle style, Size value) => ((PickerStyle)style).StartScrollOffset = value), - - // TabButton - (new ExternalThemeKeyList(typeof(TabButton), typeof(TabButtonStyle))) - .Add("/Size", (ViewStyle style, Size value) => ((ViewStyle)style).Size = value) - .Add("/CornerRadius", (ViewStyle style, float? value) => ((ViewStyle)style).CornerRadius = value) - .AddSelector("/BackgroundColor", (ViewStyle style, Selector value) => ((ViewStyle)style).BackgroundColor = value, ControlState.Selected) - .AddSelector("/Text/PixelSize", SetButtonTextPixelSize, ControlState.Selected) - .Add("/Text/Size", (ViewStyle style, Size value) => ((ButtonStyle)style).Text.Size = value) - .AddSelector("/Text/TextColor", SetButtonTextColor, ControlState.Selected) - .Add("/Icon/Size", (ViewStyle style, Size value) => ((ButtonStyle)style).Icon.Size = value) - .AddSelector("/Icon/Color", (ViewStyle style, Selector value) => ((ButtonStyle)style).Icon.Color = value, ControlState.Selected) - .Add("/TopLine/Size", (ViewStyle style, Size value) => ((TabButtonStyle)style).TopLine.Size = value) - .AddSelector("/TopLine/BackgroundColor", (ViewStyle style, Selector value) => ((TabButtonStyle)style).TopLine.BackgroundColor = value, ControlState.Selected) - .Add("/BottomLine/Size", (ViewStyle style, Size value) => ((TabButtonStyle)style).BottomLine.Size = value) - .Add("/BottomLine/Position", (ViewStyle style, Position value) => ((TabButtonStyle)style).BottomLine.Position = value) - .AddSelector("/BottomLine/BackgroundColor", (ViewStyle style, Selector value) => ((TabButtonStyle)style).BottomLine.BackgroundColor = value, ControlState.Selected), - - // AlertDialog - (new ExternalThemeKeyList(typeof(AlertDialog), typeof(AlertDialogStyle))) - .Add("/Size", (ViewStyle style, Size value) => ((ViewStyle)style).Size = value) - .Add("/Padding", (ViewStyle style, Extents value) => ((ViewStyle)style).Padding = value) - .Add("/BackgroundImage", (ViewStyle style, string value) => ((ViewStyle)style).BackgroundImage = value) - .Add("/TitleTextLabel/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).TitleTextLabel.Size = value) - .Add("/TitleTextLabel/Margin", (ViewStyle style, Extents value) => ((AlertDialogStyle)style).TitleTextLabel.Margin = value) - .Add("/TitleTextLabel/PixelSize", (ViewStyle style, float? value) => ((AlertDialogStyle)style).TitleTextLabel.PixelSize = value) - .Add("/TitleTextLabel/HorizontalAlignment", (ViewStyle style, HorizontalAlignment? value) => ((AlertDialogStyle)style).TitleTextLabel.HorizontalAlignment = value) - .Add("/TitleTextLabel/VerticalAlignment", (ViewStyle style, VerticalAlignment? value) => ((AlertDialogStyle)style).TitleTextLabel.VerticalAlignment = value) - .AddSelector("/TitleTextLabel/TextColor", (ViewStyle style, Selector value) => ((AlertDialogStyle)style).TitleTextLabel.TextColor = value) - .Add("/MessageTextLabel/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).MessageTextLabel.Size = value) - .Add("/MessageTextLabel/Margin", (ViewStyle style, Extents value) => ((AlertDialogStyle)style).MessageTextLabel.Margin = value) - .Add("/MessageTextLabel/PixelSize", (ViewStyle style, float? value) => ((AlertDialogStyle)style).MessageTextLabel.PixelSize = value) - .Add("/MessageTextLabel/MultiLine", (ViewStyle style, bool? value) => ((AlertDialogStyle)style).MessageTextLabel.MultiLine = value) - .Add("/MessageTextLabel/HorizontalAlignment", (ViewStyle style, HorizontalAlignment? value) => ((AlertDialogStyle)style).MessageTextLabel.HorizontalAlignment = value) - .Add("/MessageTextLabel/VerticalAlignment", (ViewStyle style, VerticalAlignment? value) => ((AlertDialogStyle)style).MessageTextLabel.VerticalAlignment = value) - .AddSelector("/MessageTextLabel/TextColor", (ViewStyle style, Selector value) => ((AlertDialogStyle)style).MessageTextLabel.TextColor = value) - .Add("/ActionContent/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).ActionContent.Size = value), - - // TimePicker - (new ExternalThemeKeyList(typeof(TimePicker), typeof(TimePickerStyle))) - .Add("/CellPadding", (ViewStyle style, Size value) => ((TimePickerStyle)style).Size = value) - .Add("/Pickers/Size", (ViewStyle style, Size value) => ((TimePickerStyle)style).Pickers.Size = value) - .AddSelector("/Pickers/ItemTextLabel/PixelSize", (ViewStyle style, Selector value) => ((TimePickerStyle)style).Pickers.ItemTextLabel.PixelSize = value, ControlState.Selected) - .Add("/Pickers/ItemTextLabel/Size", (ViewStyle style, Size value) => ((TimePickerStyle)style).Pickers.ItemTextLabel.Size = value) - .AddSelector("/Pickers/ItemTextLabel/TextColor", (ViewStyle style, Selector value) => ((TimePickerStyle)style).Pickers.ItemTextLabel.TextColor = value, ControlState.Selected) - .AddSelector("/Pickers/ItemTextLabel/BackgroundColor", (ViewStyle style, Selector value) => ((TimePickerStyle)style).Pickers.ItemTextLabel.BackgroundColor = value, ControlState.Selected) - .Add("/Pickers/Divider/SizeHeight", (ViewStyle style, float? value) => ((TimePickerStyle)style).Pickers.Divider.SizeHeight = value) - .Add("/Pickers/Divider/Position", (ViewStyle style, Position value) => ((TimePickerStyle)style).Pickers.Divider.Position = value) - .AddSelector("/Pickers/Divider/BackgroundColor", (ViewStyle style, Selector value) => ((TimePickerStyle)style).Pickers.Divider.BackgroundColor = value, ControlState.Selected) - .Add("/Pickers/StartScrollOffset", (ViewStyle style, Size value) => ((TimePickerStyle)style).Pickers.StartScrollOffset = value), - - // DatePicker - (new ExternalThemeKeyList(typeof(DatePicker), typeof(DatePickerStyle))) - .Add("/CellPadding", (ViewStyle style, Size value) => ((DatePickerStyle)style).Size = value) - .Add("/Pickers/Size", (ViewStyle style, Size value) => ((DatePickerStyle)style).Pickers.Size = value) - .AddSelector("/Pickers/ItemTextLabel/PixelSize", (ViewStyle style, Selector value) => ((DatePickerStyle)style).Pickers.ItemTextLabel.PixelSize = value, ControlState.Selected) - .Add("/Pickers/ItemTextLabel/Size", (ViewStyle style, Size value) => ((DatePickerStyle)style).Pickers.ItemTextLabel.Size = value) - .AddSelector("/Pickers/ItemTextLabel/TextColor", (ViewStyle style, Selector value) => ((DatePickerStyle)style).Pickers.ItemTextLabel.TextColor = value, ControlState.Selected) - .AddSelector("/Pickers/ItemTextLabel/BackgroundColor", (ViewStyle style, Selector value) => ((DatePickerStyle)style).Pickers.ItemTextLabel.BackgroundColor = value, ControlState.Selected) - .Add("/Pickers/Divider/SizeHeight", (ViewStyle style, float? value) => ((DatePickerStyle)style).Pickers.Divider.SizeHeight = value) - .Add("/Pickers/Divider/Position", (ViewStyle style, Position value) => ((DatePickerStyle)style).Pickers.Divider.Position = value) - .AddSelector("/Pickers/Divider/BackgroundColor", (ViewStyle style, Selector value) => ((DatePickerStyle)style).Pickers.Divider.BackgroundColor = value, ControlState.Selected) - .Add("/Pickers/StartScrollOffset", (ViewStyle style, Size value) => ((DatePickerStyle)style).Pickers.StartScrollOffset = value), - - // AlertDialog - (new ExternalThemeKeyList(typeof(AlertDialog), typeof(AlertDialogStyle))) - .Add("/Size", (ViewStyle style, Size value) => ((ViewStyle)style).Size = value) - .Add("/Padding", (ViewStyle style, Extents value) => ((ViewStyle)style).Padding = value) - .Add("/BackgroundImage", (ViewStyle style, string value) => ((ViewStyle)style).BackgroundImage = value) - .Add("/TitleTextLabel/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).TitleTextLabel.Size = value) - .Add("/TitleTextLabel/Margin", (ViewStyle style, Extents value) => ((AlertDialogStyle)style).TitleTextLabel.Margin = value) - .Add("/TitleTextLabel/PixelSize", (ViewStyle style, float? value) => ((AlertDialogStyle)style).TitleTextLabel.PixelSize = value) - .Add("/TitleTextLabel/HorizontalAlignment", (ViewStyle style, HorizontalAlignment? value) => ((AlertDialogStyle)style).TitleTextLabel.HorizontalAlignment = value) - .Add("/TitleTextLabel/VerticalAlignment", (ViewStyle style, VerticalAlignment? value) => ((AlertDialogStyle)style).TitleTextLabel.VerticalAlignment = value) - .AddSelector("/TitleTextLabel/TextColor", (ViewStyle style, Selector value) => ((AlertDialogStyle)style).TitleTextLabel.TextColor = value) - .Add("/MessageTextLabel/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).MessageTextLabel.Size = value) - .Add("/MessageTextLabel/Margin", (ViewStyle style, Extents value) => ((AlertDialogStyle)style).MessageTextLabel.Margin = value) - .Add("/MessageTextLabel/PixelSize", (ViewStyle style, float? value) => ((AlertDialogStyle)style).MessageTextLabel.PixelSize = value) - .Add("/MessageTextLabel/MultiLine", (ViewStyle style, bool? value) => ((AlertDialogStyle)style).MessageTextLabel.MultiLine = value) - .Add("/MessageTextLabel/HorizontalAlignment", (ViewStyle style, HorizontalAlignment? value) => ((AlertDialogStyle)style).MessageTextLabel.HorizontalAlignment = value) - .Add("/MessageTextLabel/VerticalAlignment", (ViewStyle style, VerticalAlignment? value) => ((AlertDialogStyle)style).MessageTextLabel.VerticalAlignment = value) - .AddSelector("/MessageTextLabel/TextColor", (ViewStyle style, Selector value) => ((AlertDialogStyle)style).MessageTextLabel.TextColor = value) - .Add("/ActionContent/Size", (ViewStyle style, Size value) => ((AlertDialogStyle)style).ActionContent.Size = value), - }; - - return actionSet; - } - public static void Preload() { ThemeManager.AddPackageTheme(Instance); - Instance.GetExternalThemeKeyListSet(); - } - - private static void SetBackgroundColor(ViewStyle style, Selector value) => style.BackgroundColor = value; - - private static void SetBackgroundImage(ViewStyle style, Selector value) => style.BackgroundImage = value; - private static void SetBackgroundBorder(ViewStyle style, Rectangle value) => style.BackgroundImageBorder = value; +#if ExternalThemeEnabled + if (string.IsNullOrEmpty(ExternalThemeManager.CurrentThemeId)) return; - private static void SetButtonTextColor(ViewStyle style, Selector value) => ((ButtonStyle)style).Text.TextColor = value; - - private static void SetButtonTextPixelSize(ViewStyle style, Selector value) => ((ButtonStyle)style).Text.PixelSize = value; - - private static void SetButtonIconResourceUrl(ViewStyle style, Selector value) => ((ButtonStyle)style).Icon.ResourceUrl = value; - - private static void SetButtonIconBorder(ViewStyle style, Rectangle value) => ((ButtonStyle)style).Icon.Border = value; - - private static void SetButtonIconBackgroundColor(ViewStyle style, Selector value) => ((ButtonStyle)style).Icon.BackgroundColor = value; - - private static void SetButtonIconBackgroundImageUrl(ViewStyle style, Selector value) => ((ButtonStyle)style).Icon.BackgroundImage = value; - - private static void SetButtonIconBackgroundBorder(ViewStyle style, Rectangle value) => ((ButtonStyle)style).Icon.BackgroundImageBorder = value; + ThemeManager.LoadPlatformTheme(ExternalThemeManager.CurrentThemeId); +#endif + } } } diff --git a/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs b/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs index 6ccbbd8..1f17bcf 100755 --- a/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs +++ b/src/Tizen.NUI.Components/Theme/DefaultThemeCommon.cs @@ -24,6 +24,9 @@ namespace Tizen.NUI.Components // It is a C# version of res/Tizen.NUI.Components_Tizen.NUI.Theme.Common.xaml internal partial class DefaultThemeCreator : IThemeCreator { + /// + /// The base theme description. + /// [SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope", Justification = "The responsibility to dispose the object is transferred to the theme object.")] public Theme Create() { @@ -33,6 +36,7 @@ namespace Tizen.NUI.Components Version = Tizen.NUI.DefaultThemeCreator.DefaultVersion }; + // Button base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Button", new ButtonStyle() { Size = new Size(339, 96), @@ -47,11 +51,11 @@ namespace Tizen.NUI.Components }, Text = new TextLabelStyle() { - PixelSize = 32, TextColor = Color.White, } }); + // CheckBox base style theme.AddStyleWithoutClone("Tizen.NUI.Components.CheckBox", new ButtonStyle() { ItemSpacing = new Size2D(32, 32), @@ -73,11 +77,11 @@ namespace Tizen.NUI.Components }, Text = new TextLabelStyle() { - PixelSize = 32, TextColor = new Color("#001447") } }); + // Popup base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Popup", new PopupStyle() { Size = new Size(500, 280), @@ -96,6 +100,7 @@ namespace Tizen.NUI.Components Buttons = new ButtonStyle() { Size = new Size(0, 80), + CornerRadius = 0, BackgroundColor = new Selector() { Normal = new Color(1, 1, 1, 1), @@ -116,6 +121,7 @@ namespace Tizen.NUI.Components } }); + // Progress base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Progress", new ProgressStyle() { Size = new Size(200, 25), @@ -140,6 +146,7 @@ namespace Tizen.NUI.Components IndeterminateImageUrl = FrameworkInformation.ResourcePath + "nui_component_default_progress_indeterminate.png", }); + // RadioButton base style theme.AddStyleWithoutClone("Tizen.NUI.Components.RadioButton", new ButtonStyle() { ItemSpacing = new Size2D(32, 32), @@ -161,11 +168,11 @@ namespace Tizen.NUI.Components }, Text = new TextLabelStyle() { - PixelSize = 32, TextColor = new Color("#001447") } }); + // Slider base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Slider", new SliderStyle() { Size = new Size(200, 50), @@ -204,6 +211,7 @@ namespace Tizen.NUI.Components }, }); + // Switch base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Switch", new SwitchStyle() { ItemSpacing = new Size2D(32, 32), @@ -237,16 +245,17 @@ namespace Tizen.NUI.Components }, Text = new TextLabelStyle() { - PixelSize = 32, TextColor = new Color("#001447") } }); + // Loading base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Loading", new LoadingStyle() { LoadingSize = new Size(100, 100), }); + // Pagination base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Pagination", new PaginationStyle() { IndicatorImageUrl = new Selector() @@ -257,32 +266,37 @@ namespace Tizen.NUI.Components IndicatorSize = new Size(10, 10), }); + // Scrollbar base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Scrollbar", new ScrollbarStyle() { TrackThickness = 12, ThumbThickness = 12, TrackColor = new Color(0f, 0f, 0f, 0f), - ThumbColor = new Color("#0A0E4AFF"), + ThumbColor = new Color("#0A0E4A"), TrackPadding = 4, ThumbVerticalImageUrl = FrameworkInformation.ResourcePath + "nui_component_default_scroll_vbar.#.png", ThumbHorizontalImageUrl = FrameworkInformation.ResourcePath + "nui_component_default_scroll_hbar.#.png", }); + // LinearLayouter base style theme.AddStyleWithoutClone("Tizen.NUI.Components.LinearLayouter", new ViewStyle() { Padding = new Extents(64, 64, 0, 0) }); + // GridLayouter base style theme.AddStyleWithoutClone("Tizen.NUI.Components.GridLayouter", new ViewStyle() { Padding = new Extents(0, 0, 0, 0), }); + // ItemsLayouter base style theme.AddStyleWithoutClone("Tizen.NUI.Components.ItemsLayouter", new ViewStyle() { Padding = new Extents(0, 0, 0, 0), }); + // RecyclerViewItem base style theme.AddStyleWithoutClone("Tizen.NUI.Components.RecyclerViewItem", new RecyclerViewItemStyle() { BackgroundColor = new Selector() @@ -294,6 +308,7 @@ namespace Tizen.NUI.Components }, }); + // DefaultLinearItem base style theme.AddStyleWithoutClone("Tizen.NUI.Components.DefaultLinearItem", new DefaultLinearItemStyle() { SizeHeight = 108, @@ -311,14 +326,16 @@ namespace Tizen.NUI.Components PixelSize = 32, Ellipsis = true, FontFamily = "BreezeSans", //FXIME Font Weight is Light - TextColor = new Color("#001447FF"), + TextColor = new Color("#001447"), + ThemeChangeSensitive = false }, SubLabel = new TextLabelStyle() { PixelSize = 28, Ellipsis = true, FontFamily = "BreezeSans", - TextColor = new Color("#001447FF"), + TextColor = new Color("#001447"), + ThemeChangeSensitive = false }, Icon = new ViewStyle() { @@ -332,9 +349,11 @@ namespace Tizen.NUI.Components { SizeHeight = 1, Margin = new Extents(64, 64, 0, 0), - BackgroundColor = new Color("#C3CAD2FF"), + BackgroundColor = new Color("#C3CAD2"), }, }); + + // DefaultGridItem base style theme.AddStyleWithoutClone("Tizen.NUI.Components.DefaultGridItem", new DefaultGridItemStyle() { Padding = new Extents(0, 0, 0, 0), @@ -344,6 +363,7 @@ namespace Tizen.NUI.Components SizeHeight = 60, PixelSize = 24, LineWrapMode = LineWrapMode.Character, + ThemeChangeSensitive = false }, Badge = new ViewStyle() { @@ -351,6 +371,7 @@ namespace Tizen.NUI.Components }, }); + // DefaultTitleItem base style theme.AddStyleWithoutClone("Tizen.NUI.Components.DefaultTitleItem", new DefaultTitleItemStyle() { SizeHeight = 60, @@ -358,13 +379,14 @@ namespace Tizen.NUI.Components Margin = new Extents(0, 0, 0, 0), BackgroundColor = new Selector() { - Normal = new Color("#EEEEF1FF"), + Normal = new Color("#EEEEF1"), }, Label = new TextLabelStyle() { PixelSize = 28, Ellipsis = true, - TextColor = new Color("#001447FF"), + TextColor = new Color("#001447"), + ThemeChangeSensitive = false }, Icon = new ViewStyle() { @@ -377,15 +399,17 @@ namespace Tizen.NUI.Components }, }); + // ContentPage base style theme.AddStyleWithoutClone("Tizen.NUI.Components.ContentPage", new ViewStyle() { - BackgroundColor = new Color("#EEEFF1FF"), + BackgroundColor = new Color("#EEEFF1"), }); + // AppBar base style theme.AddStyleWithoutClone("Tizen.NUI.Components.AppBar", new AppBarStyle() { Size = new Size(-1, 120), - BackgroundColor = new Color("#EEEFF1FF"), + BackgroundColor = new Color("#EEEFF1"), BackButton = new ButtonStyle() { Size = new Size(48, 48), @@ -397,12 +421,13 @@ namespace Tizen.NUI.Components ResourceUrl = FrameworkInformation.ResourcePath + "nui_component_default_back_button.png", Color = new Selector() { - Normal = new Color("#0A0E4AFF"), - Focused = new Color("#00338BFF"), - Pressed = new Color("#1B69CAFF"), - Disabled = new Color("#C3CAD2FF"), + Normal = new Color("#0A0E4A"), + Focused = new Color("#00338B"), + Pressed = new Color("#1B69CA"), + Disabled = new Color("#C3CAD2"), }, }, + ThemeChangeSensitive = false }, TitleTextLabel = new TextLabelStyle() { @@ -410,8 +435,9 @@ namespace Tizen.NUI.Components VerticalAlignment = VerticalAlignment.Center, TextColor = new Selector() { - Normal = new Color("#000C2BFF"), - } + Normal = new Color("#000C2B"), + }, + ThemeChangeSensitive = false }, ActionView = new ViewStyle() { @@ -429,10 +455,10 @@ namespace Tizen.NUI.Components PixelSize = 26, TextColor = new Selector() { - Normal = new Color("#0A0E4AFF"), - Focused = new Color("#00338BFF"), - Pressed = new Color("#1B69CAFF"), - Disabled = new Color("#C3CAD2FF"), + Normal = new Color("#0A0E4A"), + Focused = new Color("#00338B"), + Pressed = new Color("#1B69CA"), + Disabled = new Color("#C3CAD2"), }, }, Icon = new ImageViewStyle() @@ -440,12 +466,13 @@ namespace Tizen.NUI.Components Size = new Size(-1, 48), Color = new Selector() { - Normal = new Color("#0A0E4AFF"), - Focused = new Color("#00338BFF"), - Pressed = new Color("#1B69CAFF"), - Disabled = new Color("#C3CAD2FF"), + Normal = new Color("#0A0E4A"), + Focused = new Color("#00338B"), + Pressed = new Color("#1B69CA"), + Disabled = new Color("#C3CAD2"), }, }, + ThemeChangeSensitive = false, }, Padding = new Extents(64, 64, 0, 0), NavigationPadding = new Extents(0, 24, 0, 0), @@ -453,6 +480,7 @@ namespace Tizen.NUI.Components ActionCellPadding = new Size2D(40, 0), }); + // Picker base style theme.AddStyleWithoutClone("Tizen.NUI.Components.Picker", new PickerStyle() { Size = new Size(160, 339), @@ -465,7 +493,7 @@ namespace Tizen.NUI.Components Size = new Size(0,72), TextColor = new Selector() { - Normal = new Color("#000C2BFF"), + Normal = new Color("#000C2B"), }, BackgroundColor = Color.White, }, @@ -474,11 +502,12 @@ namespace Tizen.NUI.Components SizeHeight = 2.0f, WidthResizePolicy = ResizePolicyType.FillToParent, Position = new Position(0, 132), - BackgroundColor = new Color("#0A0E4AFF"), + BackgroundColor = new Color("#0A0E4A"), }, StartScrollOffset = new Size(0, 12), }); + // TabButton base style theme.AddStyleWithoutClone("Tizen.NUI.Components.TabButton", new TabButtonStyle() { Size = new Size(-1, 84), @@ -490,21 +519,22 @@ namespace Tizen.NUI.Components Size = new Size(-2, -2), TextColor = new Selector() { - Normal = new Color("#000C2BFF"), - Selected = new Color("#000C2BFF"), - Pressed = new Color("#1473E6FF"), - Disabled = new Color("#C3CAD2FF"), + Normal = new Color("#000C2B"), + Selected = new Color("#000C2B"), + Pressed = new Color("#1473E6"), + Disabled = new Color("#C3CAD2"), }, + ThemeChangeSensitive = false, }, Icon = new ImageViewStyle() { Size = new Size(48, 48), Color = new Selector() { - Normal = new Color("#000C2BFF"), - Selected = new Color("#000C2BFF"), - Pressed = new Color("#1473E6FF"), - Disabled = new Color("#C3CAD2FF"), + Normal = new Color("#000C2B"), + Selected = new Color("#000C2B"), + Pressed = new Color("#1473E6"), + Disabled = new Color("#C3CAD2"), }, }, TopLine = new ViewStyle() @@ -512,10 +542,10 @@ namespace Tizen.NUI.Components Size = new Size(-1, 1), BackgroundColor = new Selector() { - Normal = new Color("#000C2BFF"), - Selected = new Color("#000C2BFF"), - Pressed = new Color("#1473E6FF"), - Disabled = new Color("#C3CAD2FF"), + Normal = new Color("#000C2B"), + Selected = new Color("#000C2B"), + Pressed = new Color("#1473E6"), + Disabled = new Color("#C3CAD2"), }, }, BottomLine = new ViewStyle() @@ -525,17 +555,19 @@ namespace Tizen.NUI.Components BackgroundColor = new Selector() { Normal = Color.Transparent, - Selected = new Color("#000C2BFF"), - Pressed = new Color("#1473E6FF"), + Selected = new Color("#000C2B"), + Pressed = new Color("#1473E6"), Disabled = Color.Transparent, }, }, }); + // NotificationToast base style theme.AddStyleWithoutClone("NotificationToast", new TextLabelStyle() { - BackgroundImage = FrameworkInformation.ResourcePath + "IoT_Toast_1.png", - BackgroundImageBorder = new Rectangle(28, 28, 28, 28), + BackgroundColor = new Color("#F2F7FF"), + CornerRadius = 20.0f, + BoxShadow = new Shadow(5.0f, new Color("#00000066"), new Vector2(2.0f, 2.0f)), TextColor = new Color("#000C2B"), PixelSize = 32, WidthResizePolicy = ResizePolicyType.UseNaturalSize, @@ -547,42 +579,42 @@ namespace Tizen.NUI.Components PositionY = 120, }); + // AlertDialog base style theme.AddStyleWithoutClone("Tizen.NUI.Components.AlertDialog", new AlertDialogStyle() { Size = new Size(-2, -2), Padding = new Extents(80, 80, 0, 0), - BackgroundImage = FrameworkInformation.ResourcePath + "nui_component_default_dialog_bg.#.png", + BackgroundColor = Color.White, + CornerRadius = 28.0f, + BoxShadow = new Shadow(2.0f, new Color("#00000029"), new Vector2(2.0f, 2.0f)), TitleTextLabel = new TextLabelStyle() { - Size = new Size(1024, -2), + Size = new Size(600, -2), Margin = new Extents(0, 0, 40, 40), PixelSize = 40, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - }, + TextColor = new Color("#000C2B"), + ThemeChangeSensitive = false, }, MessageTextLabel = new TextLabelStyle() { - Size = new Size(1024, -2), + Size = new Size(600, -2), Margin = new Extents(0, 0, 0, 64), PixelSize = 32, MultiLine = true, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - }, + TextColor = new Color("#000C2B"), + ThemeChangeSensitive = false, }, ActionContent = new ViewStyle() { - Size = new Size(1024, -2), + Size = new Size(600, -2), }, }); + // TimePicker base style theme.AddStyleWithoutClone("Tizen.NUI.Components.TimePicker", new TimePickerStyle() { CellPadding = new Size(50, 339), @@ -597,23 +629,22 @@ namespace Tizen.NUI.Components VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Size = new Size(0,72), - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - }, + TextColor = new Color("#000C2B"), BackgroundColor = Color.White, + ThemeChangeSensitive = false }, Divider = new ViewStyle() { SizeHeight = 2.0f, WidthResizePolicy = ResizePolicyType.FillToParent, Position = new Position(0, 132), - BackgroundColor = new Color("#0A0E4AFF"), + BackgroundColor = new Color("#0A0E4A"), }, StartScrollOffset = new Size2D(0, 12), } }); + // DatePicker base style theme.AddStyleWithoutClone("Tizen.NUI.Components.DatePicker", new DatePickerStyle() { CellPadding = new Size(50, 339), @@ -628,23 +659,22 @@ namespace Tizen.NUI.Components VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Size = new Size(0,72), - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - }, + TextColor = new Color("#000C2B"), BackgroundColor = Color.White, + ThemeChangeSensitive = false }, Divider = new ViewStyle() { SizeHeight = 2.0f, WidthResizePolicy = ResizePolicyType.FillToParent, Position = new Position(0, 132), - BackgroundColor = new Color("#0A0E4AFF"), + BackgroundColor = new Color("#0A0E4A"), }, StartScrollOffset = new Size2D(0, 12), } }); + // MenuItem base style theme.AddStyleWithoutClone("Tizen.NUI.Components.MenuItem", new ButtonStyle() { Size = new Size(480, -2), @@ -660,21 +690,22 @@ namespace Tizen.NUI.Components VerticalAlignment = VerticalAlignment.Center, TextColor = new Selector() { - Normal = new Color("#001447FF"), - Focused = new Color("#00338BFF"), - Pressed = new Color("#1B69CAFF"), - Disabled = new Color("#C3CAD2FF"), + Normal = new Color("#001447"), + Focused = new Color("#00338B"), + Pressed = new Color("#1B69CA"), + Disabled = new Color("#C3CAD2"), }, + ThemeChangeSensitive = false }, Icon = new ImageViewStyle() { Size = new Size(-2, 48), Color = new Selector() { - Normal = new Color("#001447FF"), - Focused = new Color("#00338BFF"), - Pressed = new Color("#1B69CAFF"), - Disabled = new Color("#C3CAD2FF"), + Normal = new Color("#001447"), + Focused = new Color("#00338B"), + Pressed = new Color("#1B69CA"), + Disabled = new Color("#C3CAD2"), }, }, }); @@ -684,4 +715,4 @@ namespace Tizen.NUI.Components } } -#endif +#endif // !PROFILE_WEARABLE diff --git a/src/Tizen.NUI.Components/Theme/ThemeDark.cs b/src/Tizen.NUI.Components/Theme/ThemeDark.cs deleted file mode 100755 index 5781f25..0000000 --- a/src/Tizen.NUI.Components/Theme/ThemeDark.cs +++ /dev/null @@ -1,611 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#if false - -using System.Diagnostics.CodeAnalysis; -using Tizen.NUI.BaseComponents; - -namespace Tizen.NUI.Components -{ - internal partial class DefaultThemeCreator : IThemeCreator - { - [SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope", Justification = "The responsibility to dispose the object is transferred to the theme object.")] - public Theme Create() - { - var theme = new Theme() - { - Id = Tizen.NUI.DefaultThemeCreator.DefaultId, - Version = Tizen.NUI.DefaultThemeCreator.DefaultVersion - }; - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Button", new ButtonStyle() - { - Size = new Size(339, 96), - CornerRadiusPolicy = VisualTransformPolicyType.Relative, - CornerRadius = 0.2916f, - ItemAlignment = LinearLayout.Alignment.Center, - BackgroundColor = new Selector() - { - Normal = new Color(0.039f, 0.055f, 0.29f, 1), - Pressed = new Color(0.106f, 0.412f, 0.792f, 1), - Focused = new Color(0, 0.2f, 0.545f, 1), - Disabled = new Color(0.765f, 0.792f, 0.824f, 1), - }, - Text = new TextLabelStyle() - { - PixelSize = 32, - TextColor = Color.White, - } - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.CheckBox", new ButtonStyle() - { - ItemSpacing = new Size2D(32, 32), - ItemAlignment = LinearLayout.Alignment.Begin, - Icon = new ImageViewStyle() - { - Size = new Size(36, 36), - ResourceUrl = new Selector() - { - Normal = FrameworkInformation.ResourcePath + "IoT_check_off.svg", - Pressed = FrameworkInformation.ResourcePath + "IoT_check_off_p.svg", - Disabled = FrameworkInformation.ResourcePath + "IoT_check_off_d.svg", - Focused = FrameworkInformation.ResourcePath + "IoT_check_off_f.svg", - Selected = FrameworkInformation.ResourcePath + "IoT_check_on.svg", - SelectedPressed = FrameworkInformation.ResourcePath + "IoT_check_on_p.svg", - SelectedFocused = FrameworkInformation.ResourcePath + "IoT_check_on_f.svg", - DisabledSelected = FrameworkInformation.ResourcePath + "IoT_check_on_d.svg", - }, - }, - Text = new TextLabelStyle() - { - PixelSize = 32, - TextColor = new Color("#001447") - } - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Popup", new PopupStyle() - { - Size = new Size(500, 280), - BackgroundColor = new Color(0.9f, 0.9f, 0.9f, 1), - ImageShadow = new ImageShadow() - { - Url = FrameworkInformation.ResourcePath + "nui_component_default_popup_shadow.png", - Border = new Rectangle(24, 24, 24, 24), - Extents = new Vector2(48, 48) - }, - Title = new TextLabelStyle() - { - PointSize = 16, - Padding = new Extents(20, 20, 20, 20), - }, - Buttons = new ButtonStyle() - { - Size = new Size(0, 80), - BackgroundColor = new Selector() - { - Normal = new Color(1, 1, 1, 1), - Pressed = new Color(1, 1, 1, 0.5f), - }, - Overlay = new ImageViewStyle() - { - BackgroundColor = new Selector() - { - Pressed = new Color(0, 0, 0, 0.1f), - Other = new Color(1, 1, 1, 0.1f), - }, - }, - Text = new TextLabelStyle() - { - TextColor = new Color(0.05f, 0.63f, 0.9f, 1), - } - } - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Progress", new ProgressStyle() - { - Size = new Size(200, 25), - Track = new ImageViewStyle() - { - ResourceUrl = FrameworkInformation.ResourcePath + "IoT_progressindicator_empty.png", - BackgroundColor = new Color(0, 0, 0, 0.1f), - }, - Buffer = new ImageViewStyle() - { - BackgroundColor = new Color(0.05f, 0.63f, 0.9f, 0.3f), - }, - Progress = new ImageViewStyle() - { - ResourceUrl = new Selector() - { - Normal = FrameworkInformation.ResourcePath + "IoT_progressindicator_progress_dark.png", - Disabled = FrameworkInformation.ResourcePath + "IoT_progressindicator_progressdisabled.png", - }, - BackgroundColor = new Color(0.05f, 0.63f, 0.9f, 1), - }, - IndeterminateImageUrl = FrameworkInformation.ResourcePath + "nui_component_default_progress_indeterminate.png", - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.RadioButton", new ButtonStyle() - { - ItemSpacing = new Size2D(32, 32), - ItemAlignment = LinearLayout.Alignment.Begin, - Icon = new ImageViewStyle() - { - Size = new Size(36, 36), - ResourceUrl = new Selector() - { - Normal = FrameworkInformation.ResourcePath + "IoT_radiobutton_off.svg", - Pressed = FrameworkInformation.ResourcePath + "IoT_radiobutton_off_p.svg", - Disabled = FrameworkInformation.ResourcePath + "IoT_radiobutton_off_d.svg", - Focused = FrameworkInformation.ResourcePath + "IoT_radiobutton_off_f.svg", - Selected = FrameworkInformation.ResourcePath + "IoT_radiobutton_on.svg", - SelectedPressed = FrameworkInformation.ResourcePath + "IoT_radiobutton_on_p.svg", - SelectedFocused = FrameworkInformation.ResourcePath + "IoT_radiobutton_on_f.svg", - DisabledSelected = FrameworkInformation.ResourcePath + "IoT_radiobutton_on_d.svg", - }, - }, - Text = new TextLabelStyle() - { - PixelSize = 32, - TextColor = new Color("#001447") - } - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Slider", new SliderStyle() - { - Size = new Size(200, 50), - TrackThickness = 8, - Track = new ImageViewStyle() - { - Size = new Size(100, 8), - ResourceUrl = new Selector() - { - Normal = FrameworkInformation.ResourcePath + "IoT_slider_status_empty_track.png", - Disabled = FrameworkInformation.ResourcePath + "IoT_slider_status_track_disabled.png", - }, - BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.1f), - }, - Progress = new ImageViewStyle() - { - Size = new Size(100, 8), - ResourceUrl = FrameworkInformation.ResourcePath + "IoT_slider_status_trackW.png", - BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1), - }, - Thumb = new ImageViewStyle() - { - Size = new Size(36, 36), - ResourceUrl = FrameworkInformation.ResourcePath + "IoT_slider_handler_normalW.png", - }, - ValueIndicatorImage = new ImageViewStyle() - { - Size = new Size(49, 24), - BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f), - }, - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Switch", new SwitchStyle() - { - ItemSpacing = new Size2D(32, 32), - ItemAlignment = LinearLayout.Alignment.Begin, - Track = new ImageViewStyle() - { - Size = new Size(80, 40), - ResourceUrl = new Selector() - { - Normal = FrameworkInformation.ResourcePath + "IoT_switch_track_off.svg", - Pressed = FrameworkInformation.ResourcePath + "IoT_switch_track_off_p.svg", - Disabled = FrameworkInformation.ResourcePath + "IoT_switch_track_off_d.svg", - Focused = FrameworkInformation.ResourcePath + "IoT_switch_track_off_f.svg", - Selected = FrameworkInformation.ResourcePath + "IoT_switch_track_on.svg", - SelectedPressed = FrameworkInformation.ResourcePath + "IoT_switch_track_on_p.svg", - SelectedFocused = FrameworkInformation.ResourcePath + "IoT_switch_track_on_f.svg", - DisabledSelected = FrameworkInformation.ResourcePath + "IoT_switch_track_on_d.svg", - }, - }, - Thumb = new ImageViewStyle() - { - Size = new Size(40, 40), - ResourceUrl = new Selector() - { - Normal = FrameworkInformation.ResourcePath + "IoT_switch_thumb.svg", - Disabled = FrameworkInformation.ResourcePath + "IoT_switch_thumb_d.svg", - Selected = FrameworkInformation.ResourcePath + "IoT_switch_thumb_s.svg", - SelectedPressed = FrameworkInformation.ResourcePath + "IoT_switch_thumb_sp.svg", - SelectedFocused = FrameworkInformation.ResourcePath + "IoT_switch_thumb_sf.svg", - } - }, - Text = new TextLabelStyle() - { - PixelSize = 32, - TextColor = new Color("#001447") - } - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Loading", new LoadingStyle() - { - LoadingSize = new Size(100, 100), - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Pagination", new PaginationStyle() - { - IndicatorImageUrl = new Selector() - { - Normal = FrameworkInformation.ResourcePath + "nui_component_default_pagination_normal_dot.png", - Selected = FrameworkInformation.ResourcePath + "nui_component_default_pagination_focus_dot.png", - }, - IndicatorSize = new Size(10, 10), - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Scrollbar", new ScrollbarStyle() - { - TrackThickness = 12, - ThumbThickness = 12, - TrackColor = new Color(0f, 0f, 0f, 0f), - ThumbColor = new Color("#0A0E4AFF"), - TrackPadding = 4, - ThumbVerticalImageUrl = FrameworkInformation.ResourcePath + "nui_component_default_scroll_vbar.#.png", - ThumbHorizontalImageUrl = FrameworkInformation.ResourcePath + "nui_component_default_scroll_hbar.#.png", - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.LinearLayouter", new ViewStyle() - { - Padding = new Extents(64, 64, 0, 0) - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.GridLayouter", new ViewStyle() - { - Padding = new Extents(0, 0, 0, 0), - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.ItemsLayouter", new ViewStyle() - { - Padding = new Extents(0, 0, 0, 0), - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.RecyclerViewItem", new RecyclerViewItemStyle() - { - BackgroundColor = new Selector() - { - Normal = new Color(1, 1, 1, 1), - Pressed = new Color(0.85f, 0.85f, 0.85f, 1), - Disabled = new Color(0.70f, 0.70f, 0.70f, 1), - Selected = new Color(0.701f, 0.898f, 0.937f, 1), - }, - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.DefaultLinearItem", new DefaultLinearItemStyle() - { - SizeHeight = 108, - Padding = new Extents(64, 64, 18, 17), - Margin = new Extents(0, 0, 0, 0), - BackgroundColor = new Selector() - { - Normal = new Color(1, 1, 1, 1), - Pressed = new Color(0.85f, 0.85f, 0.85f, 1), - Disabled = new Color(0.70f, 0.70f, 0.70f, 1), - Selected = new Color(0.85f, 0.85f, 0.85f, 1), - }, - Label = new TextLabelStyle() - { - PixelSize = 32, - Ellipsis = true, - FontFamily = "BreezeSans", //FXIME Font Weight is Light - TextColor = new Color("#001447FF"), - }, - SubLabel = new TextLabelStyle() - { - PixelSize = 28, - Ellipsis = true, - FontFamily = "BreezeSans", - TextColor = new Color("#001447FF"), - }, - Icon = new ViewStyle() - { - Margin = new Extents(0, 32, 0, 0) - }, - Extra = new ViewStyle() - { - Margin = new Extents(32, 0, 0, 0) - }, - Seperator = new ViewStyle() - { - SizeHeight = 1, - Margin = new Extents(64, 64, 0, 0), - BackgroundColor = new Color("#C3CAD2FF"), - }, - }); - theme.AddStyleWithoutClone("Tizen.NUI.Components.DefaultGridItem", new DefaultGridItemStyle() - { - Padding = new Extents(0, 0, 0, 0), - Margin = new Extents(5, 5, 5, 5), - Caption = new TextLabelStyle() - { - SizeHeight = 60, - PixelSize = 24, - LineWrapMode = LineWrapMode.Character, - }, - Badge = new ViewStyle() - { - Margin = new Extents(5, 5, 5, 5), - }, - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.DefaultTitleItem", new DefaultTitleItemStyle() - { - SizeHeight = 60, - Padding = new Extents(64, 64, 12, 12), - Margin = new Extents(0, 0, 0, 0), - BackgroundColor = new Selector() - { - Normal = new Color("#EEEEF1FF"), - }, - Label = new TextLabelStyle() - { - PixelSize = 28, - Ellipsis = true, - TextColor = new Color("#001447FF"), - }, - Icon = new ViewStyle() - { - Margin = new Extents(40, 0, 0, 0) - }, - Seperator = new ViewStyle() - { - Margin = new Extents(0, 0, 0, 0), - BackgroundColor = new Color(0, 0, 0, 0), - }, - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.ContentPage", new ViewStyle() - { - BackgroundColor = new Color("#EEEFF1FF"), - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.AppBar", new AppBarStyle() - { - Size = new Size(-1, 120), - BackgroundColor = new Color("#EEEFF1FF"), - BackButton = new ButtonStyle() - { - Size = new Size(48, 48), - CornerRadius = 0, - BackgroundColor = new Color(0, 0, 0, 0), - Icon = new ImageViewStyle() - { - Size = new Size(48, 48), - ResourceUrl = FrameworkInformation.ResourcePath + "nui_component_default_back_button.png", - Color = new Selector() - { - Normal = new Color("#0A0E4AFF"), - Focused = new Color("#00338BFF"), - Pressed = new Color("#1B69CAFF"), - Disabled = new Color("#C3CAD2FF"), - }, - }, - }, - TitleTextLabel = new TextLabelStyle() - { - PixelSize = 40, - VerticalAlignment = VerticalAlignment.Center, - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - } - }, - ActionView = new ViewStyle() - { - Size = new Size(-1, 48), - CornerRadius = 0, - BackgroundColor = new Color(0, 0, 0, 0), - }, - ActionButton = new ButtonStyle() - { - Size = new Size(-1, 48), - CornerRadius = 0, - BackgroundColor = new Color(0, 0, 0, 0), - Text = new TextLabelStyle() - { - PixelSize = 26, - TextColor = new Selector() - { - Normal = new Color("#0A0E4AFF"), - Focused = new Color("#00338BFF"), - Pressed = new Color("#1B69CAFF"), - Disabled = new Color("#C3CAD2FF"), - }, - }, - Icon = new ImageViewStyle() - { - Size = new Size(-1, 48), - Color = new Selector() - { - Normal = new Color("#0A0E4AFF"), - Focused = new Color("#00338BFF"), - Pressed = new Color("#1B69CAFF"), - Disabled = new Color("#C3CAD2FF"), - }, - }, - }, - Padding = new Extents(64, 64, 0, 0), - NavigationPadding = new Extents(0, 24, 0, 0), - ActionPadding = new Extents(40, 0, 0, 0), - ActionCellPadding = new Size2D(40, 0), - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.Picker", new PickerStyle() - { - Size = new Size(160, 339), - ItemTextLabel = new TextLabelStyle() - { - //FIXME: Should be check PointSize. given size from UX is too large. - PixelSize = 32, - VerticalAlignment = VerticalAlignment.Center, - HorizontalAlignment = HorizontalAlignment.Center, - Size = new Size(0,72), - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - }, - BackgroundColor = Color.White, - }, - Divider = new ViewStyle() - { - SizeHeight = 2.0f, - WidthResizePolicy = ResizePolicyType.FillToParent, - Position = new Position(0, 132), - BackgroundColor = new Color("#0A0E4AFF"), - }, - StartScrollOffset = new Size(0, 12), - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.TabButton", new TabButtonStyle() - { - Size = new Size(-1, 84), - CornerRadius = 0, - BackgroundColor = Color.White, - Text = new TextLabelStyle() - { - PixelSize = 28, - Size = new Size(-2, -2), - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - Selected = new Color("#000C2BFF"), - Pressed = new Color("#1473E6FF"), - Disabled = new Color("#C3CAD2FF"), - }, - }, - Icon = new ImageViewStyle() - { - Size = new Size(48, 48), - Color = new Selector() - { - Normal = new Color("#000C2BFF"), - Selected = new Color("#000C2BFF"), - Pressed = new Color("#1473E6FF"), - Disabled = new Color("#C3CAD2FF"), - }, - }, - TopLine = new ViewStyle() - { - Size = new Size(-1, 1), - BackgroundColor = new Selector() - { - Normal = new Color("#000C2BFF"), - Selected = new Color("#000C2BFF"), - Pressed = new Color("#1473E6FF"), - Disabled = new Color("#C3CAD2FF"), - }, - }, - BottomLine = new ViewStyle() - { - Size = new Size(-1, 8), - Position = new Position(0, 76), // 84 - 8 - BackgroundColor = new Selector() - { - Normal = Color.Transparent, - Selected = new Color("#000C2BFF"), - Pressed = new Color("#1473E6FF"), - Disabled = Color.Transparent, - }, - }, - }); - - 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, - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.TimePicker", new TimePickerStyle() - { - CellPadding = new Size(50, 339), - - Pickers = new PickerStyle() - { - Size = new Size(160, 339), - ItemTextLabel = new TextLabelStyle() - { - //FIXME: Should be check PointSize. given size from UX is too large. - PixelSize = 32, - VerticalAlignment = VerticalAlignment.Center, - HorizontalAlignment = HorizontalAlignment.Center, - Size = new Size(0,72), - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - }, - BackgroundColor = Color.White, - }, - Divider = new ViewStyle() - { - SizeHeight = 2.0f, - WidthResizePolicy = ResizePolicyType.FillToParent, - Position = new Position(0, 132), - BackgroundColor = new Color("#0A0E4AFF"), - }, - StartScrollOffset = new Size2D(0, 12), - } - }); - - theme.AddStyleWithoutClone("Tizen.NUI.Components.DatePicker", new DatePickerStyle() - { - CellPadding = new Size(50, 339), - - Pickers = new PickerStyle() - { - Size = new Size(160, 339), - ItemTextLabel = new TextLabelStyle() - { - //FIXME: Should be check PointSize. given size from UX is too large. - PixelSize = 32, - VerticalAlignment = VerticalAlignment.Center, - HorizontalAlignment = HorizontalAlignment.Center, - Size = new Size(0,72), - TextColor = new Selector() - { - Normal = new Color("#000C2BFF"), - }, - BackgroundColor = Color.White, - }, - Divider = new ViewStyle() - { - SizeHeight = 2.0f, - WidthResizePolicy = ResizePolicyType.FillToParent, - Position = new Position(0, 132), - BackgroundColor = new Color("#0A0E4AFF"), - }, - StartScrollOffset = new Size2D(0, 12), - } - }); - - return theme; - } - } -} - -#endif diff --git a/src/Tizen.NUI.Components/Utils/StyleManager.cs b/src/Tizen.NUI.Components/Utils/StyleManager.cs index dfc6044..b639a7a 100755 --- a/src/Tizen.NUI.Components/Utils/StyleManager.cs +++ b/src/Tizen.NUI.Components/Utils/StyleManager.cs @@ -28,6 +28,8 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public sealed class StyleManager { + private const string defaultName = "DEFAULT"; + /// /// StyleManager construct. /// @@ -67,6 +69,12 @@ namespace Tizen.NUI.Components var key = value.ToUpperInvariant(); + if (key.Equals(defaultName)) + { + ThemeManager.CurrentTheme = null; + return; + } + // Please note that it does not check "key == Theme" here, // because of the font size issue of the Tizen.NUI.StyleManager. // (There are applications to use NUI.Components.StyleManager.ThemeChangedEvent to fix Tizen.NUI.StyleManager font size issue.) @@ -87,7 +95,7 @@ namespace Tizen.NUI.Components /// /// (Theme name, Theme instance) /// - private Dictionary ThemeMap { get; } = new Dictionary { ["DEFAULT"] = ThemeManager.DefaultTheme }; + private Dictionary ThemeMap { get; } = new Dictionary(); /// /// Register style in StyleManager. @@ -107,17 +115,14 @@ namespace Tizen.NUI.Components if (Activator.CreateInstance(styleType) is StyleBase styleBase) { - var key = "DEFAULT"; - - if (bDefault && theme != null) + if (string.IsNullOrEmpty(theme) || defaultName.Equals(theme, StringComparison.CurrentCultureIgnoreCase)) { - ThemeMap[key].AddStyleWithoutClone(style, styleBase.GetViewStyle()); + ThemeManager.BaseTheme.AddStyleWithoutClone(style, styleBase.GetViewStyle()); + ThemeManager.UpdateThemeForInitialize(); + return; } - if (theme != null) - { - key = theme.ToUpperInvariant(); - } + var key = theme.ToUpperInvariant(); if (!ThemeMap.ContainsKey(key) || ThemeMap[key] == null) { @@ -133,6 +138,12 @@ namespace Tizen.NUI.Components } ThemeMap[key].AddStyleWithoutClone(style, styleBase.GetViewStyle()); + + if (bDefault) + { + ThemeManager.BaseTheme.AddStyleWithoutClone(style, styleBase.GetViewStyle()); + ThemeManager.UpdateThemeForInitialize(); + } } } @@ -168,17 +179,27 @@ namespace Tizen.NUI.Components throw new ArgumentException("The argument targetTheme must be specified"); } - var key = targetTheme.ToUpperInvariant(); - - if (!ThemeMap.ContainsKey(key) || ThemeMap[key] == null) + if (Activator.CreateInstance(style) is StyleBase styleBase) { - Tizen.Log.Error("NUI", "The theme name should be a known one."); - return; - } + if (defaultName.Equals(targetTheme, StringComparison.CurrentCultureIgnoreCase)) + { + ThemeManager.BaseTheme.AddStyleWithoutClone(component.FullName, styleBase.GetViewStyle()); + ThemeManager.UpdateThemeForInitialize(); + return; + } - if (Activator.CreateInstance(style) as StyleBase != null) - { - ThemeMap[key].AddStyleWithoutClone(component.FullName, (Activator.CreateInstance(style) as StyleBase).GetViewStyle()); + var key = targetTheme.ToUpperInvariant(); + + if (!ThemeMap.ContainsKey(key) || ThemeMap[key] == null) + { + Tizen.Log.Error("NUI", "The theme name should be a known one."); + return; + } + + if (Activator.CreateInstance(style) as StyleBase != null) + { + ThemeMap[key].AddStyleWithoutClone(component.FullName, styleBase.GetViewStyle()); + } } } diff --git a/src/Tizen.NUI.Components/res/IoT_Toast_1.png b/src/Tizen.NUI.Components/res/IoT_Toast_1.png deleted file mode 100644 index d923619df58f5fc9b05caf8b34a0aae6465381b3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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^uV`0GZ|t>jV3)R~i?Kl{&HKdhmmf$^yL zq8_&|K;LaMAZPOmtF{HEhrjiea;PBpA^aw=G2^C*1AG2!fIotnmy7Wdw5k2A^=sJj z!pPO6@l?BDNnqLIsYU7A)p%YA#voMs0BDROiis=L+B@09ZnwS_yqM?~ueu@EXvhRi za~-Y#67ITe+E!c`JxwcH-Eg7n_zP78c4MS$db(Y|xvZ>gyr6bWX;uU@uf%a#w4td$HvVg~OZfQd+53;HstANle}$u2Y5!d$VGc_Kl95aA_=Ao_ zUwG)^>euRMfB%vE!sR4VN1$n!gCnHn2r@#8g8tBhrYG;g$(gM`N7?Q*o6EmI+$oMl zfpWVYuizi_zV6l#VTQK#b9kA_n~{;ma>c8xB+~Xcyb$3IqZ7B!v|CJdW)WjoepZ^< zr|O9T%BfqTpz5|ID2`M!xltE?US&45M6%x%idtoe=y(#IcZV#DS2@F;5jT8TkE}Cn zdMTVAjih0)VndA~pR=Gq=6RC!!$T&UFr{r4v?uR01F!m2C(t>Xd0$z<)Z z6Ux^8#}j{-q`by}Wg?bQ6!l@Is&(<5(vzwA9x>90IPulK_hS&UXP)eJX@J@i+%G;f zlvKVJdU^lxT|ykIzSd*plx@Zw>8WindV<%kzA8tedIW~^kU|tEl}O&)&d%`c!zRIedWjR`hl0JbRcvIm@jQ=!NUi`A? z)P^lqUk?ioBL6F+W-4pXl#TEEfq`nOBC_MeqB9n%(r6nEt^B|tM39LyzTQ!tFQ;CZ z-OdGZKEd1<@_su+_EhVwzPH7_o0%dyy6W$9sM)NfEjAWF#6ShMtf7f4ugG4Nb3r2j z_Pice0mO89cpaKWMHQUmwUlzS+3`3sEnS4jA{$fCqx0HyB6pr^QmlK}SW*i_NRdRE z;z)h)*u1*3$>b-G;xPwNcLFWFG$~+-C{8C1YbH77Rc>_s{?fJhV~@qhj9q46U&0Gl z>Zi=MYdVg9nF15e9^t;tV3$tEZe#p&#fN4;@p~Zb4`cY{o(*6|1 z!BP4+MTlN^3sDC}?2G$U**t2SbtGn=4T%4uV*H~Vj-}lA_rFQb2pSa;)@uNESh*Iz zPW?th*kwq3x%}~b!`O{Gr@1fMR_(z8m{=~&{t&U4S$hzd0;{IXnuWzX;`%}h0smQ(3oh<>Y-wvhAdgTr#-PB8p0zTMW*s~Vs?V3C1P-Cv z)ei|qNY~+lP$ZaNkxYiA6e^2@6)%rylKyL1|C2%x9Sw^1!ka^fKxh*<-6kMB8kgas zOyEj+XB#+FGHekPL?n?8ks(8j45Vy84A7u_FZU;mzoIF+n@0m975aK$$}w>mP!RKy zYB4&Iekm&vENmI_dvS2yQlRn(Xe4@XCMbKt5~zW@!~aU~S)%?|f`8NU|4{`4L=Kug zAHtuS)qla)*}da&GNkijmqJcG;Jqd-1((*FV1j$!6_MDlJY5SKjzz6ljBa(40JE*h z2eMk3#nG_%y%&qY#FyBa>Prc4-R|fS7%3sxUE_wibRt$Y6_$MxJJ)ZzzWiE^ZnulT z%p|6Jo9DW{LTCZkJfd;hz{^Gr32CEOX`i8RRy0B?f=wYVkU7e_!egE zdCuJ}o8hR1@U^&)b*7lCZlc_igE&}lDy(Kn=$I{sDfL%|f12v-`Ml z8xMH=@XPo__=rqU&YK!l$;lwa4d7&U~5#`%5&4;P5HK8PHC>cse3!+JMMUcAS9 z>(wZX(Ks>Ie@(UX$99>jNduE>p-$^@t(r-}DX?V^Hw24FM!zME=|%O9)D$n(-k-Yz zDmBu4k8#UY-s%4BHvtWKbb`=PgyPPjodB3~%+Mx`7NjTXDRfmMjnwO1_m0+)s~9)A z9Og5@P4kLoIB2a%M95O=7l+Et&hfHCMjAqVB>)Aubu_L>Z{#OxHi7u`Ezo1b{z#^B zv`w9cV7g9f1^RxS`euz=D6@*go?q9zJwCkKMn-<5IbwdvOrPa+J$RgQKDf7tPLz2v zctGkC#wS8qSV9PSFh|u6t!TH#U>p+wA0MBs-_rqsF*7&KcXqi;6)e=yFJ;f3 z#xC3!6vXV5FZJOei`}Qr;-$(olN3BlC$xhHX$&Duyml(<4 z@I&m@MbdA8M z;qD|NA1^yCPPp4wBu0Xp9ugg%a7h4is5UCivp;Yz8lgI41ZNlS9KW=)r5BJHw219T(BhEImO_YH^-hU zpW&uTy7m>B`fa9Z6>cjT7#KX>uNnLH0!VwICFWQx9}h#s1&s0?cjlM#Xqa5}hfws8&}jf+z{>h6Xt)h0d7)Wd%YC)_IibUan{JS7s& zRxmKI46J25SM%KB8yFf!X&Q%zfW6ESt3+XEoSqh*ITU6YsYC`bXyIe^+$c)@4K_Z$ zHLSfk2wrhpyXep%U3$f@Rp|$XyT7LnJrXT$VYpKbMoi~8Ig%o>lv;hPtGfY?IK;5d zV3fULxT;IvAFBY{+gnHP;dvc_K~L4LxVd?k5{NR@E5a^Q=i-k$hYE=jGAroA9`a

-6S-of6^{08f=rDI5_h3erfTIOkawF{ zlxp`C$HD2?AA2sXUf6e~{gYdq@g^SjgafE6YobVt;NO+%! z^Nn-CcXG+}ZfTFNdL16(G?Ny?{;rd@hnkmZH}wEyM<9(A|F&{KJ1in<6nQ?J2GODE z$PwJURXq*Mh#>QvZ0-ex^GcIh3@*H~feGw9XIZ$%g|BbNY_1fT&_bob2Lr2i8om}o z?shl<$yUo>Cv+~t_L^$0w3`@_c5qnz@1&iWkj*_Ux$xUy+uc)^zux3%jmrGxWB+8s kI|ZTfHUK||=x|zHPB_!uvI7qY&jLm4tuI+sT|nOc7v4B}JOBUy diff --git a/src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Common.xaml b/src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Common.xaml deleted file mode 100755 index 76ca878..0000000 --- a/src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Common.xaml +++ /dev/null @@ -1,172 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {NUIResourcePath nui_component_default_popup_shadow.png} - 24, 24, 24, 24 - 0, 0 - 48, 48 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Wearable.xaml b/src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Wearable.xaml deleted file mode 100755 index 8acbf18..0000000 --- a/src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Wearable.xaml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Tizen.NUI.Wearable/res/Theme/Tizen.NUI.Wearable_Tizen.NUI.Theme.Common.xaml b/src/Tizen.NUI.Wearable/res/Theme/Tizen.NUI.Wearable_Tizen.NUI.Theme.Common.xaml deleted file mode 100644 index bf14f12..0000000 --- a/src/Tizen.NUI.Wearable/res/Theme/Tizen.NUI.Wearable_Tizen.NUI.Theme.Common.xaml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Tizen.NUI.Wearable/src/internal/Theme/DefaultTheme.cs b/src/Tizen.NUI.Wearable/src/internal/Theme/DefaultTheme.cs index a072a02..3ca7083 100644 --- a/src/Tizen.NUI.Wearable/src/internal/Theme/DefaultTheme.cs +++ b/src/Tizen.NUI.Wearable/src/internal/Theme/DefaultTheme.cs @@ -81,7 +81,5 @@ namespace Tizen.NUI.Wearable return theme; } - - public HashSet GetExternalThemeKeyListSet() => null; } } diff --git a/src/Tizen.NUI/res/Theme/Tizen.NUI_Tizen.NUI.Theme.Common.xaml b/src/Tizen.NUI/res/Theme/Tizen.NUI_Tizen.NUI.Theme.Common.xaml deleted file mode 100644 index 96c19cd..0000000 --- a/src/Tizen.NUI/res/Theme/Tizen.NUI_Tizen.NUI.Theme.Common.xaml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/src/Tizen.NUI/res/Theme/Tizen.NUI_Tizen.NUI.Theme.Wearable.xaml b/src/Tizen.NUI/res/Theme/Tizen.NUI_Tizen.NUI.Theme.Wearable.xaml deleted file mode 100644 index cc5dd43..0000000 --- a/src/Tizen.NUI/res/Theme/Tizen.NUI_Tizen.NUI.Theme.Wearable.xaml +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Application/NUIApplication.cs b/src/Tizen.NUI/src/public/Application/NUIApplication.cs index 03c3311..848511b 100755 --- a/src/Tizen.NUI/src/public/Application/NUIApplication.cs +++ b/src/Tizen.NUI/src/public/Application/NUIApplication.cs @@ -50,7 +50,6 @@ namespace Tizen.NUI [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")] public NUIApplication() : base(new NUICoreBackend()) { - ExternalThemeManager.Initialize(); } ///

@@ -64,7 +63,6 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition)) { - ExternalThemeManager.Initialize(); } /// @@ -75,7 +73,6 @@ namespace Tizen.NUI [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")] public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet)) { - ExternalThemeManager.Initialize(); } /// @@ -90,7 +87,6 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, WindowMode.Opaque, windowSize, windowPosition)) { - ExternalThemeManager.Initialize(); } /// @@ -102,7 +98,6 @@ namespace Tizen.NUI [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")] public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode)) { - ExternalThemeManager.Initialize(); } /// @@ -118,7 +113,6 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition)) { - ExternalThemeManager.Initialize(); } /// @@ -137,7 +131,30 @@ namespace Tizen.NUI //windowMode and styleSheet will be added later. currently it's not working as expected. Graphics.Backend = backend; Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!"); - ExternalThemeManager.Initialize(); + } + + /// + /// The constructor with theme option. + /// + /// The theme option. + [EditorBrowsable(EditorBrowsableState.Never)] + [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")] + public NUIApplication(ThemeOptions option) : base(new NUICoreBackend()) + { + ApplyThemeOption(option); + } + + /// + /// The constructor with window size and position and theme option. + /// + /// The window size. + /// The window position. + /// The theme option. + [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")] + [EditorBrowsable(EditorBrowsableState.Never)] + public NUIApplication(Size2D windowSize, Position2D windowPosition, ThemeOptions option) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition)) + { + ApplyThemeOption(option); } /// @@ -171,6 +188,34 @@ namespace Tizen.NUI } /// + /// Enumeration for theme options of the NUIApplication. + /// + [Flags] + [EditorBrowsable(EditorBrowsableState.Never)] + public enum ThemeOptions : int + { + /// + /// No option specified. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + None = 0, + + /// + /// Enable platform theme. + /// When this option is on, all views in the NUIApplication is affected by platform theme (e.g. light/dark). + /// + [EditorBrowsable(EditorBrowsableState.Never)] + PlatformThemeEnabled = 1 << 0, + + /// + /// Sets the default value of View.ThemeChangeSensitive. + /// when this option is on, all views are made sensitive on theme changing by default. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + ThemeChangeSensitive = 1 << 1, + }; + + /// /// ResourceManager to handle multilingual. /// /// 4 @@ -395,7 +440,7 @@ namespace Tizen.NUI static public void Preload() { Interop.Application.PreInitialize(); - ThemeManager.AddPackageTheme(DefaultThemeCreator.Instance); + ThemeManager.Preload(); IsPreload = true; } @@ -418,6 +463,19 @@ namespace Tizen.NUI /// Check if it is loaded as dotnet-loader-nui. /// static internal bool IsPreload { get; set; } + + private void ApplyThemeOption(ThemeOptions option) + { + if ((option & ThemeOptions.PlatformThemeEnabled) != 0) + { + ThemeManager.PlatformThemeEnabled = true; + } + + if ((option & ThemeOptions.ThemeChangeSensitive) != 0) + { + ThemeManager.ApplicationThemeChangeSensitive = true; + } + } } /// diff --git a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs index 4a8986f..84bf967 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyle.cs @@ -77,6 +77,13 @@ namespace Tizen.NUI.BaseComponents } /// + /// The flag that is used when creating a component with this style. + /// If the value is true, it will include default component style defined in the default theme. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IncludeDefaultStyle { get; set; } = false; + + /// /// Gets or sets the image resource url of the background of view. /// The mutually exclusive with "BackgroundColor". Setting it overwrites existing "BackgroundColor". /// @@ -538,6 +545,8 @@ namespace Tizen.NUI.BaseComponents SetValue(destinationProperty, sourceValue); } } + + IncludeDefaultStyle = source.IncludeDefaultStyle; } /// diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 7e12bc6..72a36ad 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -48,15 +48,6 @@ namespace Tizen.NUI.BaseComponents private TransitionOptions transitionOptions = null; private ThemeData themeData; - internal class ThemeData - { - public bool controlStatePropagation = false; - public ViewStyle viewStyle; - public bool themeChangeSensitive = false; - public ControlState controlStates = ControlState.Normal; - public ViewSelectorData selectorData; - } - static View() { RegisterPropertyGroup(PositionProperty, positionPropertyGroup); @@ -176,6 +167,7 @@ namespace Tizen.NUI.BaseComponents public static bool LayoutingDisabled { get; set; } = true; /// + /// Deprecate. Please do not use this. /// The style instance applied to this view. /// Note that please do not modify the ViewStyle. /// Modifying ViewStyle will affect other views with same ViewStyle. @@ -225,7 +217,7 @@ namespace Tizen.NUI.BaseComponents ControlStateChangeEventInternal?.Invoke(this, changeInfo); - if (themeData.controlStatePropagation) + if (themeData.ControlStatePropagation) { foreach (View child in Children) { @@ -2507,14 +2499,14 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public bool EnableControlStatePropagation { - get => themeData?.controlStatePropagation ?? false; + get => themeData?.ControlStatePropagation ?? false; set { if (EnableControlStatePropagation == value) return; if (themeData == null) themeData = new ThemeData(); - themeData.controlStatePropagation = value; + themeData.ControlStatePropagation = value; foreach (View child in Children) { @@ -2591,7 +2583,7 @@ namespace Tizen.NUI.BaseComponents /// /// If the value is true, the View will change its style as the theme changes. - /// It is false by default, but turned to true when setting StyleName (by setting property or using specified constructor). + /// The default value is false in normal case but it can be true when the NUIApplication is created with . /// /// 9 public bool ThemeChangeSensitive @@ -2623,7 +2615,8 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] protected virtual void OnThemeChanged(object sender, ThemeChangedEventArgs e) { - UpdateStyle(); + if (string.IsNullOrEmpty(styleName)) ApplyStyle(ThemeManager.GetUpdateStyleWithoutClone(GetType())); + else ApplyStyle(ThemeManager.GetUpdateStyleWithoutClone(styleName)); } /// diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs index 5fb6d1d..de59832 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs @@ -39,8 +39,15 @@ namespace Tizen.NUI.BaseComponents Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)view.SwigCPtr, View.Property.StyleName, new Tizen.NUI.PropertyValue(styleName)); view.styleName = styleName; - view.UpdateStyle(); - view.ThemeChangeSensitive = true; + + if (string.IsNullOrEmpty(styleName)) return; + + var style = ThemeManager.GetUpdateStyleWithoutClone(styleName); + + if (style == null) return; + + view.ApplyStyle(style); + view.SetThemeApplied(); } }), defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) => @@ -1676,20 +1683,24 @@ namespace Tizen.NUI.BaseComponents if (view.themeData == null) view.themeData = new ThemeData(); - view.themeData.themeChangeSensitive = (bool)newValue; + view.themeData.ThemeChangeSensitive = (bool)newValue; + + if (!view.themeData.ThemeApplied) return; - if (view.themeData.themeChangeSensitive) + if (view.themeData.ThemeChangeSensitive && !view.themeData.ListeningThemeChangeEvent) { + view.themeData.ListeningThemeChangeEvent = true; ThemeManager.ThemeChangedInternal.Add(view.OnThemeChanged); } - else + else if (!view.themeData.ThemeChangeSensitive && view.themeData.ListeningThemeChangeEvent) { + view.themeData.ListeningThemeChangeEvent = false; ThemeManager.ThemeChangedInternal.Remove(view.OnThemeChanged); } }, defaultValueCreator: (bindable) => { - return ((View)bindable).themeData?.themeChangeSensitive ?? false; + return ((View)bindable).themeData?.ThemeChangeSensitive ?? ThemeManager.ApplicationThemeChangeSensitive; }); /// diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index a51b48b..db50bf5 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Runtime.CompilerServices; namespace Tizen.NUI.BaseComponents @@ -30,6 +31,56 @@ namespace Tizen.NUI.BaseComponents { internal string styleName; + internal class ThemeData + { + [Flags] + private enum States : byte + { + None = 0, + ControlStatePropagation = 1 << 0, + ThemeChangeSensitive = 1 << 1, + ThemeApplied = 1 << 2, // It is true when the view has valid style name or the platform theme has a component style for this view type. + // That indicates the view can have different styles by theme. + // Hence if the current state has ThemeApplied and ThemeChangeSensitive, the view will change its style by theme changing. + ListeningThemeChangeEvent = 1 << 3, + }; + + private States states = ThemeManager.ApplicationThemeChangeSensitive ? States.ThemeChangeSensitive : States.None; + public ViewStyle viewStyle; + public ControlState controlStates = ControlState.Normal; + public ViewSelectorData selectorData; + + public bool ControlStatePropagation + { + get => ((states & States.ControlStatePropagation) != 0); + set => SetOption(States.ControlStatePropagation, value); + } + + public bool ThemeChangeSensitive + { + get => ((states & States.ThemeChangeSensitive) != 0); + set => SetOption(States.ThemeChangeSensitive, value); + } + + public bool ThemeApplied + { + get => ((states & States.ThemeApplied) != 0); + set => SetOption(States.ThemeApplied, value); + } + + public bool ListeningThemeChangeEvent + { + get => ((states & States.ListeningThemeChangeEvent) != 0); + set => SetOption(States.ListeningThemeChangeEvent, value); + } + + private void SetOption(States option, bool value) + { + if (value) states |= option; + else states &= ~option; + } + } + /// /// The color mode of View. /// This specifies whether the View uses its own color, or inherits its parent color. @@ -1115,6 +1166,18 @@ namespace Tizen.NUI.BaseComponents return value == null ? null : new Selector(value); } + internal void SetThemeApplied() + { + if (themeData == null) themeData = new ThemeData(); + themeData.ThemeApplied = true; + + if (ThemeChangeSensitive && !themeData.ListeningThemeChangeEvent) + { + themeData.ListeningThemeChangeEvent = true; + ThemeManager.ThemeChangedInternal.Add(OnThemeChanged); + } + } + /// /// you can override it to clean-up your own resources. /// @@ -1134,10 +1197,13 @@ namespace Tizen.NUI.BaseComponents //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. - themeData?.selectorData?.Reset(this); - if (ThemeChangeSensitive) + if (themeData != null) { - ThemeManager.ThemeChangedInternal.Remove(OnThemeChanged); + themeData.selectorData?.Reset(this); + if (themeData.ListeningThemeChangeEvent) + { + ThemeManager.ThemeChangedInternal.Remove(OnThemeChanged); + } } } @@ -1317,10 +1383,23 @@ namespace Tizen.NUI.BaseComponents /// Apply initial style to the view. /// [EditorBrowsable(EditorBrowsableState.Never)] - protected void InitializeStyle(ViewStyle style = null) + protected virtual void InitializeStyle(ViewStyle style = null) { - if (style != null) ApplyStyle(style); // Use given style - else UpdateStyle(); // Use style in the current theme + // First, apply initial style if needs. + var initialStyle = ThemeManager.GetInitialStyleWithoutClone(GetType()); + if (style == null || style.IncludeDefaultStyle) + { + ApplyStyle(initialStyle); + } + + // Then, apply given style. + ApplyStyle(style); + + // Listen theme change event if needs. + if (ThemeManager.PlatformThemeEnabled && initialStyle != null) + { + SetThemeApplied(); + } } private View ConvertIdToView(uint id) @@ -1400,18 +1479,6 @@ namespace Tizen.NUI.BaseComponents return false; } - private void UpdateStyle() - { - ViewStyle newStyle; - if (string.IsNullOrEmpty(styleName)) newStyle = ThemeManager.GetStyleWithoutClone(GetType()); - else newStyle = ThemeManager.GetStyleWithoutClone(styleName); - - if (newStyle != null) - { - ApplyStyle(newStyle); - } - } - private ViewSelectorData EnsureSelectorData() { if (themeData == null) themeData = new ThemeData(); diff --git a/src/Tizen.NUI/src/public/Theme/DefaultTheme.cs b/src/Tizen.NUI/src/public/Theme/DefaultTheme.cs index c01168e..dca88a0 100644 --- a/src/Tizen.NUI/src/public/Theme/DefaultTheme.cs +++ b/src/Tizen.NUI/src/public/Theme/DefaultTheme.cs @@ -27,8 +27,6 @@ namespace Tizen.NUI internal const string DefaultVersion = "1.0.0"; internal static IThemeCreator Instance { get; set; } = new DefaultThemeCreator(); - - public HashSet GetExternalThemeKeyListSet() => null; } } diff --git a/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs b/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs index 1981ba2..0cff955 100644 --- a/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs +++ b/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs @@ -23,6 +23,9 @@ namespace Tizen.NUI { internal partial class DefaultThemeCreator { + /// + /// The base theme description. + /// [SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope", Justification = "The responsibility to dispose the object is transferred to the theme object.")] public Theme Create() { @@ -79,4 +82,5 @@ namespace Tizen.NUI } } } -#endif + +#endif // !PROFILE_TV diff --git a/src/Tizen.NUI/src/public/Theme/DictionaryExternalTheme.cs b/src/Tizen.NUI/src/public/Theme/DictionaryExternalTheme.cs deleted file mode 100644 index 886540f..0000000 --- a/src/Tizen.NUI/src/public/Theme/DictionaryExternalTheme.cs +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#if DEBUG - -using System.Collections.Generic; - -namespace Tizen.NUI -{ - /// - /// This is a helper class to test external theme applying. - /// - internal class DictionaryExternalTheme : IExternalTheme - { - private readonly Dictionary theme; - - public DictionaryExternalTheme(string id, string version, Dictionary theme) - { - Id = id; - Version = version; - this.theme = theme; - } - - public string Id { get; } - - public string Version { get; } - - public string GetValue(string key) - { - theme.TryGetValue(key, out string extracted); - - return extracted; - } - } -} -#endif diff --git a/src/Tizen.NUI/src/public/Theme/ExternalThemeKeyList.cs b/src/Tizen.NUI/src/public/Theme/ExternalThemeKeyList.cs deleted file mode 100755 index ab3b37d..0000000 --- a/src/Tizen.NUI/src/public/Theme/ExternalThemeKeyList.cs +++ /dev/null @@ -1,288 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Reflection; -using Tizen.NUI.BaseComponents; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI -{ - /// - /// This class holds a list of string key and corresponding setter function. - /// - /// Key - /// Represents a specific property in a style, for example, - /// the key "/Text/PixelSize" of styleType "Button" means "ButtonStyle.Text.PixelSize". - /// - /// - /// Action - /// One action takes two values, - /// * viewStyle : A style instance in a theme. - /// * value: A string value that will overwrite a property value in a given viewStyle. - /// The action parses a given string value into a typed object and set it to the viewStyle. - /// - /// - internal class ExternalThemeKeyList - { - private Type componentType; - private Type styleType; - private object selectorData; - private List list = new List(); - - /// - /// Create a new key list - /// For example, - /// - /// new ExternalThemeKeyList(typeof(Button), typeof(ButtonStyle)); - /// - /// This means that the keys are related with ButtonStyle and they are defined to decorate Button component. - /// - internal ExternalThemeKeyList(Type componentType, Type styleType) - { - this.componentType = componentType; - this.styleType = styleType; - } - - /// - /// Add a key with a corresponding action. - /// For example, - /// - /// var keyList = new ExternalThemeKeyList(typeof(Button), typeof(ButtonStyle)); - /// keyList.Add<Extents>("/Margin", (ViewStyle style, Extents value) => viewStyle.Margin = value); - /// - /// - internal ExternalThemeKeyList Add(string key, Action setter) - { - list.Add(new KeyActionPair(componentType.Name + key, (ViewStyle viewStyle, string stringInput) => - { - if (ParseXamlStringToObject(stringInput) is T tValue) - { - if (tValue != null) - { - setter(viewStyle, tValue); - } - } - })); - return this; - } - - /// - /// - /// The series of actions for a selector. - /// T is a content type of a selector. - /// For example, assume that the component type is "Progress", - /// - /// AddSelector<Color>("/TrackColor", setter); - /// - /// This will produce additional keys and actions for 5 basic ControlStates, - /// "Progress/TrackColor" - /// "Progress/TrackColorFocused" - /// "Progress/TrackColorPressed" - /// "Progress/TrackColorDisabled" - /// "Progress/TrackColorOther" - /// - /// - /// Note that if you want to add actions for additional control states, please specify them as parameter. - /// - /// - /// - /// AddSelector<Color>("/TrackColor", setter, ControlState.DisabledSelected); - /// - internal ExternalThemeKeyList AddSelector(string key, Action> setter, params ControlState[] additionalStates) - { - list.Add(new KeyActionPair(componentType.Name + key, GenSelectorAction(ControlState.Normal))); - list.Add(new KeyActionPair(componentType.Name + key + nameof(ControlState.Focused), GenSelectorAction(ControlState.Focused))); - list.Add(new KeyActionPair(componentType.Name + key + nameof(ControlState.Pressed), GenSelectorAction(ControlState.Pressed))); - list.Add(new KeyActionPair(componentType.Name + key + nameof(ControlState.Disabled), GenSelectorAction(ControlState.Disabled))); - list.Add(new KeyActionPair(componentType.Name + key + nameof(ControlState.Other), GenSelectorAction(ControlState.Other))); - - foreach (var state in additionalStates) - { - list.Add(new KeyActionPair(componentType.Name + key + nameof(state), GenSelectorAction(state))); - } - - list.Add(new KeyActionPair(GenSelectorFinalizer(setter))); - - return this; - } - - /// - /// Note that, the view's background can be either color or image value. - /// This method add keys for a selector and each action can handle both color and string (for image url). - /// - internal ExternalThemeKeyList AddBackgroundSelector(string key, Action> colorSetter, Action> imageSetter, params ControlState[] additionalStates) - { - list.Add(new KeyActionPair(componentType.Name + key, GenBackgroundSelectorAction(ControlState.Normal))); - list.Add(new KeyActionPair(componentType.Name + key + nameof(ControlState.Focused), GenBackgroundSelectorAction(ControlState.Focused))); - list.Add(new KeyActionPair(componentType.Name + key + nameof(ControlState.Pressed), GenBackgroundSelectorAction(ControlState.Pressed))); - list.Add(new KeyActionPair(componentType.Name + key + nameof(ControlState.Disabled), GenBackgroundSelectorAction(ControlState.Disabled))); - list.Add(new KeyActionPair(componentType.Name + key + nameof(ControlState.Other), GenBackgroundSelectorAction(ControlState.Other))); - - foreach (var state in additionalStates) - { - list.Add(new KeyActionPair(componentType.Name + key + nameof(state), GenBackgroundSelectorAction(state))); - } - - list.Add(new KeyActionPair(GenColorOrImageSelectorFinalizer(colorSetter, imageSetter))); - - return this; - } - - internal void ApplyKeyActions(IExternalTheme externalTheme, Theme theme) - { - var style = theme.GetStyle(componentType.FullName); - - foreach (var item in list) - { - if (item.IsFinalizer) - { - item.Action(style, null); - continue; - } - - string newValue = externalTheme.GetValue(item.Key); - if (newValue != null) - { - if (style == null || style.GetType() != styleType) - { - style = Activator.CreateInstance(styleType) as ViewStyle; - theme.AddStyleWithoutClone(componentType.FullName, style); - } - - // Invoke action with the existing style to overwrite properties of it. - item.Action(style, newValue); - } - } - } - - private Action GenSelectorAction(ControlState state) - { - return (ViewStyle viewStyle, string stringInput) => - { - if (ParseXamlStringToObject(stringInput) is T tValue) - { - if (selectorData == null) - { - selectorData = new Selector(); - } - ((Selector)selectorData).AddWithoutDuplicationCheck(state, tValue); - } - }; - } - - private Action GenBackgroundSelectorAction(ControlState state) - { - return (ViewStyle viewStyle, string stringInput) => - { - var imageUrl = TryConvertToResourcePath(stringInput); - - if (imageUrl != null) - { - if (selectorData == null || (selectorData as Selector == null)) - { - selectorData = new Selector(); - } - ((Selector)selectorData).AddWithoutDuplicationCheck(state, imageUrl); - } - else if (ParseXamlStringToObject(stringInput) is Color color) - { - if (selectorData == null || (selectorData as Selector == null)) - { - selectorData = new Selector(); - } - ((Selector)selectorData).AddWithoutDuplicationCheck(state, color); - } - }; - } - - private Action GenSelectorFinalizer(Action> setter) - { - return (ViewStyle viewStyle, string value) => - { - if (selectorData == null || viewStyle == null) - { - return; - } - setter(viewStyle, (Selector)selectorData); - selectorData = null; - }; - } - - private Action GenColorOrImageSelectorFinalizer(Action> colorSetter, Action> imageSetter) - { - return (ViewStyle viewStyle, string value) => - { - if (viewStyle == null) - { - return; - } - if (selectorData is Selector colorSelector) - { - colorSetter(viewStyle, colorSelector); - } - else if (selectorData is Selector imageSelector) - { - imageSetter(viewStyle, imageSelector); - } - selectorData = null; - }; - } - - private static object ParseXamlStringToObject(string stringInput) - { - if (typeof(T) == typeof(string)) - { - return TryConvertToResourcePath(stringInput) ?? stringInput; - } - return stringInput.ConvertTo(typeof(T), () => typeof(T).GetTypeInfo(), null); - } - - private static string TryConvertToResourcePath(string stringInput) - { - Debug.Assert(stringInput != null); - if (stringInput.StartsWith("{") && stringInput.EndsWith("}")) - { - // TODO Need to use Tizen.Applications.ThemeManager.Theme.GetPath instead SharedResourcePath after fixing abort problem. - return ExternalThemeManager.SharedResourcePath + "/" + stringInput.Substring(1, stringInput.Length - 2); - } - return null; - } - - internal struct KeyActionPair - { - public KeyActionPair(string key, Action action) - { - Key = key; - Action = action; - } - - public KeyActionPair(Action action) - { - Key = null; - Action = action; - } - - public bool IsFinalizer => (Key == null); - - public string Key { get; } - - public Action Action { get; } - } - } -} diff --git a/src/Tizen.NUI/src/public/Theme/ExternalThemeManager.cs b/src/Tizen.NUI/src/public/Theme/ExternalThemeManager.cs index 760f2ab..02d6538 100755 --- a/src/Tizen.NUI/src/public/Theme/ExternalThemeManager.cs +++ b/src/Tizen.NUI/src/public/Theme/ExternalThemeManager.cs @@ -16,8 +16,8 @@ */ using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.IO; using Tizen.Applications; namespace Tizen.NUI @@ -25,195 +25,135 @@ namespace Tizen.NUI [SuppressMessage("Microsoft.Design", "CA1031: Do not catch general exception types", Justification = "This method is to handle external resources that may throw an exception but ignorable. This method should not interrupt the main stream.")] internal static class ExternalThemeManager { - private static Tizen.Applications.ThemeManager.ThemeLoader themeLoader = InitializeThemeLoader(); + private static Tizen.Applications.ThemeManager.ThemeLoader themeLoader; + private static string id; + private static string version; - private static string sharedResourcePath; -#if DEBUG - private static IExternalTheme theme; -#endif static ExternalThemeManager() { } - public static string SharedResourcePath + public static void Initialize() { - get + if (themeLoader != null) { - if (themeLoader == null) - { - return string.Empty; - } -#if DEBUG - if (theme != null) - { - return string.Empty; - } -#endif - if (sharedResourcePath != null) - { - return sharedResourcePath; - } - - var tizenTheme = themeLoader.CurrentTheme; - - if (tizenTheme == null || string.IsNullOrEmpty(tizenTheme.Id) || string.IsNullOrEmpty(tizenTheme.Version)) - { - sharedResourcePath = string.Empty; - } - else - { - ApplicationInfo themePkgInfo; - try - { - themePkgInfo = ApplicationManager.GetInstalledApplication(tizenTheme.Id); - } - catch (ArgumentException e) - { - Tizen.Log.Error("NUI", $"{e.GetType().Name} occurred while getting theme application info."); - throw; - } - catch (InvalidOperationException e) - { - Tizen.Log.Error("NUI", $"{e.GetType().Name} occurred while getting theme application info."); - throw; - } - - if (themePkgInfo == null) - { - sharedResourcePath = string.Empty; - } - else - { - sharedResourcePath = themePkgInfo.SharedResourcePath; - } - } + return; + } - return sharedResourcePath; + try + { + themeLoader = new Tizen.Applications.ThemeManager.ThemeLoader(); + themeLoader.ThemeChanged += OnExternalPlatformThemeChanged; + } + catch (Exception e) + { + Tizen.Log.Info("NUI", $"[Ignorable] {e.GetType().Name} occurred while setting Tizen.Applications.ThemeManager: {e.Message}"); } } - public static void Initialize() + + /// Returns the theme's shared resource path that is currently loading. + public static string SharedResourcePath { get; set; } = String.Empty; + + // FIXME Please remove this API after fix ThemeLoader.CurrentTheme is fixed. + public static string CurrentThemeId { - if (themeLoader == null) + get { - return; + if (id == null) UpdateCurrentThemeIdAndVersion(); + return id; } - - themeLoader.ThemeChanged += OnTizenThemeChanged; } - public static IExternalTheme GetCurrentTheme() + // FIXME Please remove this API after fix ThemeLoader.CurrentTheme is fixed. + public static string CurrentThemeVersion { - if (themeLoader == null) + get { - return null; + if (version == null) UpdateCurrentThemeIdAndVersion(); + return version; } + } -#if DEBUG - if (theme != null) + public static bool SetTheme(string id) + { + if (themeLoader != null) { - return theme; + try + { + themeLoader.CurrentTheme = themeLoader.LoadTheme(id); + return true; + } + catch (Exception e) + { + Tizen.Log.Info("NUI", $"[Ignorable] {e.GetType().Name} occurred while getting load theme using {themeLoader.GetType().FullName}: {e.Message}"); + } } -#endif - Tizen.Applications.ThemeManager.Theme tizenTheme = null; - try - { - tizenTheme = themeLoader.CurrentTheme; - } - catch (Exception e) - { - Tizen.Log.Info("NUI", $"[Ignorable] {e.GetType().Name} occurred while getting current theme using {themeLoader.GetType().FullName}: {e.Message}"); - } + return false; + } - if (tizenTheme == null || string.IsNullOrEmpty(tizenTheme.Id) || string.IsNullOrEmpty(tizenTheme.Version)) + public static string GetSharedResourcePath(string id) + { + if (!string.IsNullOrEmpty(id)) { - return null; + try + { + using (var themePkgInfo = ApplicationManager.GetInstalledApplication(id)) + { + return themePkgInfo.SharedResourcePath; + } + } + catch (ArgumentException e) + { + Tizen.Log.Error("NUI", $"{e.GetType().Name} occurred while getting theme application info."); + } + catch (InvalidOperationException e) + { + Tizen.Log.Error("NUI", $"{e.GetType().Name} occurred while getting theme application info."); + } } - Tizen.Log.Info("NUI", $"TizenTheme: Id({tizenTheme.Id}), Version({tizenTheme.Version}), Title({tizenTheme.Title})"); - - return new TizenExternalTheme(tizenTheme); + return null; } - public static IExternalTheme GetTheme(string id) + private static void UpdateCurrentThemeIdAndVersion() { if (themeLoader == null) { - return null; + return; } Tizen.Applications.ThemeManager.Theme tizenTheme = null; try { - tizenTheme = themeLoader.LoadTheme(id); + tizenTheme = themeLoader.CurrentTheme; } catch (Exception e) { - Tizen.Log.Info("NUI", $"[Ignorable] {e.GetType().Name} occurred while getting load theme using {themeLoader.GetType().FullName}: {e.Message}"); - } - - return tizenTheme == null ? null : new TizenExternalTheme(tizenTheme); - } - -#if DEBUG - public static void SetTestTheme(IExternalTheme testTheme) - { - if (testTheme == null) - { - throw new ArgumentNullException(nameof(testTheme)); + Tizen.Log.Info("NUI", $"[Ignorable] {e.GetType().Name} occurred while getting current theme using {themeLoader.GetType().FullName}: {e.Message}"); } - if (string.IsNullOrEmpty(testTheme.Id) || string.IsNullOrEmpty(testTheme.Version)) + if (tizenTheme == null || string.IsNullOrEmpty(tizenTheme.Id) || string.IsNullOrEmpty(tizenTheme.Version)) { - throw new ArgumentException(); + return; } - theme = testTheme; - ThemeManager.ApplyExternalTheme(theme); - } - - public static void SetTestTheme(string id, string version, Dictionary testData) - { - if (id == null) - { - throw new ArgumentNullException(nameof(id)); - } - if (version == null) - { - throw new ArgumentNullException(nameof(version)); - } - if (testData == null) - { - throw new ArgumentNullException(nameof(testData)); - } + Tizen.Log.Info("NUI", $"TizenTheme: Id({tizenTheme.Id}), Version({tizenTheme.Version}), Title({tizenTheme.Title})"); - theme = new DictionaryExternalTheme(id, version, testData); - ThemeManager.ApplyExternalTheme(theme); + id = tizenTheme.Id; + version = tizenTheme.Version; } -#endif - private static void OnTizenThemeChanged(object sender, Tizen.Applications.ThemeManager.ThemeEventArgs e) + private static void OnExternalPlatformThemeChanged(object sender, Tizen.Applications.ThemeManager.ThemeEventArgs e) { -#if DEBUG - theme = null; -#endif Tizen.Log.Info("NUI", $"TizenTheme: Id({e.Theme.Id}), Version({e.Theme.Version}), Title({e.Theme.Title})"); - sharedResourcePath = null; - ThemeManager.ApplyExternalTheme(new TizenExternalTheme(e.Theme)); - } - private static Tizen.Applications.ThemeManager.ThemeLoader InitializeThemeLoader() - { - try - { - return new Tizen.Applications.ThemeManager.ThemeLoader(); - } - catch (Exception e) - { - Tizen.Log.Info("NUI", $"[Ignorable] {e.GetType().Name} occurred while setting Tizen.Applications.ThemeManager: {e.Message}"); - } + id = e.Theme.Id; + version = e.Theme.Version; - return null; + if (!ThemeManager.PlatformThemeEnabled) return; + + ThemeManager.ApplyExternalPlatformTheme(id, version); } } } diff --git a/src/Tizen.NUI/src/public/Theme/IExternalTheme.cs b/src/Tizen.NUI/src/public/Theme/IExternalTheme.cs deleted file mode 100644 index cb75be4..0000000 --- a/src/Tizen.NUI/src/public/Theme/IExternalTheme.cs +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -namespace Tizen.NUI -{ - /// - /// This is a wrapper to express external theme, such as, tizen-theme-manager's theme. - /// - internal interface IExternalTheme - { - string Id { get; } - string Version { get; } - string GetValue(string key); - } -} diff --git a/src/Tizen.NUI/src/public/Theme/IThemeCreator.cs b/src/Tizen.NUI/src/public/Theme/IThemeCreator.cs index 9f8cfb9..22dcc5c 100644 --- a/src/Tizen.NUI/src/public/Theme/IThemeCreator.cs +++ b/src/Tizen.NUI/src/public/Theme/IThemeCreator.cs @@ -15,13 +15,10 @@ * */ -using System.Collections.Generic; - namespace Tizen.NUI { internal interface IThemeCreator { Theme Create(); - HashSet GetExternalThemeKeyListSet(); } } diff --git a/src/Tizen.NUI/src/public/Theme/Theme.cs b/src/Tizen.NUI/src/public/Theme/Theme.cs index 2acfe74..36d7ade 100755 --- a/src/Tizen.NUI/src/public/Theme/Theme.cs +++ b/src/Tizen.NUI/src/public/Theme/Theme.cs @@ -121,7 +121,7 @@ namespace Tizen.NUI if (string.IsNullOrEmpty(baseTheme)) return; - var baseThemeInstance = (Theme)ThemeManager.GetBuiltinTheme(baseTheme)?.Clone(); + var baseThemeInstance = (Theme)ThemeManager.LoadPlatformTheme(baseTheme)?.Clone(); if (baseThemeInstance != null) { @@ -320,6 +320,8 @@ namespace Tizen.NUI if (Id == null) Id = theme.Id; + if (Version == null) Version = theme.Version; + foreach (var item in theme) { if (item.Value == null) @@ -382,32 +384,7 @@ namespace Tizen.NUI /// internal void AddStyleWithoutClone(string styleName, ViewStyle value) => map[styleName] = value; - internal void ApplyExternalTheme(IExternalTheme externalTheme, HashSet keyListSet) - { - Id = externalTheme.Id; - Version = externalTheme.Version; - - if (keyListSet == null) - { - // Nothing to apply - return; - } - - foreach (var keyList in keyListSet) - { - keyList?.ApplyKeyActions(externalTheme, this); - } - } - - internal bool HasSameIdAndVersion(IExternalTheme externalTheme) - { - if (externalTheme == null) - { - return false; - } - - return string.Equals(Id, externalTheme.Id, StringComparison.OrdinalIgnoreCase) && string.Equals(Version, externalTheme.Version, StringComparison.OrdinalIgnoreCase); - } + internal bool HasSameIdAndVersion(string id, string version) => string.Equals(Id, id, StringComparison.OrdinalIgnoreCase) && string.Equals(Version, version, StringComparison.OrdinalIgnoreCase); internal void SetChangedResources(IEnumerable> changedResources) { diff --git a/src/Tizen.NUI/src/public/Theme/ThemeChangedEventArgs.cs b/src/Tizen.NUI/src/public/Theme/ThemeChangedEventArgs.cs index 31d9239..368c22d 100755 --- a/src/Tizen.NUI/src/public/Theme/ThemeChangedEventArgs.cs +++ b/src/Tizen.NUI/src/public/Theme/ThemeChangedEventArgs.cs @@ -28,15 +28,30 @@ namespace Tizen.NUI /// /// [EditorBrowsable(EditorBrowsableState.Never)] - public ThemeChangedEventArgs(string themeId) + public ThemeChangedEventArgs(string themeId, string platformThemeId, bool isPlatformThemeChanged) { ThemeId = themeId; + PlatformThemeId = platformThemeId; + IsPlatformThemeChanged = isPlatformThemeChanged; } /// - /// The new theme's ID. + /// The new theme's Id. /// /// 9 public string ThemeId { get; } + + /// + /// The platform theme's Id. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string PlatformThemeId { get; } + + /// + /// Whether this event is trigger by platform theme change. + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsPlatformThemeChanged { get; } } } diff --git a/src/Tizen.NUI/src/public/Theme/ThemeDark.cs b/src/Tizen.NUI/src/public/Theme/ThemeDark.cs deleted file mode 100644 index e4d457c..0000000 --- a/src/Tizen.NUI/src/public/Theme/ThemeDark.cs +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#if false - -using System.Diagnostics.CodeAnalysis; -using Tizen.NUI.BaseComponents; - -namespace Tizen.NUI -{ - internal partial class DefaultThemeCreator - { - [SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope", Justification = "The responsibility to dispose the object is transferred to the theme object.")] - public Theme Create() - { - Theme theme = new Theme() - { - Id = DefaultId, - Version = DefaultVersion, - }; - - // TextLabel style. - theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextLabel", new TextLabelStyle() - { - FontFamily = "BreezeSans", - PixelSize = 32, - TextColor = new Color(1.00f, 1.00f, 1.00f, 1), - FontStyle = new PropertyMap().Add("weight", new PropertyValue("light")), - }); - - // TextField style. - theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextField", new TextFieldStyle() - { - FontFamily = "BreezeSans", - PixelSize = 32, - TextColor = new Color(1.00f, 1.00f, 1.00f, 1), - FontStyle = new PropertyMap().Add("weight", new PropertyValue("regular")), - PrimaryCursorColor = new Vector4(0.08f, 0.45f, 0.90f, 1), - SecondaryCursorColor = new Vector4(0.08f, 0.45f, 0.90f, 1), - CursorWidth = 3, - SelectionHighlightColor = new Vector4(1.00f, 1.00f, 1.00f, 0.20f), - GrabHandleColor = new Color(0.08f, 0.45f, 0.90f, 1), - GrabHandleImage = FrameworkInformation.ResourcePath + "IoT_handler_center_downW.png", - SelectionHandleImageLeft = new PropertyMap().Add("filename", new PropertyValue(FrameworkInformation.ResourcePath + "IoT_handler_downleftW.png")), - SelectionHandleImageRight = new PropertyMap().Add("filename", new PropertyValue(FrameworkInformation.ResourcePath + "IoT_handler_downrightW.png")), - }); - - // TextEditor style. - theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextEditor", new TextEditorStyle() - { - FontFamily = "BreezeSans", - PixelSize = 32, - TextColor = new Color(1.00f, 1.00f, 1.00f, 1), - FontStyle = new PropertyMap().Add("weight", new PropertyValue("regular")), - PrimaryCursorColor = new Vector4(0.08f, 0.45f, 0.90f, 1), - SecondaryCursorColor = new Vector4(0.08f, 0.45f, 0.90f, 1), - CursorWidth = 3, - SelectionHighlightColor = new Vector4(1.00f, 1.00f, 1.00f, 0.20f), - GrabHandleColor = new Color(0.08f, 0.45f, 0.90f, 1), - GrabHandleImage = FrameworkInformation.ResourcePath + "IoT_handler_center_downW.png", - SelectionHandleImageLeft = new PropertyMap().Add("filename", new PropertyValue(FrameworkInformation.ResourcePath + "IoT_handler_downleftW.png")), - SelectionHandleImageRight = new PropertyMap().Add("filename", new PropertyValue(FrameworkInformation.ResourcePath + "IoT_handler_downrightW.png")), - }); - - return theme; - } - } -} -#endif diff --git a/src/Tizen.NUI/src/public/Theme/ThemeManager.cs b/src/Tizen.NUI/src/public/Theme/ThemeManager.cs index c720316..ffacf44 100755 --- a/src/Tizen.NUI/src/public/Theme/ThemeManager.cs +++ b/src/Tizen.NUI/src/public/Theme/ThemeManager.cs @@ -23,6 +23,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using Tizen.NUI.BaseComponents; namespace Tizen.NUI @@ -41,13 +42,18 @@ namespace Tizen.NUI /// 9 public static class ThemeManager { - private static Theme defaultTheme; - private static Theme currentTheme; - private static readonly List builtinThemes = new List(); // Themes provided by framework. - private static readonly List packages = new List();// This is to store default theme creators by packages. + private static Theme baseTheme; // The base theme. It includes all styles including structures (Size, Position, Policy) of components. + private static Theme platformTheme; // The platform theme. This may include color and image information without structure detail. + private static Theme userTheme; // The user custom theme. + private static Theme themeForUpdate; // platformTheme + userTheme. It is used when the component need to update according to theme change. + private static Theme themeForInitialize; // baseTheme + platformTheme + userTheme. It is used when the component is created. + private static readonly List cachedPlatformThemes = new List(); // Themes provided by framework. + private static readonly List packages = new List();// This is to store base theme creators by packages. + private static bool platformThemeEnabled = false; static ThemeManager() { + ExternalThemeManager.Initialize(); AddPackageTheme(DefaultThemeCreator.Instance); } @@ -62,27 +68,84 @@ namespace Tizen.NUI /// internal static WeakEvent> ThemeChangedInternal = new WeakEvent>(); + /// + /// The current theme Id. + /// It returns null when no theme is applied. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static string ThemeId + { + get => userTheme?.Id; + } + + /// + /// The current platform theme Id. + /// Note that it returns null when the platform theme is disabled. + /// If the is given, it can be one of followings in tizen 6.5: + /// + /// + /// org.tizen.default-light-theme + /// + /// + /// org.tizen.default-dark-theme + /// + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static string PlatformThemeId + { + get => platformTheme?.Id; + } + + /// + /// To support deprecated StyleManager. /// NOTE that, please remove this after remove Tizen.NUI.Components.StyleManager - internal static Theme DefaultTheme + /// + internal static Theme BaseTheme { - get => defaultTheme; - set => defaultTheme = value; + get => baseTheme; + set + { + baseTheme = value; + UpdateThemeForInitialize(); + } } + /// + /// To support deprecated StyleManager. + /// NOTE that, please remove this after remove Tizen.NUI.Components.StyleManager + /// internal static Theme CurrentTheme { - get => currentTheme ?? defaultTheme; + get => userTheme ?? baseTheme; set { - currentTheme = value; + userTheme = value; + UpdateThemeForInitialize(); NotifyThemeChanged(); } } - private static bool ThemeApplied => defaultTheme.Count > 0 || (currentTheme != null && currentTheme.Count > 0); + internal static bool PlatformThemeEnabled + { + get => platformThemeEnabled; + set + { + if (platformThemeEnabled == value) return; + + platformThemeEnabled = value; + + if (platformThemeEnabled) + { + ApplyExternalPlatformTheme(ExternalThemeManager.CurrentThemeId, ExternalThemeManager.CurrentThemeVersion); + } + } + } + + internal static bool ApplicationThemeChangeSensitive { get; set; } = false; /// - /// Apply theme to the NUI. + /// Apply custom theme to the NUI. /// This will change the appearance of the existing components with property on. /// This also affects all components created afterwards. /// @@ -98,34 +161,25 @@ namespace Tizen.NUI newTheme.Id = "NONAME"; } - CurrentTheme = newTheme; + userTheme = newTheme; + UpdateThemeForInitialize(); + UpdateThemeForUpdate(); + NotifyThemeChanged(); } /// - /// Change base theme. - /// Originally base theme is a platform profile specific theme. + /// Change tizen theme. /// User may change this to one of platform installed one. /// /// The installed theme Id. /// true on success, false when it failed to find installed theme with given themeId. /// Thrown when the given themeId is null. [EditorBrowsable(EditorBrowsableState.Never)] - public static bool ApplyBaseTheme(string themeId) + public static bool ApplyPlatformTheme(string themeId) { if (themeId == null) throw new ArgumentNullException(nameof(themeId)); - var theme = GetBuiltinTheme(themeId); - - if (theme != null) - { - defaultTheme = theme; - NotifyThemeChanged(); - return true; - } - - Tizen.Log.Info("NUI", $"No Theme found with given id : {themeId}"); - - return false; + return ExternalThemeManager.SetTheme(themeId); } /// @@ -155,49 +209,95 @@ namespace Tizen.NUI } /// - /// Load a style with style name in the current theme. + /// Load a platform style with style name in the current theme. + /// It returns null when the platform theme is disabled. . /// /// The style name. + /// Thrown when the given styleName is null. [EditorBrowsable(EditorBrowsableState.Never)] - internal static ViewStyle GetStyleWithoutClone(string styleName) + public static ViewStyle GetPlatformStyle(string styleName) { - if (!ThemeApplied) return null; + if (styleName == null) throw new ArgumentNullException(nameof(styleName)); + return platformTheme?.GetStyle(styleName)?.Clone(); + } - return currentTheme?.GetStyle(styleName) ?? defaultTheme.GetStyle(styleName); + /// + /// Load a platform style with view type in the current theme. + /// It returns null when the platform theme is disabled. . + /// + /// The type of the view. Full name of the given type will be a key to find a style in the current theme. (e.g. Tizen.NUI.Components.Button) + /// Thrown when the given viewType is null. + [EditorBrowsable(EditorBrowsableState.Never)] + public static ViewStyle GetPlatformStyle(Type viewType) + { + if (viewType == null) throw new ArgumentNullException(nameof(viewType)); + return platformTheme?.GetStyle(viewType)?.Clone(); } /// + /// Load a style with style name in the current theme. + /// + /// The style name. + internal static ViewStyle GetStyleWithoutClone(string styleName) => userTheme?.GetStyle(styleName); + + /// /// Load a style with View type in the current theme. /// /// The type of View. - [EditorBrowsable(EditorBrowsableState.Never)] - internal static ViewStyle GetStyleWithoutClone(Type viewType) - { - if (!ThemeApplied) return null; + internal static ViewStyle GetStyleWithoutClone(Type viewType) => userTheme?.GetStyle(viewType); - return currentTheme?.GetStyle(viewType) ?? defaultTheme.GetStyle(viewType); - } + /// + /// Load a style with style name in the current theme. + /// + /// The style name. + internal static ViewStyle GetUpdateStyleWithoutClone(string styleName) => themeForUpdate?.GetStyle(styleName); /// - /// Get a built-in theme. + /// Load a style with View type in the current theme. /// - /// The built-in theme id. - [EditorBrowsable(EditorBrowsableState.Never)] - internal static Theme GetBuiltinTheme(string themeId) + /// The type of View. + internal static ViewStyle GetUpdateStyleWithoutClone(Type viewType) => themeForUpdate?.GetStyle(viewType); + + /// + /// Load a initial component style. + /// + internal static ViewStyle GetInitialStyleWithoutClone(string styleName) => themeForInitialize.GetStyle(styleName); + + /// + /// Load a initial component style. + /// + internal static ViewStyle GetInitialStyleWithoutClone(Type viewType) => themeForInitialize.GetStyle(viewType); + + /// + /// Get a platform installed theme. + /// + /// The theme id. + internal static Theme LoadPlatformTheme(string themeId) { Debug.Assert(themeId != null); - Theme result = null; - int index = builtinThemes.FindIndex(x => string.Equals(x.Id, themeId, StringComparison.OrdinalIgnoreCase)); + // Check if it is already loaded. + int index = cachedPlatformThemes.FindIndex(x => string.Equals(x.Id, themeId, StringComparison.OrdinalIgnoreCase)); if (index >= 0) { - result = builtinThemes[index]; + Tizen.Log.Info("NUI", $"Hit cache."); + var found = cachedPlatformThemes[index]; + // If the cached is not a full set, update it. + if (found.PackageCount < packages.Count) + { + UpdatePlatformTheme(found); + Tizen.Log.Info("NUI", $"Update cache."); + } + return found; } - else + + var newTheme = CreatePlatformTheme(themeId); + if (newTheme != null) { - result = LoadBuiltinTheme(themeId); + cachedPlatformThemes.Add(newTheme); + Tizen.Log.Info("NUI", $"Platform theme has been loaded successfully."); } - return result; + return newTheme; } /// @@ -210,50 +310,49 @@ namespace Tizen.NUI internal static void ApplyFallbackTheme(Theme fallbackTheme) { Debug.Assert(fallbackTheme != null); - defaultTheme = (Theme)fallbackTheme?.Clone(); + BaseTheme = (Theme)fallbackTheme?.Clone(); } /// - /// Set an external theme as a base theme. + /// Apply an external platform theme. /// - /// The external theme instance to be applied as base. - internal static void ApplyExternalTheme(IExternalTheme externalTheme) + /// The external theme id. + /// The external theme version. + internal static void ApplyExternalPlatformTheme(string id, string version) { #if ExternalThemeEnabled - Debug.Assert(defaultTheme != null); + Debug.Assert(baseTheme != null); - if (defaultTheme.HasSameIdAndVersion(externalTheme)) + // If the given theme is invalid, do nothing. + if (string.IsNullOrEmpty(id)) { return; } - int index = builtinThemes.FindIndex(x => x.HasSameIdAndVersion(externalTheme)); - if (index >= 0 && builtinThemes[index].PackageCount == packages.Count) + // If no platform theme has been applied and the base theme can cover the given one, do nothing. + if (platformTheme == null && baseTheme.HasSameIdAndVersion(id, version)) { - defaultTheme = builtinThemes[index]; - NotifyThemeChanged(); + Tizen.Log.Info("NUI", "The base theme can cover platform theme: Skip loading."); return; } - var newTheme = new Theme() + // If the given theme is already applied, do nothing. + if (platformTheme != null && platformTheme.HasSameIdAndVersion(id, version)) { - Id = externalTheme.Id, - Version = externalTheme.Version - }; + Tizen.Log.Info("NUI", "Platform theme is already applied: Skip loading."); + return; + } - AddToBuiltinThemes(newTheme); + var loaded = LoadPlatformTheme(id); - foreach (IThemeCreator themeCreator in packages) + if (loaded != null) { - var packageTheme = themeCreator.Create(); - Debug.Assert(packageTheme != null); - - packageTheme.ApplyExternalTheme(externalTheme, themeCreator.GetExternalThemeKeyListSet()); - newTheme.MergeWithoutClone(packageTheme); + Tizen.Log.Info("NUI", $"{loaded.Id} has been applied successfully."); + platformTheme = loaded; + UpdateThemeForInitialize(); + UpdateThemeForUpdate(); + NotifyThemeChanged(true); } - - defaultTheme = newTheme; - NotifyThemeChanged(); #endif } @@ -263,83 +362,179 @@ namespace Tizen.NUI { return; } + + Tizen.Log.Info("NUI", $"AddPackageTheme({themeCreator.GetType().Assembly.GetName().Name})"); packages.Add(themeCreator); - var packageTheme = themeCreator.Create(); - Debug.Assert(packageTheme != null); + // Base theme + var packageBaseTheme = themeCreator.Create(); + Debug.Assert(packageBaseTheme != null); + + if (baseTheme == null) baseTheme = packageBaseTheme; + else baseTheme.MergeWithoutClone(packageBaseTheme); + baseTheme.PackageCount++; #if ExternalThemeEnabled - var externalTheme = ExternalThemeManager.GetCurrentTheme(); - if (externalTheme != null && !packageTheme.HasSameIdAndVersion(externalTheme)) + if (platformThemeEnabled) { - packageTheme.ApplyExternalTheme(externalTheme, themeCreator.GetExternalThemeKeyListSet()); + Tizen.Log.Info("NUI", $"Platform theme is enabled"); + if (platformTheme != null) + { + UpdatePlatformTheme(platformTheme); + } + else + { + if (!baseTheme.HasSameIdAndVersion(ExternalThemeManager.CurrentThemeId, ExternalThemeManager.CurrentThemeVersion)) + { + var loaded = LoadPlatformTheme(ExternalThemeManager.CurrentThemeId); + if (loaded != null) + { + platformTheme = loaded; + } + } + } + UpdateThemeForUpdate(); } #endif - if (defaultTheme == null) + UpdateThemeForInitialize(); + } + + internal static void Preload() + { +#if ExternalThemeEnabled + Debug.Assert(baseTheme != null); + + if (string.IsNullOrEmpty(ExternalThemeManager.CurrentThemeId)) return; + + LoadPlatformTheme(ExternalThemeManager.CurrentThemeId); +#endif + } + + // TODO Please make it private after removing Tizen.NUI.Components.StyleManager. + internal static void UpdateThemeForUpdate() + { + if (userTheme == null) { - defaultTheme = new Theme() - { - Id = packageTheme.Id, - Version = packageTheme.Version - }; - AddToBuiltinThemes(defaultTheme); + themeForUpdate = platformTheme; + return; + } + + if (platformTheme == null) + { + themeForUpdate = userTheme; + return; } - defaultTheme.MergeWithoutClone(packageTheme); - defaultTheme.PackageCount++; + themeForUpdate = new Theme(); + themeForUpdate.Merge(platformTheme); + themeForUpdate.MergeWithoutClone(userTheme); } - private static void AddToBuiltinThemes(Theme theme) + // TODO Please make it private after removing Tizen.NUI.Components.StyleManager. + internal static void UpdateThemeForInitialize() { - int index = builtinThemes.FindIndex(x => x.Id.Equals(theme.Id, StringComparison.OrdinalIgnoreCase)); - if (index >= 0) + if (platformTheme == null && userTheme == null) + { + themeForInitialize = baseTheme; + return; + } + + themeForInitialize = new Theme(); + themeForInitialize.Merge(baseTheme); + + if (userTheme == null) { - builtinThemes[index] = theme; + if (platformTheme != null) themeForInitialize.MergeWithoutClone(platformTheme); } else { - builtinThemes.Add(theme); + if (platformTheme != null) themeForInitialize.Merge(platformTheme); + themeForInitialize.MergeWithoutClone(userTheme); + } + } + + private static void UpdatePlatformTheme(Theme theme) + { + var sharedResourcePath = ExternalThemeManager.GetSharedResourcePath(theme.Id); + + if (sharedResourcePath == null) + { + return; + } + + for (var i = theme.PackageCount; i < packages.Count; i++) + { + theme.MergeWithoutClone(CreatePlatformTheme(sharedResourcePath, packages[i].GetType().Assembly.GetName().Name)); } + theme.PackageCount = packages.Count; } - private static Theme LoadBuiltinTheme(string id) + private static Theme CreatePlatformTheme(string id) { - Debug.Assert(id != null); - // Load from tizen-theme-manager - var externalTheme = ExternalThemeManager.GetTheme(id); + var sharedResourcePath = ExternalThemeManager.GetSharedResourcePath(id); - if (externalTheme == null) + if (sharedResourcePath == null) { return null; } var newTheme = new Theme() { - Id = externalTheme.Id, - Version = externalTheme.Version + Id = id }; - AddToBuiltinThemes(newTheme); - - foreach (IThemeCreator themeCreator in packages) + foreach (var packageCreator in packages) { - var packageTheme = themeCreator.Create(); - Debug.Assert(packageTheme != null); - - packageTheme.ApplyExternalTheme(externalTheme, themeCreator.GetExternalThemeKeyListSet()); - newTheme.MergeWithoutClone(packageTheme); + newTheme.MergeWithoutClone(CreatePlatformTheme(sharedResourcePath, packageCreator.GetType().Assembly.GetName().Name)); } + newTheme.PackageCount = packages.Count; return newTheme; } - private static void NotifyThemeChanged() + [SuppressMessage("Microsoft.Design", "CA1031: Do not catch general exception types", Justification = "This method is to handle external resources that may throw an exception but ignorable. This method should not interrupt the main stream.")] + private static Theme CreatePlatformTheme(string sharedResourcePath, string assemblyName) + { + ExternalThemeManager.SharedResourcePath = sharedResourcePath; + try + { + return new Theme(sharedResourcePath + assemblyName + ".Theme.xaml"); + } + catch (System.IO.FileNotFoundException) + { + Tizen.Log.Info("NUI", $"[Ignorable] Current tizen theme does not have NUI theme."); + } + catch (Exception e) + { + Tizen.Log.Info("NUI", $"[Ignorable] {e.GetType().Name} occurred while applying tizen theme to {assemblyName}: {e.Message}"); + } + + return new Theme(); + } + + private static void AddToPlatformThemes(Theme theme) + { + int index = cachedPlatformThemes.FindIndex(x => x.Id.Equals(theme.Id, StringComparison.OrdinalIgnoreCase)); + if (index >= 0) + { + Tizen.Log.Info("NUI", $"Existing {theme.Id} item is overwritten"); + cachedPlatformThemes[index] = theme; + } + else + { + cachedPlatformThemes.Add(theme); + Tizen.Log.Info("NUI", $"New {theme.Id} is saved."); + } + } + + private static void NotifyThemeChanged(bool platformThemeUpdated = false) { - Debug.Assert(defaultTheme != null); + Debug.Assert(baseTheme != null); - var id = currentTheme?.Id ?? defaultTheme.Id; - ThemeChangedInternal.Invoke(null, new ThemeChangedEventArgs(id)); - ThemeChanged?.Invoke(null, new ThemeChangedEventArgs(id)); + var platformThemeId = platformTheme?.Id; + var userThemeId = userTheme?.Id; + ThemeChangedInternal.Invoke(null, new ThemeChangedEventArgs(userThemeId, platformThemeId, platformThemeUpdated)); + ThemeChanged?.Invoke(null, new ThemeChangedEventArgs(userThemeId, platformThemeId, platformThemeUpdated)); } } } diff --git a/src/Tizen.NUI/src/public/Theme/TizenExternalTheme.cs b/src/Tizen.NUI/src/public/Theme/TizenExternalTheme.cs deleted file mode 100755 index f13786b..0000000 --- a/src/Tizen.NUI/src/public/Theme/TizenExternalTheme.cs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -using System; -using System.Diagnostics.CodeAnalysis; - -namespace Tizen.NUI -{ - /// - /// This is a wrapper to express tizen-theme-manager's theme. - /// - internal class TizenExternalTheme : IExternalTheme - { - private const string prefix = "/theme/"; - private readonly Tizen.Applications.ThemeManager.Theme theme; - - internal TizenExternalTheme(Tizen.Applications.ThemeManager.Theme theme) - { - this.theme = theme; - } - - public string Id - { - get => theme.Id; - } - - public string Version - { - get => theme.Version; - } - - [SuppressMessage("Microsoft.Design", "CA1031: Do not catch general exception types", Justification = "This method is to handle external resources that may throw an exception but ignorable. This method should not interrupt the main stream.")] - public string GetValue(string key) - { - string themeKey = prefix + key; - string extracted = null; - - try - { - if (theme.HasKey(themeKey)) - { - extracted = theme.GetString(themeKey); - } - } - catch (Exception e) - { - Tizen.Log.Error("NUI", $"{e.GetType().Name} occurred while getting value from {theme.GetType().FullName}: {e.Message}"); - } - - return extracted; - } - } -} diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ThemeResourcePathExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ThemeResourcePathExtension.cs new file mode 100755 index 0000000..1a56015 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ThemeResourcePathExtension.cs @@ -0,0 +1,51 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System; +using System.ComponentModel; +using Tizen.NUI.Binding; + +namespace Tizen.NUI.Xaml +{ + /// The class to support theme resource path. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty(nameof(FilePath))] + [AcceptEmptyServiceProvider] + public class ThemeResourcePathExtension : IMarkupExtension + { + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public ThemeResourcePathExtension() + { + } + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string FilePath { get; set; } + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string ProvideValue(IServiceProvider serviceProvider) => ExternalThemeManager.SharedResourcePath + FilePath; + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) + { + return (this as IMarkupExtension).ProvideValue(serviceProvider); + } + } +} -- 2.7.4