Adding Rotation of tray and Background Property to App Icons. 05/280805/1 accepted/tizen/unified/20220908.172938
authorshivamv <shivam.v2@samsung.com>
Mon, 5 Sep 2022 08:46:58 +0000 (14:16 +0530)
committershivamv <shivam.v2@samsung.com>
Mon, 5 Sep 2022 08:46:58 +0000 (14:16 +0530)
Change-Id: I0114a8d9cf83d5cf770bd97766b6d668f23d8e8d
Signed-off-by: shivamv <shivam.v2@samsung.com>
TrayApplication/Common/DeviceInfo.cs [changed mode: 0644->0755]
TrayApplication/Core/AppLauncher.cs [changed mode: 0644->0755]
TrayApplication/Models/AppInfoModel.cs [changed mode: 0644->0755]
TrayApplication/TrayApplication.cs [changed mode: 0644->0755]
TrayApplication/TrayApplication.csproj [changed mode: 0644->0755]
TrayApplication/ViewModels/ApplicationViewModel.cs [changed mode: 0644->0755]
TrayApplication/ViewModels/QuickAccessViewModel.cs [changed mode: 0644->0755]
TrayApplication/Views/ApplicationsView.cs [changed mode: 0644->0755]
TrayApplication/Views/MainView.cs [changed mode: 0644->0755]
TrayApplication/res/images/default_gradient.png [new file with mode: 0755]
packaging/org.tizen.TrayApplication-1.0.0.tpk

old mode 100644 (file)
new mode 100755 (executable)
index 248a18a..7874a1b
@@ -1,4 +1,5 @@
-using Tizen.System;
+using Tizen.NUI;
+using Tizen.System;
 
 namespace TrayApplication.Common
 {
@@ -6,6 +7,7 @@ namespace TrayApplication.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";
 
@@ -15,11 +17,38 @@ namespace TrayApplication.Common
             bool isHeightAvailable = Information.TryGetValue(HeightKey, out height);
             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");
+                width = 1280;
+                height = 720;
+                Tizen.Log.Debug(Resources.LogTag, "Width and height are not available , setting default size as 1280 x 720");
             }
-            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; }
old mode 100644 (file)
new mode 100755 (executable)
index 3b88850..f53d68d
@@ -1,9 +1,13 @@
-using Tizen.Applications;
+using System;
+using Tizen.Applications;
 
 namespace TrayApplication.Core
 {
     static class AppLauncher
     {
+
+        public static event EventHandler<EventArgs> AppLaunched;
+
         public static void LaunchApplication(string id)
         {
             AppControl appControl = new AppControl()
@@ -12,6 +16,7 @@ namespace TrayApplication.Core
                 Operation = id == "org.tizen.homescreen-efl" ? AppControlOperations.Main : AppControlOperations.Default,
             };
             AppControl.SendLaunchRequest(appControl);
+            AppLaunched.Invoke(new object(), new EventArgs());
         }
     }
 }
old mode 100644 (file)
new mode 100755 (executable)
index 2c96be2..13d917c
@@ -1,4 +1,7 @@
-using System.Windows.Input;
+using System;
+using System.Collections.Generic;
+using System.Windows.Input;
+using Tizen.NUI;
 using Tizen.NUI.Binding;
 using TrayApplication.Common;
 using TrayApplication.Core;
@@ -26,6 +29,13 @@ namespace TrayApplication.Models
             set => SetProperty(ref iconUrl, value);
         }
 
+        private PropertyMap iconBackground;
+        public PropertyMap IconBackground
+        {
+            get => iconBackground;
+            set => SetProperty(ref iconBackground, value);
+        }
+
         private ICommand appSelectCommand;
         public ICommand AppSelectCommand
         {
@@ -37,5 +47,103 @@ namespace TrayApplication.Models
         {
             AppLauncher.LaunchApplication(ApplicationId);
         }
+
+        private void SetDefaultBackground()
+        {
+            ImageVisual imageVisual = new ImageVisual()
+            {
+                URL = Resources.GetImagePath() + "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);
+            }
+        }
     }
 }
old mode 100644 (file)
new mode 100755 (executable)
index dd2896b..c8ecd44
@@ -1,4 +1,6 @@
 using System;
+using System.Collections.Generic;
+using System.Text;
 using Tizen.NUI;
 using Tizen.NUI.WindowSystem.Shell;
 using TrayApplication.Views;
