/* * Copyright(c) 2019 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.ComponentModel; namespace Tizen.NUI.Components { /// /// StyleManager is a class to manager all style. /// /// 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 sealed class StyleManager { private string theme = "default"; private Dictionary> themeStyleSet = new Dictionary>(); private Dictionary defaultStyleSet = new Dictionary(); private EventHandler themeChangeHander; /// /// StyleManager construct. /// /// 6 private StyleManager() { } /// /// An event for the theme changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.
///
/// 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 event EventHandler ThemeChangedEvent { add { themeChangeHander += value; } remove { themeChangeHander -= value; } } /// /// StyleManager static instance. /// /// 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 static StyleManager Instance { get; } = new StyleManager(); /// /// Style theme. /// /// 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 string Theme { get { return theme; } set { if(theme != value) { theme = value; themeChangeHander?.Invoke(null, new ThemeChangeEventArgs { CurrentTheme = theme }); } } } /// /// Register style in StyleManager. /// /// Style name. /// Theme. /// Style type. /// Flag to decide if it is default style. /// 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 void RegisterStyle(string style, string theme, Type styleType, bool bDefault = false) { if(style == null) { throw new InvalidOperationException($"style can't be null"); } if(theme == null || bDefault == true) { if(defaultStyleSet.ContainsKey(style)) { throw new InvalidOperationException($"{style}] already be used"); } else { defaultStyleSet.Add(style, styleType); } return; } if(themeStyleSet.ContainsKey(style) && themeStyleSet[style].ContainsKey(theme)) { throw new InvalidOperationException($"{style}] already be used"); } if(!themeStyleSet.ContainsKey(style)) { themeStyleSet.Add(style, new Dictionary()); } themeStyleSet[style].Add(theme, styleType); } /// /// Get attributes by style. /// /// Style name. /// 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 Attributes GetAttributes(string style) { if(style == null) { return null; } object obj = null; if(themeStyleSet.ContainsKey(style) && themeStyleSet[style].ContainsKey(Theme)) { obj = Activator.CreateInstance(themeStyleSet[style][Theme]); } else if(defaultStyleSet.ContainsKey(style)) { obj = Activator.CreateInstance(defaultStyleSet[style]); } return (obj as StyleBase)?.GetAttributes(); } /// /// ThemeChangeEventArgs is a class to record theme change event arguments which will sent to user. /// /// 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 class ThemeChangeEventArgs : EventArgs { public string CurrentTheme; } } }