Added the following Changes: 19/280719/3
authortarun.mahay <tarun.mahay@samsung.com>
Fri, 2 Sep 2022 10:19:32 +0000 (15:49 +0530)
committertarun.mahay <tarun.mahay@samsung.com>
Fri, 2 Sep 2022 15:36:55 +0000 (21:06 +0530)
1. App Rotation and Border UI.
2. Background of App Icons.

Change-Id: I3e4d8ec462dc1ef985423f7f1ab8f0e9f5b96992
Signed-off-by: tarun.mahay <tarun.mahay@samsung.com>
Apps/Apps.cs
Apps/Apps.csproj
Apps/Common/DeviceInfo.cs
Apps/Models/AppInfoModel.cs
Apps/ViewManager.cs
Apps/ViewModels/AppInfoViewModel.cs
Apps/Views/AppView.cs
Apps/res/images/default_gradient.png [new file with mode: 0644]
packaging/org.tizen.Apps-1.0.0.tpk

index a7186183d955aa9094dd65c31d1f3299869c9ad1..f85eabaf22673f71c6f05809016bb5761b587682 100644 (file)
@@ -1,4 +1,5 @@
-using Tizen.NUI;
+using System.Collections.Generic;
+using Tizen.NUI;
 using Apps.Common;
 
 namespace Apps
@@ -9,8 +10,10 @@ namespace Apps
         //Current height of tray application is 360. This needs to be updated if height of tray application changes in future.
         private const int TrayApplicationHeight = 360;
         private ViewManager viewManager;
+        private Window window;
+        private Window.WindowOrientation orientation;
 
-        public Program() : base(ThemeOptions.PlatformThemeEnabled)
+        public Program() : base( new Size2D(960, 540), new Position2D(480 , 170), ThemeOptions.PlatformThemeEnabled, new DefaultBorder())
         {
         }
 
@@ -18,38 +21,70 @@ namespace Apps
         {
             Tizen.Log.Info(Resources.LogTag, "Program OnCreate");
             base.OnCreate();
-            Window window = Window.Instance;
+            window = Window.Instance;
             window.SetTransparency(true);
-            int width, height, positionX, positionY;
+            List<Window.WindowOrientation> list = new List<Window.WindowOrientation>
+            {
+                Window.WindowOrientation.Landscape,
+                Window.WindowOrientation.LandscapeInverse,
+                Window.WindowOrientation.NoOrientationPreference,
+                Window.WindowOrientation.Portrait,
+                Window.WindowOrientation.PortraitInverse,
+            };
+
+            window.SetAvailableOrientations(list);
+            orientation = window.GetCurrentOrientation();
+            UpdateWindowSize();
+            UpdateWindowPosition();
+            window.BackgroundColor = Color.Transparent;
+            window.KeyEvent += OnKeyEvent;
+            window.Resized += OnWindowResized;
+            viewManager = new ViewManager(window);
+            Tizen.Log.Info(Resources.LogTag, "Show Window");
+        }
+
+        protected override void OnTerminate()
+        {
+            Tizen.Log.Info(Resources.LogTag, "On App Terminate");
+            viewManager.CleanUp();
+            base.OnTerminate();
+        }
+
+        private void UpdateWindowSize()
+        {
+            int width, height;
             if (DeviceInfo.IsPortrait)
             {
                 width = DeviceInfo.DisplayHeight / 2;
                 height = DeviceInfo.DisplayWidth / 2;
-                positionX = (DeviceInfo.DisplayWidth - width) / 2;
-                positionY = (DeviceInfo.DisplayHeight - height) / 2;
             }
             else
             {
                 width = DeviceInfo.DisplayWidth / 2;
                 height = DeviceInfo.DisplayHeight / 2;
-                positionX = (DeviceInfo.DisplayWidth - width) / 2;
-                positionY = DeviceInfo.DisplayHeight - height - TrayApplicationHeight.SpToPx();
             }
-            window.WindowPosition = new Position2D(positionX, positionY);
             window.WindowSize = new Size2D(width, height);
-            window.BackgroundColor = Color.Transparent;
-            window.KeyEvent += OnKeyEvent;
-            viewManager = new ViewManager(window);
-            Tizen.Log.Info(Resources.LogTag, "Show Window");
+            Tizen.Log.Info(Resources.LogTag, "width is: "+ window.WindowSize.Width);
+            Tizen.Log.Info(Resources.LogTag, "height is: " + window.WindowSize.Height);
         }
 