@@ -14,42 +16,57 @@ namespace TrayApplication
         }
 
         private const int WindowHeight = 313;
+        private const int SwipeUpLength = 5;
+        private const int SwipeDownLength = 60;
+        private const int MinimizedWindowHeight = 36;
+        private const int BottomMargin = 48;
         private int positionX;
         private int positionY;
         private bool isTrayVisible = true;
 
         private Window window;
         private MainView mainView;
-        private TizenShell tzShell;
+        private TizenShell tizenShell;
         private SoftkeyService softkeyService;
+        private Window.WindowOrientation windowOrientation;
 
         private float touchStartPosition;
         protected override void OnCreate()
         {
             Tizen.Log.Info(Resources.LogTag, "Program OnCreate");
             base.OnCreate();
+
             window = GetDefaultWindow();
-            int sizeWidth = (int)((DeviceInfo.IsPortrait ? 0.6 : 0.5) * DeviceInfo.DisplayWidth);
-            int sizeHeight = WindowHeight.SpToPx();
-            positionX = (int)((DeviceInfo.IsPortrait ? 0.2 : 0.25) * DeviceInfo.DisplayWidth);
-            positionY = DeviceInfo.DisplayHeight;
-            window.WindowSize = new Size2D(sizeWidth, sizeHeight);
-            window.WindowPosition = new Position2D(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);
+            windowOrientation = window.GetCurrentOrientation();
+            Tizen.Log.Info(Resources.LogTag, "Orientation: " + windowOrientation);
+
+            UpdateWindowDimensions();
             window.BackgroundColor = Color.Transparent;
             window.SetTransparency(true);
 
-            tzShell = new TizenShell();
-            softkeyService = new SoftkeyService(tzShell, window);
+            tizenShell = new TizenShell();
+            softkeyService = new SoftkeyService(tizenShell, window);
             softkeyService.Show();
 
             window.KeyEvent += OnKeyEvent;
             window.TouchEvent += OnTouch;
+            window.Resized += OnWindowResized;
             AppScoreDataBase.InitializeDataBase();
 
             mainView = new MainView();
             window.Add(mainView);
             mainView.RemovedFromWindow += MainViewRemovedFromWindow;
             mainView.VisibilityChanged += MainViewVisibilityChanged;
+            AppLauncher.AppLaunched += OnAppLaunched;
             mainView.HideView();
             Tizen.Log.Info(Resources.LogTag, "Tray Application Created");
         }
@@ -61,6 +78,34 @@ namespace TrayApplication
             base.OnTerminate();
         }
 
