2016-03-22 23:02:25 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Windows.Foundation;
|
|
|
|
|
using Windows.Graphics.Display;
|
|
|
|
|
using Windows.UI.Xaml;
|
2017-03-07 22:56:24 +03:00
|
|
|
|
using Xamarin.Forms.Internals;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Platform.UWP
|
|
|
|
|
{
|
|
|
|
|
internal class WindowsDeviceInfo : DeviceInfo
|
|
|
|
|
{
|
|
|
|
|
DisplayInformation _information;
|
|
|
|
|
bool _isDisposed;
|
|
|
|
|
|
|
|
|
|
public WindowsDeviceInfo()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Screen size and DPI can change at any time
|
|
|
|
|
_information = DisplayInformation.GetForCurrentView();
|
|
|
|
|
_information.OrientationChanged += OnOrientationChanged;
|
|
|
|
|
CurrentOrientation = GetDeviceOrientation(_information.CurrentOrientation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Size PixelScreenSize
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
double scaling = ScalingFactor;
|
|
|
|
|
Size scaled = ScaledScreenSize;
|
|
|
|
|
double width = Math.Round(scaled.Width * scaling);
|
|
|
|
|
double height = Math.Round(scaled.Height * scaling);
|
|
|
|
|
|
|
|
|
|
return new Size(width, height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Size ScaledScreenSize
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
Rect windowSize = Window.Current.Bounds;
|
|
|
|
|
return new Size(windowSize.Width, windowSize.Height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override double ScalingFactor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-12-22 02:29:31 +03:00
|
|
|
|
return ((int)_information.ResolutionScale) / 100d;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (_isDisposed)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-08-02 23:54:57 +03:00
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
|
|
|
|
_information.OrientationChanged -= OnOrientationChanged;
|
|
|
|
|
_information = null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
|
_isDisposed = true;
|
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DeviceOrientation GetDeviceOrientation(DisplayOrientations orientations)
|
|
|
|
|
{
|
|
|
|
|
switch (orientations)
|
|
|
|
|
{
|
|
|
|
|
case DisplayOrientations.Landscape:
|
|
|
|
|
case DisplayOrientations.LandscapeFlipped:
|
|
|
|
|
return DeviceOrientation.Landscape;
|
|
|
|
|
|
|
|
|
|
case DisplayOrientations.Portrait:
|
|
|
|
|
case DisplayOrientations.PortraitFlipped:
|
|
|
|
|
return DeviceOrientation.Portrait;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
case DisplayOrientations.None:
|
|
|
|
|
return DeviceOrientation.Other;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnOrientationChanged(DisplayInformation sender, object args)
|
|
|
|
|
{
|
|
|
|
|
CurrentOrientation = GetDeviceOrientation(sender.CurrentOrientation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|