-        protected override void OnTerminate()
+        private void UpdateWindowPosition()
         {
-            Tizen.Log.Info(Resources.LogTag, "On App Terminate");
-            viewManager.CleanUp();
-            base.OnTerminate();
+            int positionX, positionY;
+            if (DeviceInfo.IsPortrait)
+            {
+                positionX = (DeviceInfo.DisplayWidth - window.WindowSize.Width) / 2;
+                positionY = (DeviceInfo.DisplayHeight - window.WindowSize.Height) / 2;
+            }
+            else
+            {
+                positionX = (DeviceInfo.DisplayWidth - window.WindowSize.Width) / 2;
+                positionY = DeviceInfo.DisplayHeight - window.WindowSize.Height - TrayApplicationHeight.SpToPx();
+            }
+            window.WindowPosition = new Position2D(positionX, positionY);
+            Tizen.Log.Info(Resources.LogTag, "position X is: " + window.WindowPosition.X);
+            Tizen.Log.Info(Resources.LogTag, "position Y is: " + window.WindowPosition.Y);
         }
-
         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
         {
             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
@@ -58,6 +93,21 @@ namespace Apps
             }
         }
 
+        private void OnWindowResized(object sender, Window.ResizedEventArgs e)
+        {
+            Window.WindowOrientation newOrientation = window.GetCurrentOrientation();
+            Tizen.Log.Debug(Resources.LogTag, "Resized Event");
+            if (orientation != newOrientation)
+            {
+                Tizen.Log.Debug(Resources.LogTag, "orientation changed");
+                DeviceInfo.UpdateDeviceInfo();
+                orientation = newOrientation;
+                UpdateWindowSize();
+                UpdateWindowPosition();
+            }
+            viewManager.UpdateAppView();
+        }
+
         static void Main(string[] args)
         {
             Tizen.Log.Info(Resources.LogTag, "Main statrted");
index 9dfc20a2694ec754d0215aa1dd26a887c7c18764..64d7785cadf758f5d2eb21505b8477b93889004e 100644 (file)
@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <TargetFramework>tizen10.0</TargetFramework>
       <TargetFrameworkIdentifier>Tizen</TargetFrameworkIdentifier>
     <AssemblyName>Apps</AssemblyName>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>None</DebugType>
   </PropertyGroup>
-  <ItemGroup>
-    <Compile Remove="res\images\**" />
-    <EmbeddedResource Remove="res\images\**" />
-    <None Remove="res\images\**" />
-  </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Tizen.NET" Version="10.0.0.17305" />
+    <PackageReference Include="Tizen.NET" Version="10.0.0.17404" />
     <PackageReference Include="Tizen.NET.Sdk" Version="1.1.8" />
   </ItemGroup>
 
index 8ad1e925ef2e9079641b59f8eacc2121761873e9..7151e6eacbbcb9a2fc2e8e83b534d625cd47c905 100644 (file)
@@ -1,4 +1,5 @@
-using Tizen.System;
+using Tizen.NUI;
+using Tizen.System;
 
 namespace Apps.Common
 {
@@ -6,6 +7,7 @@ namespace Apps.Common
     {
         private static int width;
         private static int height;
+        private static Window.WindowOrientation orientation;
         private const string WidthKey = "tizen.org/feature/screen.width";
         private const string HeightKey = "tizen.org/feature/screen.height";
 
@@ -13,13 +15,40 @@ namespace Apps.Common
         {
             bool isWidthAvailable = Information.TryGetValue(WidthKey, out width);
             bool isHeightAvailable = Information.TryGetValue(HeightKey, out height);
-            if(isHeightAvailable == false || isWidthAvailable == false)
+            if (isHeightAvailable == false || isWidthAvailable == false)
             {
                 width = 1920;
                 height = 1080;
                 Tizen.Log.Debug(Resources.LogTag, "Width and height are not available , setting default size as 1920 x 1080");
             }
-            IsPortrait = width < height;
+            orientation = Window.Instance.GetCurrentOrientation();
+            IsPortrait = orientation == Window.WindowOrientation.Portrait || orientation == Window.WindowOrientation.PortraitInverse;
+        }
+
+        public static void UpdateDeviceInfo()
+        {
+            Window.WindowOrientation currentOrientation = Window.Instance.GetCurrentOrientation();
+            if (orientation == Window.WindowOrientation.Portrait || orientation == Window.WindowOrientation.PortraitInverse)
+            {
+                if(currentOrientation == Window.WindowOrientation.Landscape || currentOrientation == Window.WindowOrientation.LandscapeInverse)
+                {
+                    ToggleOrientation();
+                }
+            }
+            else
+            {
+                if (currentOrientation == Window.WindowOrientation.Portrait || currentOrientation == Window.WindowOrientation.PortraitInverse)
+                {
+                    ToggleOrientation();
+                }
+            }
+            orientation = currentOrientation;
+        }
+
+        private static void ToggleOrientation()
+        {
+            (width, height) = (height, width);
+            IsPortrait = !IsPortrait;
         }
 
         public static bool IsPortrait { get; private set; }
index d40f8bd51f8cb4836191b523e5312d4712b9df2a..12d89f5531d1fa7297a0989ab2c80618fa8eb44f 100644 (file)
@@ -1,5 +1,8 @@
-using Apps.Common;
-
+using System;
+using System.Collections.Generic;
+using Tizen.NUI;
+using Tizen.Applications;
+using Apps.Common;
 namespace Apps.Models
 {
     class AppInfoModel : PropertyNotifier
@@ -9,6 +12,7 @@ namespace Apps.Models
             Name = name;
             ApplicationId = applicationId;
             IconUrl = url;
+            SetExtractedBackground(url);
         }
 
         public string Name { get; internal set; }
@@ -22,5 +26,111 @@ namespace Apps.Models
             get => iconUrl;
             set => SetProperty(ref iconUrl, value);
         }
+
+        private PropertyMap iconBackground;
+
+        public PropertyMap IconBackground
+        {
+            get => iconBackground;
+            set => SetProperty(ref iconBackground, value);
+        }
+
+        private void SetDefaultBackground()
+        {
+            ImageVisual imageVisual = new ImageVisual()
+            {
+                URL = Application.Current.DirectoryInfo.Resource + "images/" + "default_gradient.png",
+            };
+            IconBackground = imageVisual.OutputVisualMap;
+        }
+
+        private void SetGradientBackground(PropertyArray stopColor)
+        {
+            GradientVisual gradientVisual = new GradientVisual()
+            {
+                StartPosition = new Vector2(0.0f, -1.0f),
+                EndPosition = new Vector2(0.0f, 1.0f),
+                StopColor = stopColor,
+                SpreadMethod = GradientVisualSpreadMethodType.Pad,
+            };
+            IconBackground = gradientVisual.OutputVisualMap;
+        }
+
+        private PropertyArray GetGradientStopColors(Palette palette)
+        {
+            PropertyArray propertyArray = new PropertyArray();
+            if (palette == null)
+            {
+                Tizen.Log.Error(Resources.LogTag, "Color palette from background is null");
+                return propertyArray;
+            }
+
+            Palette.Swatch lightMutedSwatch = palette.GetLightMutedSwatch();
+            Palette.Swatch darkMutedSwatch = palette.GetDarkMutedSwatch();
+            if (lightMutedSwatch != null && darkMutedSwatch != null)
+            {
+                propertyArray.PushBack(new PropertyValue(lightMutedSwatch.GetRgb()));
+                propertyArray.PushBack(new PropertyValue(darkMutedSwatch.GetRgb()));
+                return propertyArray;
+            }
+
+            Palette.Swatch lightVibrantSwatch = palette.GetLightVibrantSwatch();
+            Palette.Swatch darkVibrantSwatch = palette.GetDarkVibrantSwatch();
+            if (lightVibrantSwatch != null && darkVibrantSwatch != null)
+            {
+                propertyArray.PushBack(new PropertyValue(lightVibrantSwatch.GetRgb()));
+                propertyArray.PushBack(new PropertyValue(darkVibrantSwatch.GetRgb()));
+                return propertyArray;
+            }
+
+            Palette.Swatch mutedSwatch = palette.GetMutedSwatch();
+            Palette.Swatch vibrantSwatch = palette.GetVibrantSwatch();
+            if (mutedSwatch != null && vibrantSwatch != null)
+            {
+                propertyArray.PushBack(new PropertyValue(mutedSwatch.GetRgb()));
+                propertyArray.PushBack(new PropertyValue(vibrantSwatch.GetRgb()));
+                return propertyArray;
+            }
+
+            IReadOnlyCollection<Palette.Swatch> swatches = palette.GetSwatches();
+            foreach (Palette.Swatch swatch in swatches)
+            {
+                if (propertyArray.Count() >= 2)
+                {
+                    return propertyArray;
+                }
+                if (swatch != null)
+                {
+                    propertyArray.PushBack(new PropertyValue(swatch.GetRgb()));
+                }
+            }
+            return propertyArray;
+        }
+
+        public async void SetExtractedBackground(string path)
+        {
+            Tizen.Log.Debug(Resources.LogTag, "Path for the color image thumbnail" + path);
+            PixelBuffer pixelBuffer = ImageLoader.LoadImageFromFile(path);
+            Palette palette = null;
+            try
+            {
+                palette = await Palette.GenerateAsync(pixelBuffer);
+            }
+            catch (ArgumentNullException e)
+            {
+                Tizen.Log.Error(Resources.LogTag, "ArgumentNullException: " + e.Message);
+            }
+            PropertyArray stopColor = GetGradientStopColors(palette);
+            if (stopColor.Count() < 2)
+            {
+                Tizen.Log.Info(Resources.LogTag, "Palette or palatte values not valid, adding default gradient");
+                SetDefaultBackground();
+            }
+            else
+            {
+                Tizen.Log.Info(Resources.LogTag, "setting palette color");
+                SetGradientBackground(stopColor);
+            }
+        }
     }
 }
