--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+internal static partial class Interop
+{
+ internal static partial class Libraries
+ {
+ public const string ThemeManager = "libcapi-appfw-tizen-theme.so";
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.Runtime.InteropServices;
+using Tizen;
+using Tizen.Applications;
+
+internal static partial class Interop
+{
+ internal static partial class ThemeManager
+ {
+ private const string LogTag = "Tizen.Applications.ThemeManager";
+
+ internal enum ErrorCode : int
+ {
+ None = Tizen.Internals.Errors.ErrorCode.None,
+ InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+ PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+ IoError = Tizen.Internals.Errors.ErrorCode.IoError,
+ }
+
+ internal static class ThemeManagerErrorFactory
+ {
+ internal static Exception GetException(Interop.ThemeManager.ErrorCode err, string message)
+ {
+ string errMessage = string.Format("{0} err = {1}", message, err);
+ Log.Warn(LogTag, errMessage);
+ switch (err)
+ {
+ case Interop.ThemeManager.ErrorCode.InvalidParameter:
+ return new ArgumentException(errMessage);
+ case Interop.ThemeManager.ErrorCode.PermissionDenied:
+ return new UnauthorizedAccessException(errMessage);
+ case Interop.ThemeManager.ErrorCode.IoError:
+ default:
+ return new InvalidOperationException(errMessage);
+ }
+ }
+ }
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void ThemeLoaderChangedCallback(IntPtr handle, IntPtr userData);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_id")]
+ internal static extern ErrorCode GetId(IntPtr handle, out string id);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_version")]
+ internal static extern ErrorCode GetVersion(IntPtr handle, out string version);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_tool_version")]
+ internal static extern ErrorCode GetToolVersion(IntPtr handle, out string version);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_title")]
+ internal static extern ErrorCode GetTitle(IntPtr handle, out string title);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_resolution")]
+ internal static extern ErrorCode GetResolution(IntPtr handle, out string resolution);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_preview")]
+ internal static extern ErrorCode GetPreview(IntPtr handle, out string preview);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_description")]
+ internal static extern ErrorCode GetDescription(IntPtr handle, out string description);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_string")]
+ internal static extern ErrorCode GetString(IntPtr handle, string key, out string val);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_string_array")]
+ internal static extern ErrorCode GetStringArray(IntPtr handle, string key, out IntPtr val, out int count);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_path")]
+ internal static extern ErrorCode GetPath(IntPtr handle, string key, out string val);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_path_array")]
+ internal static extern ErrorCode GetPathArray(IntPtr handle, string key, out IntPtr val, out int count);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_int")]
+ internal static extern ErrorCode GetInt(IntPtr handle, string key, out int val);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_float")]
+ internal static extern ErrorCode GetFloat(IntPtr handle, string key, out float val);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_get_bool")]
+ internal static extern ErrorCode GetBool(IntPtr handle, string key, out bool val);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_clone")]
+ internal static extern ErrorCode ThemeClone(IntPtr handle, out IntPtr cloned);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_destroy")]
+ internal static extern ErrorCode ThemeDestroy(IntPtr handle);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_loader_create")]
+ internal static extern ErrorCode LoaderCreate(out IntPtr loaderHandle);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_loader_destroy")]
+ internal static extern ErrorCode LoaderDestroy(IntPtr loaderHandle);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_loader_add_event")]
+ internal static extern ErrorCode LoaderAddEvent(IntPtr loaderHandle, ThemeLoaderChangedCallback callback, IntPtr userData, out string eventId);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_loader_remove_event")]
+ internal static extern ErrorCode LoaderRemoveEvent(IntPtr loaderHandle, string eventId);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_loader_load_current")]
+ internal static extern ErrorCode LoaderLoadCurrentTheme(IntPtr loaderHandle, out IntPtr handle);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_loader_load")]
+ internal static extern ErrorCode LoaderLoadTheme(IntPtr loaderHandle, string id, out IntPtr handle);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_loader_query_id")]
+ internal static extern ErrorCode LoaderQueryId(IntPtr loaderHandle, out IntPtr ids, out int count);
+
+ [DllImport(Libraries.ThemeManager, EntryPoint = "theme_loader_set_current")]
+ internal static extern ErrorCode LoaderSetCurrentTheme(IntPtr loaderHandle, string id);
+ }
+}
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\src\Tizen\Tizen.csproj" />
+ </ItemGroup>
+
+
+</Project>
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29806.167
+MinimumVisualStudioVersion = 15.0.26124.0
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.ThemeManager", "Tizen.Applications.ThemeManager.csproj", "{C37063A6-0105-43F6-B3EA-CA4786F62BD7}"
+ ProjectSection(ProjectDependencies) = postProject
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3} = {A0671F32-9031-4F70-B888-D3A27ABC05F3}
+ EndProjectSection
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen", "..\..\..\src\Tizen\Tizen.csproj", "{A0671F32-9031-4F70-B888-D3A27ABC05F3}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Debug|x64.Build.0 = Debug|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Debug|x86.Build.0 = Debug|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Release|x64.ActiveCfg = Release|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Release|x64.Build.0 = Release|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Release|x86.ActiveCfg = Release|Any CPU
+ {C37063A6-0105-43F6-B3EA-CA4786F62BD7}.Release|x86.Build.0 = Release|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Debug|x64.Build.0 = Debug|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Debug|x86.Build.0 = Debug|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Release|x64.ActiveCfg = Release|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Release|x64.Build.0 = Release|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Release|x86.ActiveCfg = Release|Any CPU
+ {A0671F32-9031-4F70-B888-D3A27ABC05F3}.Release|x86.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {0131746E-72CC-496D-9774-A02B519FDB0C}
+ EndGlobalSection
+EndGlobal
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Applications.ThemeManager
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public class Theme : IDisposable
+ {
+ private bool _disposed = false;
+ private IntPtr _handle;
+ private string _id = String.Empty;
+ private string _version = String.Empty;
+ private string _toolVersion = String.Empty;
+ private string _title = String.Empty;
+ private string _resolution = String.Empty;
+ private string _preview = String.Empty;
+ private string _description = String.Empty;
+
+ /// <summary>
+ /// A copy constructor of Theme.
+ /// </summary>
+ /// <param name="theme">Theme class.</param>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of system error.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ /// <since_tizen> 8 </since_tizen>
+ public Theme(Theme theme)
+ {
+ if (theme == null || theme._handle == IntPtr.Zero)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(Interop.ThemeManager.ErrorCode.InvalidParameter, "Invalid parameter");
+ }
+
+ var err = Interop.ThemeManager.ErrorCode.None;
+ err = Interop.ThemeManager.ThemeClone(theme._handle, out _handle);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to clone handle");
+ }
+ }
+
+ internal Theme(IntPtr handle)
+ {
+ _handle = handle;
+ var err = Interop.ThemeManager.ErrorCode.None;
+ err = Interop.ThemeManager.GetId(handle, out _id);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get id");
+ }
+
+ err = Interop.ThemeManager.GetVersion(handle, out _version);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get version");
+ }
+
+ err = Interop.ThemeManager.GetToolVersion(handle, out _toolVersion);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get tool version");
+ }
+
+ err = Interop.ThemeManager.GetTitle(handle, out _title);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get title");
+ }
+
+ err = Interop.ThemeManager.GetResolution(handle, out _resolution);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get resolution");
+ }
+
+ err = Interop.ThemeManager.GetPreview(handle, out _preview);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get preview");
+ }
+
+ err = Interop.ThemeManager.GetDescription(handle, out _description);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get description");
+ }
+ }
+
+ /// <summary>
+ /// A Theme ID
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public string Id { get { return _id; } }
+
+ /// <summary>
+ /// A Theme Version
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public string Version { get { return _version; } }
+
+ /// <summary>
+ /// A Theme ToolVersion
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public string ToolVersion { get { return _toolVersion; } }
+
+ /// <summary>
+ /// A Theme Title
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public string Title { get { return _title; } }
+
+ /// <summary>
+ /// A Theme Resolution
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public string Resolution { get { return _resolution; } }
+
+ /// <summary>
+ /// A Theme Preview
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public string Preview { get { return _preview; } }
+
+ /// <summary>
+ /// A Theme Description
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public string Description { get { return _description; } }
+
+
+ /// <summary>
+ /// Gets the string corresponding with given key.
+ /// </summary>
+ /// <param name="key">The string key to find information.</param>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public string GetString(string key)
+ {
+ string str;
+ var err = Interop.ThemeManager.GetString(_handle, key, out str);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get string value of the key");
+ }
+
+ return str;
+ }
+
+ /// <summary>
+ /// Gets the string array corresponding with given key.
+ /// </summary>
+ /// <param name="key">The string key to find information.</param>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public IEnumerable<string> GetStrings(string key)
+ {
+ IntPtr val;
+ int count;
+ string[] strings;
+ var err = Interop.ThemeManager.GetStringArray(_handle, key, out val, out count);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get string array value of the key");
+ }
+
+ IntPtrToStringArray(val, count, out strings);
+ return strings;
+ }
+
+ /// <summary>
+ /// Gets the integer corresponding with given key.
+ /// </summary>
+ /// <param name="key">The string key to find information.</param>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public int GetInt(string key)
+ {
+ int val;
+ var err = Interop.ThemeManager.GetInt(_handle, key, out val);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get integer value of the key");
+ }
+
+ return val;
+ }
+
+ /// <summary>
+ /// Gets the float corresponding with given key.
+ /// </summary>
+ /// <param name="key">The string key to find information.</param>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public float GetFloat(string key)
+ {
+ float val;
+ var err = Interop.ThemeManager.GetFloat(_handle, key, out val);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get float value of the key");
+ }
+
+ return val;
+ }
+
+ /// <summary>
+ /// Gets the bool corresponding with given key.
+ /// </summary>
+ /// <param name="key">The string key to find information.</param>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public bool GetBool(string key)
+ {
+ bool val;
+ var err = Interop.ThemeManager.GetBool(_handle, key, out val);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get bool value of the key");
+ }
+
+ return val;
+ }
+
+ /// <summary>
+ /// Gets the path corresponding with given key.
+ /// </summary>
+ /// <param name="key">The string key to find information.</param>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public string GetPath(string key)
+ {
+ string val;
+ var err = Interop.ThemeManager.GetPath(_handle, key, out val);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get path value of the key");
+ }
+
+ return val;
+ }
+
+ /// <summary>
+ /// Gets the path array corresponding with given key.
+ /// </summary>
+ /// <param name="key">The string key to find information.</param>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public IEnumerable<string> GetPaths(string key)
+ {
+ IntPtr val;
+ int count;
+ string[] paths;
+ var err = Interop.ThemeManager.GetPathArray(_handle, key, out val, out count);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get path array value of the key");
+ }
+
+ IntPtrToStringArray(val, count, out paths);
+ return paths;
+ }
+
+ static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
+ {
+ managedArray = new string[size];
+ IntPtr[] IntPtrArray = new IntPtr[size];
+ Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
+ for (int iterator = 0; iterator < size; iterator++)
+ {
+ managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);
+ }
+ }
+ /// <summary>
+ /// Releases all resources used by the Theme class.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases the unmanaged resources used by the Theme class specifying whether to perform a normal dispose operation.
+ /// </summary>
+ /// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ return;
+
+ if (_handle != IntPtr.Zero)
+ {
+ Interop.ThemeManager.ThemeDestroy(_handle);
+ _handle = IntPtr.Zero;
+ }
+ _disposed = true;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.Text;
+
+namespace Tizen.Applications.ThemeManager
+{
+ /// <summary>
+ /// ThemeEventArgs class. This class is an event arguments of the ThemeLoaderChanged events.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public class ThemeEventArgs : EventArgs
+ {
+ internal ThemeEventArgs(Theme theme)
+ {
+ Theme = theme;
+ }
+
+ /// <summary>
+ /// A Theme
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public Theme Theme { get; }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.Runtime.InteropServices;
+
+namespace Tizen.Applications.ThemeManager
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public class ThemeLoader : IDisposable
+ {
+ private const string LogTag = "Tizen.Applications.ThemeManager";
+ private bool _disposed = false;
+ private event EventHandler<ThemeEventArgs> _changedEventHandler;
+ private Interop.ThemeManager.ThemeLoaderChangedCallback _callback;
+ private string _eventId;
+ private Theme _currentTheme = null;
+ internal IntPtr _loaderHandle = IntPtr.Zero;
+
+ /// <summary>
+ /// Creates ThemeLoader.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="OutOfMemoryException">Failed to create handle.</exception>
+ public ThemeLoader()
+ {
+ Interop.ThemeManager.ErrorCode err = Interop.ThemeManager.LoaderCreate(out _loaderHandle);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to create themeloader");
+ }
+ }
+
+ private void OnThemeChanged(IntPtr handle, IntPtr userData)
+ {
+ Interop.ThemeManager.ThemeClone(handle, out IntPtr cloned);
+ _changedEventHandler?.Invoke(this, new ThemeEventArgs(new Theme(cloned)));
+ }
+
+ /// <summary>
+ /// Adds or removes events for theme changed.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public event EventHandler<ThemeEventArgs> ThemeChanged
+ {
+ add
+ {
+ if (_changedEventHandler == null)
+ {
+ if (_callback == null)
+ _callback = new Interop.ThemeManager.ThemeLoaderChangedCallback(OnThemeChanged);
+ Interop.ThemeManager.ErrorCode err = Interop.ThemeManager.LoaderAddEvent(_loaderHandle, _callback, IntPtr.Zero, out _eventId);
+
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to add event");
+ }
+
+ }
+ _changedEventHandler += value;
+
+ }
+ remove
+ {
+ _changedEventHandler -= value;
+ if (_changedEventHandler == null)
+ {
+ Interop.ThemeManager.ErrorCode err = Interop.ThemeManager.LoaderRemoveEvent(_loaderHandle, _eventId);
+
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to remove event");
+ }
+ _callback = null;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Sets current theme.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ public Theme CurrentTheme
+ {
+ get
+ {
+ if (_currentTheme != null && _currentTheme.Id.Length > 0)
+ return _currentTheme;
+
+ Interop.ThemeManager.ErrorCode err = Interop.ThemeManager.LoaderLoadCurrentTheme(_loaderHandle, out IntPtr _themeHandle);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to load current theme");
+ }
+
+ _currentTheme = new Theme(_themeHandle);
+ return _currentTheme;
+ }
+ set
+ {
+ if (value == null)
+ throw new ArgumentException("value is null");
+
+ Interop.ThemeManager.ErrorCode err = Interop.ThemeManager.LoaderSetCurrentTheme(_loaderHandle, value.Id);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to set current. Err = " + err);
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to set current theme");
+ }
+
+ if(_currentTheme != value)
+ _currentTheme = value;
+ }
+ }
+
+ /// <summary>
+ /// Loads theme.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ public Theme LoadTheme(string id)
+ {
+ IntPtr _themeHandle;
+
+ Interop.ThemeManager.ErrorCode err = Interop.ThemeManager.LoaderLoadTheme(_loaderHandle, id, out _themeHandle);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to load theme");
+ }
+
+ return new Theme(_themeHandle);
+ }
+
+ /// <summary>
+ /// Gets bundle of theme IDs.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
+ public IEnumerable<string> QueryIds()
+ {
+ IntPtr ids;
+ string[] stringArray;
+ int count;
+
+ Interop.ThemeManager.ErrorCode err = Interop.ThemeManager.LoaderQueryId(_loaderHandle, out ids, out count);
+ if (err != Interop.ThemeManager.ErrorCode.None)
+ {
+ throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to query ids");
+ }
+
+ IntPtrToStringArray(ids, count, out stringArray);
+ return stringArray;
+ }
+
+ static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
+ {
+ managedArray = new string[size];
+ IntPtr[] IntPtrArray = new IntPtr[size];
+ Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
+ for (int iterator = 0; iterator < size; iterator++)
+ {
+ managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);
+ }
+ }
+
+ /// <summary>
+ /// Releases all resources used by the ThemeLoader class.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases the unmanaged resources used by the ThemeLoader class specifying whether to perform a normal dispose operation.
+ /// </summary>
+ /// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ return;
+
+ if (_loaderHandle != IntPtr.Zero)
+ {
+ Interop.ThemeManager.LoaderDestroy(_loaderHandle);
+ _loaderHandle = IntPtr.Zero;
+ }
+
+ if (disposing && _currentTheme != null)
+ _currentTheme.Dispose();
+
+ _disposed = true;
+ }
+ }
+}