1. App Rotation and Border UI.
2. Background of App Icons.
Change-Id: I3e4d8ec462dc1ef985423f7f1ab8f0e9f5b96992
Signed-off-by: tarun.mahay <tarun.mahay@samsung.com>
-using Tizen.NUI;
+using System.Collections.Generic;
+using Tizen.NUI;
using Apps.Common;
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())
{
}
{
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"))
}
}
+ 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");
<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>
-using Tizen.System;
+using Tizen.NUI;
+using Tizen.System;
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";
{
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; }
-using Apps.Common;
-
+using System;
+using System.Collections.Generic;
+using Tizen.NUI;
+using Tizen.Applications;
+using Apps.Common;
namespace Apps.Models
{
class AppInfoModel : PropertyNotifier
Name = name;
ApplicationId = applicationId;
IconUrl = url;
+ SetExtractedBackground(url);
}
public string Name { get; internal set; }
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);
+ }
+ }
}
}
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;
appViewModel = new AppViewModel();
appView = new AppView(appViewModel);
window.Add(appView);
- window.Resized += OnResize;
UpdateViewModel(appListTask);
PackageManager.InstallProgressChanged += OnInstallProgressChanged;
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)
}
}
- 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();
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Threading;
using Tizen.Applications;
using Apps.Common;
using Apps.Models;
}
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);
}
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;
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();