index 1abe1421358dba9fbcf8ab52c1d639f9ee276afd..468ec1acb7d348f43eb3b87e11951247470bf4aa 100644 (file)
@@ -1,8 +1,9 @@
 using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
 using System.Linq;
+using System.Threading.Tasks;
+using System.Collections.Generic;
 using System.IO;
+using Tizen.NUI;
 using Tizen.NUI.Xaml;
 using Tizen.Applications;
 using Tizen.NUI;
@@ -27,7 +28,6 @@ namespace Apps
             appViewModel = new AppViewModel();
             appView = new AppView(appViewModel);
             window.Add(appView);
-            window.Resized += OnResize;
             UpdateViewModel(appListTask);
 
             PackageManager.InstallProgressChanged += OnInstallProgressChanged;
@@ -36,12 +36,16 @@ namespace Apps
             ThemeManager.ThemeChanged += OnThemeChanged;
         }
 
+        public void UpdateAppView()
+        {
+            appView.Size2D = new Size2D(Window.Instance.Size.Width, Window.Instance.Size.Height);
+        }
         public void CleanUp()
         {
             PackageManager.InstallProgressChanged -= OnInstallProgressChanged;
             PackageManager.UninstallProgressChanged -= OnUninstallProgressChanged;
             ThemeManager.ThemeChanged -= OnThemeChanged;
-            appView?.Dispose();            
+            appView?.Dispose();
         }
 
         private void OnThemeChanged(object sender, ThemeChangedEventArgs e)