+        private void UpdateWindowDimensions()
+        {
+            int sizeWidth = (int)((DeviceInfo.IsPortrait ? 0.6 : 0.5) * DeviceInfo.DisplayWidth);
+            int sizeHeight = WindowHeight.SpToPx();
+            positionX = (int)((DeviceInfo.IsPortrait ? 0.2 : 0.25) * DeviceInfo.DisplayWidth);
+            positionY = isTrayVisible ? DeviceInfo.DisplayHeight - (WindowHeight + BottomMargin).SpToPx() : DeviceInfo.DisplayHeight - MinimizedWindowHeight.SpToPx();
+            window.WindowPosition = new Position2D(positionX, positionY);
+            window.WindowSize = new Size2D(sizeWidth, sizeHeight);
+        }
+
+        private void OnAppLaunched(object sender, EventArgs e)
+        {
+            mainView?.HideView();
+        }
+
+        private void OnWindowResized(object sender, Window.ResizedEventArgs e)
+        {
+            Tizen.Log.Info(Resources.LogTag, "Tray Resized");
+            Window.WindowOrientation currentWindowOrientation = window.GetCurrentOrientation();
+            if (windowOrientation != currentWindowOrientation)
+            {
+                DeviceInfo.UpdateDeviceInfo();
+                windowOrientation = currentWindowOrientation;
+                UpdateWindowDimensions();
+                mainView.UpdateView();
+            }
+        }
+
         private void MainViewRemovedFromWindow(object sender, EventArgs e)
         {
             Tizen.Log.Info(Resources.LogTag, "Main View Removed");
@@ -71,17 +116,9 @@ namespace TrayApplication
         private void MainViewVisibilityChanged(object sender, Tizen.NUI.BaseComponents.View.VisibilityChangedEventArgs e)
         {
             Tizen.Log.Info(Resources.LogTag, "Main View Visibility Changed");
-            if (isTrayVisible == true)
-            {
-                positionY = DeviceInfo.DisplayHeight - 36.SpToPx();
-                window.WindowPosition = new Position2D(positionX, positionY);
-            }
-            else
-            {
-                positionY = DeviceInfo.DisplayHeight - (WindowHeight + 48).SpToPx();
-                window.WindowPosition = new Position2D(positionX, positionY);
-            }
             isTrayVisible = !isTrayVisible;
+            positionY = isTrayVisible ? DeviceInfo.DisplayHeight - (WindowHeight + BottomMargin).SpToPx() : DeviceInfo.DisplayHeight - MinimizedWindowHeight.SpToPx();
+            window.WindowPosition = new Position2D(positionX, positionY);
         }
 
         private void OnTouch(object sender, Window.TouchEventArgs e)
@@ -96,7 +133,7 @@ namespace TrayApplication
                 if (e.Touch.GetState(0) == PointStateType.Finished)
                 {
                     float touchEndPosition = e.Touch.GetScreenPosition(0).Y;
-                    if (touchEndPosition - touchStartPosition >= 60.SpToPx())
+                    if (touchEndPosition - touchStartPosition >= SwipeDownLength.SpToPx())
                     {
                         if (mainView != null)
                         {
@@ -114,13 +151,13 @@ namespace TrayApplication
                 if (e.Touch.GetState(0) == PointStateType.Motion || e.Touch.GetState(0) == PointStateType.Finished)
                 {
                     float touchEndPosition = e.Touch.GetScreenPosition(0).Y;
-                    if (touchStartPosition - touchEndPosition >= 5.SpToPx())
+                    if (touchStartPosition - touchEndPosition >= SwipeUpLength.SpToPx())
                     {
                         if (mainView != null)
                         {
                             mainView.ShowView();
                         }
-                        touchStartPosition = 313.SpToPx();
+                        touchStartPosition = WindowHeight.SpToPx();
                     }
                 }
             }
old mode 100644 (file)
new mode 100755 (executable)
index 5e96be5..f0a9ee9
@@ -19,8 +19,8 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.7" />
-    <PackageReference Include="Tizen.NET" Version="10.0.0.17357" />
+    <PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.8" />
+    <PackageReference Include="Tizen.NET" Version="10.0.0.17411" />
     <PackageReference Include="Tizen.NET.Sdk" Version="1.1.8" />
   </ItemGroup>
 
old mode 100644 (file)
new mode 100755 (executable)
index 085efae..20589f8
@@ -1,5 +1,6 @@
 using System.Collections;
 using System.Collections.Generic;
+using System.Threading;
 using System.Windows.Input;
 using Tizen.Applications;
 using Tizen.NUI;
@@ -13,12 +14,20 @@ namespace TrayApplication.ViewModels
     class ApplicationViewModel : PropertyNotifier
     {
         Dictionary<string, int> appScoreData;
-        private readonly int appsCount;
+        Dictionary<string, AppInfoModel> appInfoModelDictionary;
+        private const string AppsId = "org.tizen.Apps";
+        private const int maxAppsPortrait = 4;
+        private const int maxAppsLandscape = 6;
+        private int appsCount;
+        private int maxAppsCount;
         public ApplicationViewModel(int appsCount)
         {
-            this.appsCount = appsCount;
+            maxAppsCount = DeviceInfo.IsPortrait ? maxAppsPortrait : maxAppsLandscape;
+            this.appsCount = appsCount < maxAppsCount ? appsCount : maxAppsCount;
             appScoreData = AppScoreDataBase.ReadData(appsCount - 1);
             BackgroundColor = ThemeManager.PlatformThemeId == Resources.DarkPlatformThemeId ? Resources.DarkApplicationsBackground : Resources.LightApplicationsBackground;
+            appInfoModelDictionary = new Dictionary<string, AppInfoModel>();
+            AddAppsApplication();
             AddButtonsInfo();
             AppRemoveCommand = new Command(OnAppRemove);
             AppScoreDataBase.OnDatabaseUpdate += OnDatabaseUpdate;
@@ -38,20 +47,40 @@ namespace TrayApplication.ViewModels
             UpdateButtonsInfo();
         }
 
+        private void AddAppsApplication()
+        {
+            AppInfoModel appsApp = new AppInfoModel("Apps", AppsId, Resources.GetCurrentThemePath() + "apps.png");
+            appsApp.SetExtractedBackground(string.Empty);
+            Thread.Sleep(100);
+            appInfoModelDictionary.Add(AppsId, appsApp);
+        }
+
+        private void CreateAppInfoModel(string appId)
+        {
+            ApplicationInfo appInfo = new ApplicationInfo(appId);
+            AppInfoModel appInfoModel = new AppInfoModel(appInfo.Label, appId, appInfo.IconPath);
+            appInfoModel.SetExtractedBackground(appInfoModel.IconUrl);
+            appInfoModelDictionary.Add(appId, appInfoModel);
+            appInfo.Dispose();
+        }
+
         private void AddButtonsInfo()
         {
             List<object> buttons = new List<object>();
             foreach (var item in appScoreData)
             {
-                ApplicationInfo appInfo = new ApplicationInfo(item.Key);
-                buttons.Add(new AppInfoModel(appInfo.Label, item.Key, appInfo.IconPath));
-                appInfo.Dispose();
+                if (appInfoModelDictionary.ContainsKey(item.Key) == false)
+                {
+                    CreateAppInfoModel(item.Key);
+                }
+                Thread.Sleep(100);
+                buttons.Add(appInfoModelDictionary[item.Key]);
             }
-            buttons.Add(new AppInfoModel("Apps", "org.tizen.Apps", Resources.GetCurrentThemePath() + "apps.png"));
+            buttons.Add(appInfoModelDictionary[AppsId]);
             ButtonsInfo = buttons;
         }
 
-        public void UpdateButtonsInfo()
+        private void UpdateButtonsInfo()
         {
             appScoreData.Clear();
             appScoreData = AppScoreDataBase.ReadData(appsCount - 1);
@@ -59,6 +88,13 @@ namespace TrayApplication.ViewModels
             AddButtonsInfo();
         }
 
+        public void UpdateViewModel(int count)
+        {
+            maxAppsCount = DeviceInfo.IsPortrait ? maxAppsPortrait : maxAppsLandscape;
+            appsCount = count < maxAppsCount ? count : maxAppsCount;
+            UpdateButtonsInfo();
+        }
+
         public void UpdateTheme()
         {
             BackgroundColor = ThemeManager.PlatformThemeId == Resources.DarkPlatformThemeId ? Resources.DarkApplicationsBackground : Resources.LightApplicationsBackground;
old mode 100644 (file)
new mode 100755 (executable)
index da4529c..9b17f1b
@@ -35,8 +35,8 @@ namespace TrayApplication.ViewModels
                 new AppInfoModel(AppNames[0], "org.tizen.homescreen-efl", imagePath + AppNames[0] + ".png"),
                 new AppInfoModel(AppNames[1], "org.tizen.setting", imagePath + AppNames[1] + ".png"),
                 new AppInfoModel(AppNames[2], "org.tizen.volume", imagePath + AppNames[2] + ".png"),
-                new AppInfoModel(AppNames[3], "org.tizen.quickpanel", imagePath + AppNames[3] + ".png"),
-                new AppInfoModel(AppNames[5], "org.tizen.powerkey-syspopup", imagePath + AppNames[5] + ".png")
+                //new AppInfoModel(AppNames[3], "org.tizen.quickpanel", imagePath + AppNames[3] + ".png"), //Will be added Later
+                //new AppInfoModel(AppNames[5], "org.tizen.powerkey-syspopup", imagePath + AppNames[5] + ".png") //Will be added Later
             };
             ButtonsInfo = buttons;
             Tizen.Log.Info(Resources.LogTag, "Done Adding ButtonsInfo");
old mode 100644 (file)
new mode 100755 (executable)
index bcdd0c9..fe27b7c
@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Collections;
+using System.Threading;
 using System.Windows.Input;
 using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
@@ -15,11 +16,15 @@ namespace TrayApplication.Views
         public event EventHandler<EventArgs> RemoveModeToggled;
 
         private const int ApplicationViewHeight = 189;
+        private const int IconGap = 16;
         private List<AppItemView> appIcons;
-        private readonly int maxAppsCount;
         private int currentAppsCount;
         private AlertDialog removePopup;
         private Window removePopupWindow;
+        private Window.WindowOrientation popupOrientation;
+        private bool removeMode;
+        private int removePopupWidth;
+        private int removePopupHeight;
 
         public static readonly BindableProperty AppListProperty = BindableProperty.Create(nameof(AppList), typeof(IEnumerable), typeof(ApplicationsView), null, propertyChanged: (bindable, oldValue, newValue) =>
         {
@@ -41,7 +46,7 @@ namespace TrayApplication.Views
 
         public static readonly BindableProperty AppRemoveCommandProperty = BindableProperty.Create(nameof(AppRemoveCommand), typeof(ICommand), typeof(ApplicationsView), null, propertyChanged: (bindable, oldValue, newValue) =>
         {
-            var instance = (ApplicationsView)bindable;
+            ApplicationsView instance = (ApplicationsView)bindable;
             if (oldValue != newValue)
             {
                 instance.appRemoveCommand = (ICommand)newValue;
@@ -49,7 +54,7 @@ namespace TrayApplication.Views
         },
         defaultValueCreator: (bindable) => ((ApplicationsView)bindable).appRemoveCommand);
 
-        public ApplicationsView(int appsCount) : base()
+        public ApplicationsView() : base()
         {
             Name = "ApplicationsView";
             WidthSpecification = LayoutParamPolicies.MatchParent;
@@ -60,12 +65,12 @@ namespace TrayApplication.Views
                 LinearOrientation = LinearLayout.Orientation.Horizontal,
                 HorizontalAlignment = HorizontalAlignment.Center,
                 VerticalAlignment = VerticalAlignment.Center,
-                CellPadding = new Size2D(16, 0).SpToPx()
+                CellPadding = new Size2D(IconGap, 0).SpToPx()
             };
-            maxAppsCount = appsCount;
             currentAppsCount = 0;
             appList = new List<object>();
-            CreateDefaultAppItems();
+            appIcons = new List<AppItemView>();
+            removeMode = false;
             Tizen.Log.Info(Resources.LogTag, "ApplicationsView");
         }
 
@@ -83,22 +88,7 @@ namespace TrayApplication.Views
                 appIcons[^1].AddTouchEvent();
                 appIcons[^1].Opacity = 1.0f;
             }
-        }
-
-        private void CreateDefaultAppItems()
-        {
-            appIcons = new List<AppItemView>();
-            for (int i = 0; i < maxAppsCount; i++)
-            {
-                AppItemView itemView = new AppItemView();
-                itemView.Hide();
-                itemView.LongPressed += (object sender, EventArgs e) =>
-                {
-                    RemoveModeToggled.Invoke(this, new EventArgs());
-                };
-                appIcons.Add(itemView);
-            }
-            Tizen.Log.Info(Resources.LogTag, "Icons Added");
+            this.removeMode = removeMode;
         }
 
         private IEnumerable appList;
@@ -117,42 +107,50 @@ namespace TrayApplication.Views
             set => SetValue(AppRemoveCommandProperty, value);
         }
 
-        private void UpdateAppIcons()
+        private void RemoveAppIcons()
+        {
+            while (appIcons.Count > 0)
+            {
+                AppItemView item = appIcons[0];
+                Remove(item);
+                appIcons.RemoveAt(0);
+                item.Dispose();
+            }
+        }
+
+        private void AddAppIcons()
         {
             List<object> appDataList = (List<object>)appList;
             int totalCount = appDataList.Count;
-
-            if (totalCount <= currentAppsCount)
+            foreach (object item in appDataList)
             {
-                for (int i = 0; i < totalCount; i++)
-                {
-                    appIcons[i].BindingContext = appDataList[i];
-                }
-                for (int i = totalCount; i < currentAppsCount; i++)
+                AppItemView itemView = new AppItemView();
+                itemView.LongPressed += (object sender, EventArgs e) =>
                 {
-                    AppItemView appItemView = appIcons[i];
-                    appItemView.Hide();
-                    Remove(appItemView);
-                }
+                    RemoveModeToggled.Invoke(this, new EventArgs());
+                };
+                appIcons.Add(itemView);
+                itemView.Show();
+                Add(itemView);
+                itemView.BindingContext = item;
+                itemView.Icon.SetBinding(ImageView.ResourceUrlProperty, "IconUrl");
+                itemView.Label.SetBinding(TextLabel.TextProperty, "Name");
+                itemView.SetBinding(AppItemView.AppSelectCommandProperty, "AppSelectCommand");
+                itemView.IconBackground.SetBinding(BackgroundProperty, "IconBackground");
             }
-            else
+            currentAppsCount = totalCount;
+            if (removeMode == true)
             {
-                for (int i = 0; i < currentAppsCount; i++)
-                {
-                    appIcons[i].BindingContext = appDataList[i];
-                }
-                for (int i = currentAppsCount; i < totalCount; i++)
-                {
-                    AppItemView itemView = appIcons[i];
-                    itemView.Show();
-                    Add(itemView);
-                    itemView.BindingContext = appDataList[i];
-                    itemView.Icon.SetBinding(ImageView.ResourceUrlProperty, "IconUrl");
-                    itemView.Label.SetBinding(TextLabel.TextProperty, "Name");
-                    itemView.SetBinding(AppItemView.AppSelectCommandProperty, "AppSelectCommand");
-                }
+                AddDeleteOption();
+                appIcons[^1].RemoveTouchEvent();
+                appIcons[^1].Opacity = 0.4f;
             }
-            currentAppsCount = totalCount;
+        }
+
+        private void UpdateAppIcons()
+        {
+            RemoveAppIcons();
+            AddAppIcons();
             Tizen.Log.Info(Resources.LogTag, "Icons Updated");
         }
 
@@ -175,15 +173,38 @@ namespace TrayApplication.Views
             }
         }
 
