Use manifest metadata.
authorPiotr Czaja <p.czaja@samsung.com>
Mon, 16 Oct 2023 10:31:52 +0000 (12:31 +0200)
committerPiotr Czaja/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <p.czaja@samsung.com>
Tue, 31 Oct 2023 15:30:47 +0000 (16:30 +0100)
Change-Id: I98bb5182c62a0d4e89d047ae0296ff31fcf91800

SettingCore/MainMenuInfo.cs
SettingMainGadget/SettingMainGadget/tizen-manifest.xml

index 3c4633c310d01917778a34638e917faddd4d0ac2..e2143f76122e88b418cd51f78a5b5b86540bf2b1 100644 (file)
@@ -16,7 +16,10 @@ namespace SettingCore
 
         private static string CachePath => System.IO.Path.Combine(Tizen.Applications.Application.Current.DirectoryInfo.Data, "main-menu.cache");
         private static List<MainMenuInfo> cache = new List<MainMenuInfo>();
-
+        private const string metadataNamePrefix = "http://tizen.org/metadata/ui-gadget/menu";
+        private const string iconPathMetadata = "icon-path";
+        private const string iconColorMetadata = "icon-color";
+        private const string titleMetadata = "title";
         static MainMenuInfo()
         {
             ReadCache();
@@ -100,6 +103,46 @@ namespace SettingCore
             };
         }
 
+        private static MainMenuInfo FromManifest(SettingGadgetInfo info)
+        {
+            string iconPath = getResourcePath(info, getMetadata(info, $"{metadataNamePrefix}/{info.Path}/{iconPathMetadata}"));
+            if (iconPath == null)
+            {
+                Logger.Warn($"could not create MainMenuGadget from {info.ClassName} manifest file.");
+                return null;
+            }
+
+            Color iconColor = getIconColor(info);
+            if (iconColor == null)
+            {
+                Logger.Warn($"could not create MainMenuGadget from {info.ClassName} manifest file.");
+                return null;
+            }
+
+            string title = getTitle(info);
+            if (title == null)
+            {
+                Logger.Warn($"could not create MainMenuGadget from {info.ClassName} manifest file.");
+                return null;
+            }
+
+            return new MainMenuInfo
+            {
+                IconPath = iconPath,
+                IconColor = iconColor,
+                Title = title,
+                Path = info.Path,
+            };
+        }
+
+        private static string getTitle(SettingGadgetInfo info)
+        {
+            var NUIGadgetResourceManager = new NUIGadgetResourceManager(info.Pkg);
+            string titleMetadata = getMetadata(info, $"{metadataNamePrefix}/{info.Path}/{MainMenuInfo.titleMetadata}");
+            string title = titleMetadata is null ? null : NUIGadgetResourceManager.GetString(titleMetadata);
+            return title;
+        }
+
         private static MainMenuInfo FromCache(SettingGadgetInfo info)
         {
             var cached = cache.SingleOrDefault(x => x.Path == info.Path);
@@ -132,6 +175,16 @@ namespace SettingCore
                 return menu;
             }
 
+            stopwatch.Restart();
+            menu = FromManifest(info);
+            stopwatch.Stop();
+            total += stopwatch.Elapsed;
+            if (menu != null)
+            {
+                Logger.Debug($"MEASURE loaded MainMenuInfo from Manifest file, path: {info.Path}, time: {stopwatch.Elapsed}");
+                return menu;
+            }
+
             stopwatch.Restart();
             menu = FromGadget(info);
             stopwatch.Stop();
@@ -145,5 +198,47 @@ namespace SettingCore
             Logger.Debug($"MEASURE could NOT load MainMenuInfo, path: {info.Path}, time: {total}");
             return null;
         }
+
+        private static Color getIconColor(SettingGadgetInfo info)
+        {
+            string iconColorHex = getMetadata(info, $"{metadataNamePrefix}/{info.Path}/{iconColorMetadata}");
+            if (iconColorHex is null)
+            {
+                return null;
+            }
+            var themeColors = iconColorHex.Split(",");
+            if (themeColors.Length != 2)
+            {
+                return null;
+            }
+            bool IsLightTheme = ThemeManager.PlatformThemeId == "org.tizen.default-light-theme";
+            Color iconColor = iconColorHex is null ? null : new Color(IsLightTheme ? themeColors[0] : themeColors[1]); ;
+            return iconColor;
+        }
+
+        private static string getMetadata(SettingGadgetInfo info, string metadataName)
+        {
+            if (info.Pkg.Metadata.TryGetValue(metadataName, out string data))
+            {
+                return data;
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        private static string getResourcePath(SettingGadgetInfo info, string relativeFilePath)
+        {
+            if (relativeFilePath is null)
+                return null;
+            string gadgetAssemplyName = info.Pkg.ExecutableFile.Replace(".dll", string.Empty);
+            string absoluteDirPath = System.IO.Path.Combine(Tizen.Applications.Application.Current.DirectoryInfo.Resource, "mount/allowed/", gadgetAssemplyName);
+
+            // remove leading slash
+            relativeFilePath = relativeFilePath.TrimStart('/');
+
+            return System.IO.Path.Combine(absoluteDirPath, relativeFilePath);
+        }
     }
 }
index 0e6f1b783b8ccae52b9c68d1138efa1950e18c0c..f80544d0970ef791bda628069b735288210d8e30 100644 (file)
   <metadata key="http://tizen.org/metadata/ui-gadget/dll" value="SettingMainGadget.dll"/>
   <metadata key="http://tizen.org/metadata/ui-gadget/resource/dll" value="SettingMainGadget.resources.dll"/>
   <metadata key="http://tizen.org/metadata/ui-gadget/resource/class-name" value="SettingMainGadget.TextResources.Resources"/>
+
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Display/icon-path" value="display.svg"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Display/icon-color" value="#0075FF,#1A85FF"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Display/title" value="IDS_ST_HEADER_DISPLAY"/>
+
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Sound/icon-path" value="sound.svg"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Sound/icon-color" value="#DB3069,#DF4679"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Sound/title" value="IDS_ST_HEADER_SOUND"/>
+
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/DateTime/icon-path" value="datetime.svg"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/DateTime/icon-color" value="#205493,#2560A8"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/DateTime/title" value="IDS_ST_BODY_DATE_AND_TIME"/>
+
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Language/icon-path" value="language_input.svg"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Language/icon-color" value="#205493,#2560A8"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Language/title" value="IDS_ST_HEADER_LANGUAGE_AND_INPUT"/>
+
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/About/icon-path" value="about.svg"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/About/icon-color" value="#301A4B,#CAB4E5"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/About/title" value="IDS_ST_BODY_ABOUT_DEVICE"/>
+
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Apps/icon-path" value="apps.svg"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Apps/icon-color" value="#7F2982,#922F95"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Apps/title" value="IDS_ST_BODY_APPLICATIONS"/>
+
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Storage/icon-path" value="storage.svg"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Storage/icon-color" value="#7F2982,#922F95"/>
+  <metadata key="http://tizen.org/metadata/ui-gadget/menu/Storage/title" value="IDS_ST_BODY_DEVICE_STORAGE"/>
 </manifest>