@@ -53,11 +57,6 @@ namespace Apps
             }
         }
 
-        private void OnResize(object sender, Window.ResizedEventArgs e)
-        {
-            appView.SizeHeight = Window.Instance.Size.Height - 48.SpToPx();
-        }
-
         private Task<IEnumerable<ApplicationInfo>> CreateAppList()
         {
             ApplicationInfoFilter appInfoFilter = new ApplicationInfoFilter();
index 3008653cc6ac9cdd70d43e43ce63e513b57f9874..09f6741669e20d8544ee06bbb454d6e5b7d618ab 100644 (file)
@@ -1,5 +1,6 @@
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Threading;
 using Tizen.Applications;
 using Apps.Common;
 using Apps.Models;
@@ -23,6 +24,7 @@ namespace Apps.ViewModels
                 }
                 AppInfoModel appInfoModel = new AppInfoModel(appInfo.Label, appInfo.ApplicationId, appInfo.IconPath);
                 Add(appInfoModel);
+                Thread.Sleep(100);
                 Tizen.Log.Info(Resources.LogTag, "App name is " + appInfo.Label);
                 Tizen.Log.Info(Resources.LogTag, "Application ID is " + appInfo.ApplicationId);
             }
index 9c5daf7aa28659d732637cf4ad9fb7c905816b16..dd988647fa303abbd5ddc3136e743c61ffe1e57b 100644 (file)
@@ -26,8 +26,7 @@ namespace Apps.Views
             StyleName = "TrayBackGround";
             ThemeChangeSensitive = true;
             CornerRadius = new Vector4(24, 24, 24, 24);
-            WidthSpecification = LayoutParamPolicies.MatchParent;
-            HeightSpecification = Window.Instance.Size.Height - 48.SpToPx();
+            Size2D = new Size2D(Window.Instance.Size.Width, Window.Instance.Size.Height);
             ItemsLayouter = new GridLayouter();
             ScrollingDirection = Direction.Vertical;
             SelectionMode = ItemSelectionMode.Single;
@@ -37,6 +36,7 @@ namespace Apps.Views
                 AppItemLayout item = new AppItemLayout();
                 item.Label.SetBinding(TextLabel.TextProperty, "Name");
                 item.Icon.SetBinding(ImageView.ResourceUrlProperty, "IconUrl");
+                item.IconBackground.SetBinding(BackgroundProperty, "IconBackground");
                 return item;
             });
             Header = GetHeader();
diff --git a/Apps/res/images/default_gradient.png b/Apps/res/images/default_gradient.png
new file mode 100644 (file)
index 0000000..ceb1deb
Binary files /dev/null and b/Apps/res/images/default_gradient.png differ
index 258c36066af72252799e75e5bad74162e4f79e5d..47ae91c731c5d723e4311269dcdd3ff869090a6f 100644 (file)
Binary files a/packaging/org.tizen.Apps-1.0.0.tpk and b/packaging/org.tizen.Apps-1.0.0.tpk differ