+        private void UpdateRemovePopupWindowDimensions()
+        {
+            Thread.Sleep(100);
+            removePopupWidth = (int)((DeviceInfo.IsPortrait ? DeviceInfo.DisplayHeight : DeviceInfo.DisplayWidth) * 0.36f);
+            removePopupHeight = 256.SpToPx();
+            int windowPositionX = ((DeviceInfo.DisplayWidth - removePopupWidth) / 2) - 144.SpToPx();
+            int windowPositionY = ((DeviceInfo.DisplayHeight - removePopupHeight) / 2) - 32.SpToPx();
+            removePopupWindow.WindowPosition = new Position2D(windowPositionX, windowPositionY);
+            removePopupWindow.WindowSize = new Size2D(removePopupWidth + 144.SpToPx(), removePopupHeight + 32.SpToPx());
+        }
+
         private void AddConfirmationPopup(object appIcon)
         {
             Tizen.Log.Info(Resources.LogTag, "Popup Added");
             if (removePopupWindow == null)
             {
-                int popupWidth = (int)((DeviceInfo.IsPortrait ? DeviceInfo.DisplayHeight : DeviceInfo.DisplayWidth) * 0.36f);
-                int popupHeight = 256.SpToPx();
-                int windowPositionX = ((DeviceInfo.DisplayWidth - popupWidth) / 2) - 144.SpToPx();
-                int windowPositionY = ((DeviceInfo.DisplayHeight - popupHeight) / 2) - 32.SpToPx();
+                removePopupWindow = new Window();
+                List<Window.WindowOrientation> list = new List<Window.WindowOrientation>
+                {
+                    Window.WindowOrientation.Landscape,
+                    Window.WindowOrientation.LandscapeInverse,
+                    Window.WindowOrientation.NoOrientationPreference,
+                    Window.WindowOrientation.Portrait,
+                    Window.WindowOrientation.PortraitInverse
+                };
+                removePopupWindow.SetAvailableOrientations(list);
+                popupOrientation = removePopupWindow.GetCurrentOrientation();
+                UpdateRemovePopupWindowDimensions();
+
+                removePopupWindow.SetTransparency(true);
+                removePopupWindow.BackgroundColor = Color.Transparent;
+
                 Button cancelButton = new Button("CancelButton");
                 Button deleteButton = new Button()
                 {
@@ -195,20 +216,15 @@ namespace TrayApplication.Views
                     removePopup = new AlertDialog()
                     {
                         StyleName = "AlertDialogBackground",
-                        Size2D = new Size2D(popupWidth, popupHeight),
+                        Size2D = new Size2D(removePopupWidth, removePopupHeight),
                         Title = "Delete App from the Tray",
                         Message = "Do you want to delete this app from the Tray? App won't be uninstalled from your device",
                         Actions = new List<Button>() { cancelButton, deleteButton },
                     };
                 }
-                removePopupWindow = new Window
-                {
-                    WindowPosition = new Position2D(windowPositionX, windowPositionY),
-                    WindowSize = new Size2D(popupWidth + 144.SpToPx(), popupHeight + 32.SpToPx()),
-                };
-                removePopupWindow.SetTransparency(true);
-                removePopupWindow.BackgroundColor = Color.Transparent;
                 removePopupWindow.Add(removePopup);
+                removePopupWindow.Resized += OnRemovePopupWindowResized;
+
                 cancelButton.Clicked += (object sender, ClickedEventArgs e) =>
                 {
                     RemoveConfirmationPopup();
@@ -221,6 +237,13 @@ namespace TrayApplication.Views
             }
         }
 
+        private void OnRemovePopupWindowResized(object sender, Window.ResizedEventArgs e)
+        {
+            UpdateRemovePopupWindowDimensions();
+            popupOrientation = removePopupWindow.GetCurrentOrientation();
+            Tizen.Log.Info(Resources.LogTag, "Orientation: " + popupOrientation);
+        }
+
         private void RemoveConfirmationPopup()
         {
             removePopupWindow.Remove(removePopup);
old mode 100644 (file)
new mode 100755 (executable)
index e2ea6de..128d844
@@ -11,6 +11,10 @@ namespace TrayApplication.Views
 {
     public class MainView : View
     {
+        private const int appIconWidth = 154;
+
+        private ApplicationViewModel applicationViewModel;
+        private QuickAccessViewModel quickAccessViewModel;
         private ApplicationsView applicationsView;
         private QuickAccessView quickAccessView;
         private Animation animation;
@@ -19,8 +23,7 @@ namespace TrayApplication.Views
         public MainView() : base()
         {
             Name = "MainView";
-            WidthSpecification = LayoutParamPolicies.MatchParent;
-            HeightSpecification = LayoutParamPolicies.MatchParent;
+            Size2D = new Size2D(Window.Instance.Size.Width, Window.Instance.Size.Height);
             CornerRadius = new Vector4(20, 20, 20, 20);
             BackgroundColor = Color.Transparent;
             Layout = new LinearLayout()
@@ -28,20 +31,23 @@ namespace TrayApplication.Views
                 LinearOrientation = LinearLayout.Orientation.Vertical
             };
             UpdateTheme(ThemeManager.PlatformThemeId);
-            int appsCount = Window.Instance.Size.Width / 154.SpToPx();
-            ApplicationViewModel applicationViewModel = new ApplicationViewModel(appsCount);
-            applicationsView = new ApplicationsView(appsCount);
+            int appsCount = Window.Instance.Size.Width / appIconWidth.SpToPx();
+
+            applicationViewModel = new ApplicationViewModel(appsCount);
+            applicationsView = new ApplicationsView();
             Add(applicationsView);
             applicationsView.BindingContext = applicationViewModel;
             applicationsView.SetBinding(BackgroundColorProperty, "BackgroundColor");
             applicationsView.SetBinding(ApplicationsView.AppListProperty, "ButtonsInfo");
             applicationsView.SetBinding(ApplicationsView.AppRemoveCommandProperty, "AppRemoveCommand");
-            QuickAccessViewModel quickAccessViewModel = new QuickAccessViewModel();
+
+            quickAccessViewModel = new QuickAccessViewModel();
             quickAccessView = new QuickAccessView();
             Add(quickAccessView);
             quickAccessView.BindingContext = quickAccessViewModel;
             quickAccessView.SetBinding(BackgroundColorProperty, "BackgroundColor");
             quickAccessView.SetBinding(QuickAccessView.AppListProperty, "ButtonsInfo");
+
             ThemeManager.ThemeChanged += OnThemeUpdated;
             removeMode = false;
             applicationsView.RemoveModeToggled += ApplicationsViewRemoveModeToggled;
@@ -76,6 +82,13 @@ namespace TrayApplication.Views
             Hide();
         }
 
+        public void UpdateView()
+        {
+            Size2D = new Size2D(Window.Instance.Size.Width, Window.Instance.Size.Height);
+            int appsCount = Window.Instance.Size.Width / 154.SpToPx();
+            applicationViewModel.UpdateViewModel(appsCount);
+        }
+
         private void SetTheme(string path)
         {
             try
diff --git a/TrayApplication/res/images/default_gradient.png b/TrayApplication/res/images/default_gradient.png
new file mode 100755 (executable)
index 0000000..ceb1deb
Binary files /dev/null and b/TrayApplication/res/images/default_gradient.png differ
index 5942c1cc981ef42c47057a33ced0b133b4623e4c..bf46a66696242dd758d747f0fc50205a04d23070 100755 (executable)
Binary files a/packaging/org.tizen.TrayApplication-1.0.0.tpk and b/packaging/org.tizen.TrayApplication-1.0.0.tpk differ