forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDualScreenService.cs
78 lines (60 loc) · 1.89 KB
/
TestDualScreenService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.DualScreen.UnitTests
{
internal class TestDualScreenService : IDualScreenService
{
Point _location;
public TestDualScreenService()
{
DeviceInfo = new TestDeviceInfo();
IsSpanned = false;
_location = Point.Zero;
}
public bool IsSpanned { get; set; }
public bool IsLandscape => DeviceInfo.CurrentOrientation == DeviceOrientation.Landscape;
public DeviceInfo DeviceInfo { get; set; }
public Size ScaledScreenSize => DeviceInfo.ScaledScreenSize;
public event EventHandler OnScreenChanged;
public void Dispose()
{
}
public Rectangle GetHinge()
{
if (!IsSpanned)
return Rectangle.Zero;
if(IsLandscape)
return new Rectangle(0, 490, DeviceInfo.ScaledScreenSize.Width, 20);
return new Rectangle(490, 0, 20, DeviceInfo.ScaledScreenSize.Height);
}
public Point? GetLocationOnScreen(VisualElement visualElement) => _location;
public Point? SetLocationOnScreen(Point point) => _location = point;
public object WatchForChangesOnLayout(VisualElement visualElement, Action action)
{
EventHandler<EventArg<VisualElement>> handler = (_, __) => action();
visualElement.BatchCommitted += handler;
return handler;
}
public void StopWatchingForChangesOnLayout(VisualElement visualElement, object handle)
{
if(handle is EventHandler<EventArg<VisualElement>> eh)
visualElement.BatchCommitted -= eh;
}
public Task<int> GetHingeAngleAsync() => Task.FromResult(0);
}
internal class TestDualScreenServiceLandscape : TestDualScreenService
{
public TestDualScreenServiceLandscape()
{
DeviceInfo.CurrentOrientation = DeviceOrientation.Landscape;
}
}
internal class TestDualScreenServicePortrait : TestDualScreenService
{
public TestDualScreenServicePortrait()
{
DeviceInfo.CurrentOrientation = DeviceOrientation.Portrait;
}
}
}