Skip to content

Commit 198ed18

Browse files
authored
Oculus native (#2174)
* Oculus native backend * build oculus * Oculus template * update readme
1 parent ec3c109 commit 198ed18

30 files changed

+4217
-1
lines changed

.github/workflows/dotnet.yml

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ jobs:
6262
run: dotnet build Kni.Platform.iOS.GL.sln --property:WarningLevel=1
6363
- name: Build Android.GL
6464
run: dotnet build Kni.Platform.Android.GL.sln --property:WarningLevel=1
65+
# - name: Build Oculus.GL
66+
# run: dotnet build Kni.Platform.Oculus.GL.sln --property:WarningLevel=1
6567
# - name: Build Cardboard.GL
6668
# run: dotnet build Kni.Platform.Cardboard.GL.sln --property:WarningLevel=1
6769
# - name: Build Windows UAP.DX11

BuildNuget.bat

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dotnet pack src\Xna.Framework.Content.Pipeline.Media\Xna.Framework.Content.Pipel
2121
"C:\Program Files (x86)\NuGet3\nuget.exe" pack NuGetPackages/MonoGame.Framework.WindowsUniversal.nuspec -OutputDirectory NuGetPackages\Output\ -BasePath . -Version 3.14.9001.0 -Properties Configuration=Release
2222

2323
dotnet pack Platforms\Kni.Platform.Android.GL.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
24+
dotnet pack Platforms\Kni.Platform.Oculus.GL.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
2425
dotnet pack Platforms\Kni.Platform.iOS.GL.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
2526
dotnet pack Platforms\Kni.Platform.WinForms.DX11.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release
2627
dotnet pack Platforms\Kni.Platform.SDL2.GL.csproj --output NuGetPackages\Output\ /t:Build /p:Configuration=Release

KNI.sln

+7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kni.Tests.SDL2.GL", "Tests\
7777
EndProject
7878
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kni.Tests.WinForms.DX11", "Tests\Kni.Tests.WinForms.DX11.csproj", "{DED2DDB6-D4BE-656D-2E54-657374732E57}"
7979
EndProject
80+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kni.Platform.Oculus.GL", "Platforms\Kni.Platform.Oculus.GL.csproj", "{3472997A-CD26-4D0D-B64A-795F913E6777}"
81+
EndProject
8082
Global
8183
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8284
Debug|Any CPU = Debug|Any CPU
@@ -207,6 +209,10 @@ Global
207209
{DED2DDB6-D4BE-656D-2E54-657374732E57}.Debug|Any CPU.Build.0 = Debug|Any CPU
208210
{DED2DDB6-D4BE-656D-2E54-657374732E57}.Release|Any CPU.ActiveCfg = Release|Any CPU
209211
{DED2DDB6-D4BE-656D-2E54-657374732E57}.Release|Any CPU.Build.0 = Release|Any CPU
212+
{3472997A-CD26-4D0D-B64A-795F913E6777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
213+
{3472997A-CD26-4D0D-B64A-795F913E6777}.Debug|Any CPU.Build.0 = Debug|Any CPU
214+
{3472997A-CD26-4D0D-B64A-795F913E6777}.Release|Any CPU.ActiveCfg = Release|Any CPU
215+
{3472997A-CD26-4D0D-B64A-795F913E6777}.Release|Any CPU.Build.0 = Release|Any CPU
210216
EndGlobalSection
211217
GlobalSection(SolutionProperties) = preSolution
212218
HideSolutionNode = FALSE
@@ -243,6 +249,7 @@ Global
243249
{5212C44E-1573-43C2-85E8-5751A12FBBFD} = {753EFCC6-42AB-433E-A013-B7B5D1FE50E0}
244250
{DED2DDB6-D4BE-B1B4-2E54-657374732E57} = {94670BA5-3B36-4EBA-A3E0-27912F6BD11A}
245251
{DED2DDB6-D4BE-656D-2E54-657374732E57} = {94670BA5-3B36-4EBA-A3E0-27912F6BD11A}
252+
{3472997A-CD26-4D0D-B64A-795F913E6777} = {9E8F9D1A-DEF1-4FA1-8DE9-0A82B7BC99D9}
246253
EndGlobalSection
247254
GlobalSection(ExtensibilityGlobals) = postSolution
248255
SolutionGuid = {48F20664-456B-4FE0-AE0A-7F5AC695B13C}

Kni.Platform.Oculus.GL.sln

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.9.34723.18
4+
MinimumVisualStudioVersion = 17.9.34723.18
5+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Framework", "Framework", "{A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}"
6+
EndProject
7+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platforms", "Platforms", "{9E8F9D1A-DEF1-4FA1-8DE9-0A82B7BC99D9}"
8+
EndProject
9+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework", "src\Xna.Framework\Xna.Framework.csproj", "{741B4B1E-89E4-434C-8867-6129838AFD51}"
10+
EndProject
11+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Content", "src\Xna.Framework.Content\Xna.Framework.Content.csproj", "{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}"
12+
EndProject
13+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Graphics", "src\Xna.Framework.Graphics\Xna.Framework.Graphics.csproj", "{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}"
14+
EndProject
15+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Audio", "src\Xna.Framework.Audio\Xna.Framework.Audio.csproj", "{3F81F76D-F0F3-44FE-A256-40AF153C33F7}"
16+
EndProject
17+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Media", "src\Xna.Framework.Media\Xna.Framework.Media.csproj", "{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}"
18+
EndProject
19+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Input", "src\Xna.Framework.Input\Xna.Framework.Input.csproj", "{8FB8B257-C091-4C41-B221-75C37B68CD8F}"
20+
EndProject
21+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Game", "src\Xna.Framework.Game\Xna.Framework.Game.csproj", "{90BBD6EF-F386-4F47-88CD-BF386C7D1705}"
22+
EndProject
23+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Devices", "src\Xna.Framework.Devices\Xna.Framework.Devices.csproj", "{6B3E56F7-C567-463C-9746-0244FD959322}"
24+
EndProject
25+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xna.Framework.Storage", "src\Xna.Framework.Storage\Xna.Framework.Storage.csproj", "{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}"
26+
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xna.Framework.XR", "src\Xna.Framework.XR\Xna.Framework.XR.csproj", "{6D0D985D-B256-4208-9E78-77897D461698}"
28+
EndProject
29+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kni.Platform.Oculus.GL", "Platforms\Kni.Platform.Oculus.GL.csproj", "{3472997A-CD26-4D0D-B64A-795F913E6777}"
30+
EndProject
31+
Global
32+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
33+
Debug|Any CPU = Debug|Any CPU
34+
Release|Any CPU = Release|Any CPU
35+
EndGlobalSection
36+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
37+
{741B4B1E-89E4-434C-8867-6129838AFD51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{741B4B1E-89E4-434C-8867-6129838AFD51}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{741B4B1E-89E4-434C-8867-6129838AFD51}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{741B4B1E-89E4-434C-8867-6129838AFD51}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{3F81F76D-F0F3-44FE-A256-40AF153C33F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{3F81F76D-F0F3-44FE-A256-40AF153C33F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{3F81F76D-F0F3-44FE-A256-40AF153C33F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{3F81F76D-F0F3-44FE-A256-40AF153C33F7}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{8FB8B257-C091-4C41-B221-75C37B68CD8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{8FB8B257-C091-4C41-B221-75C37B68CD8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{8FB8B257-C091-4C41-B221-75C37B68CD8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{8FB8B257-C091-4C41-B221-75C37B68CD8F}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{90BBD6EF-F386-4F47-88CD-BF386C7D1705}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{90BBD6EF-F386-4F47-88CD-BF386C7D1705}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{90BBD6EF-F386-4F47-88CD-BF386C7D1705}.Release|Any CPU.ActiveCfg = Release|Any CPU
64+
{90BBD6EF-F386-4F47-88CD-BF386C7D1705}.Release|Any CPU.Build.0 = Release|Any CPU
65+
{6B3E56F7-C567-463C-9746-0244FD959322}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
66+
{6B3E56F7-C567-463C-9746-0244FD959322}.Debug|Any CPU.Build.0 = Debug|Any CPU
67+
{6B3E56F7-C567-463C-9746-0244FD959322}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{6B3E56F7-C567-463C-9746-0244FD959322}.Release|Any CPU.Build.0 = Release|Any CPU
69+
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
70+
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
71+
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
72+
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C}.Release|Any CPU.Build.0 = Release|Any CPU
73+
{6D0D985D-B256-4208-9E78-77897D461698}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
74+
{6D0D985D-B256-4208-9E78-77897D461698}.Debug|Any CPU.Build.0 = Debug|Any CPU
75+
{6D0D985D-B256-4208-9E78-77897D461698}.Release|Any CPU.ActiveCfg = Release|Any CPU
76+
{6D0D985D-B256-4208-9E78-77897D461698}.Release|Any CPU.Build.0 = Release|Any CPU
77+
{3472997A-CD26-4D0D-B64A-795F913E6777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
78+
{3472997A-CD26-4D0D-B64A-795F913E6777}.Debug|Any CPU.Build.0 = Debug|Any CPU
79+
{3472997A-CD26-4D0D-B64A-795F913E6777}.Release|Any CPU.ActiveCfg = Release|Any CPU
80+
{3472997A-CD26-4D0D-B64A-795F913E6777}.Release|Any CPU.Build.0 = Release|Any CPU
81+
EndGlobalSection
82+
GlobalSection(SolutionProperties) = preSolution
83+
HideSolutionNode = FALSE
84+
EndGlobalSection
85+
GlobalSection(NestedProjects) = preSolution
86+
{741B4B1E-89E4-434C-8867-6129838AFD51} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
87+
{1DC4C439-A8A6-4A11-AB3B-A88DCBA05449} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
88+
{4B8D3F73-BBD2-4057-B86B-8B73B957DC0F} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
89+
{3F81F76D-F0F3-44FE-A256-40AF153C33F7} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
90+
{6E0E6284-13FF-4DC7-8FC2-B6D756EAF1FD} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
91+
{8FB8B257-C091-4C41-B221-75C37B68CD8F} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
92+
{90BBD6EF-F386-4F47-88CD-BF386C7D1705} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
93+
{6B3E56F7-C567-463C-9746-0244FD959322} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
94+
{7AE82BAB-5F52-427A-8F6F-DA829261FF9C} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
95+
{6D0D985D-B256-4208-9E78-77897D461698} = {A5A52329-49D0-4CE0-BA3E-DBD2BA90988F}
96+
{3472997A-CD26-4D0D-B64A-795F913E6777} = {9E8F9D1A-DEF1-4FA1-8DE9-0A82B7BC99D9}
97+
EndGlobalSection
98+
EndGlobal

NuGetPackages/RegisterLocalNuget.bat

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set username=username
2525
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.UAP.DX11 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive
2626
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.SDL2.GL 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive
2727
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.Android.GL 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive
28+
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.Oculus.GL 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive
2829

2930
"C:\Program Files (x86)\nuget\nuget.exe" delete nkast.Kni.Platform.WinForms.DX11.OculusOVR 3.14.9001 -Source "C:\Users\%username%\.nuget\localPackages" -NonInteractive
3031

@@ -54,6 +55,7 @@ set username=username
5455
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.UAP.DX11.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"
5556
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.SDL2.GL.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"
5657
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.Android.GL.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"
58+
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.Oculus.GL.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"
5759

5860
"C:\Program Files (x86)\nuget\nuget.exe" add output\nkast.Kni.Platform.WinForms.DX11.OculusOVR.3.14.9001.nupkg -Source "C:\Users\%username%\.nuget\localPackages"
5961

Platforms/Game/.Android/ConcreteGraphicsDeviceManager.cs

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ public override bool BeginDraw()
220220

221221
public override void EndDraw()
222222
{
223+
#if OCULUS
224+
return; // On Oculus, do not Present() the backbuffer.
225+
#endif
226+
223227
//base.EndDraw();
224228

225229
GraphicsDevice device = this.GraphicsDevice;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
using System.Linq;
3+
using Android.App;
4+
using Android.Content.Res;
5+
using Android.OS;
6+
using Android.Views;
7+
8+
namespace Microsoft.Xna.Framework
9+
{
10+
/// <summary>
11+
/// Properties that change from how XNA works by default
12+
/// </summary>
13+
public class AndroidCompatibility
14+
{
15+
private static AndroidCompatibility _current;
16+
17+
/// <summary>
18+
/// Because the Kindle Fire devices default orientation is fliped by 180 degrees from all the other android devices
19+
/// on the market we need to do some special processing to make sure that LandscapeLeft is the correct way round.
20+
/// This list contains all the Build.Model strings of the effected devices, it should be added to if and when
21+
/// more devices exhibit the same issues.
22+
/// </summary>
23+
private readonly string[] Kindles = new[] { "KFTT", "KFJWI", "KFJWA", "KFSOWI", "KFTHWA", "KFTHWI", "KFAPWA", "KFAPWI" };
24+
25+
public bool FlipLandscape { get; private set; }
26+
27+
[CLSCompliant(false)]
28+
public Orientation NaturalOrientation { get; private set; }
29+
30+
31+
[CLSCompliant(false)]
32+
public static AndroidCompatibility Current
33+
{
34+
get
35+
{
36+
if (_current != null)
37+
return _current;
38+
else
39+
throw new InvalidOperationException("Not initialized.");
40+
}
41+
}
42+
43+
internal static void Initialize(Activity activity)
44+
{
45+
if (_current == null)
46+
_current = new AndroidCompatibility(activity);
47+
}
48+
49+
private AndroidCompatibility(Activity activity)
50+
{
51+
FlipLandscape = Kindles.Contains(Build.Model);
52+
NaturalOrientation = GetDeviceNaturalOrientation(activity);
53+
}
54+
55+
private Orientation GetDeviceNaturalOrientation(Activity activity)
56+
{
57+
var orientation = activity.Resources.Configuration.Orientation;
58+
SurfaceOrientation rotation = activity.WindowManager.DefaultDisplay.Rotation;
59+
60+
// check if MainActivity setup is correct.
61+
var screenOrientation = activity.RequestedOrientation;
62+
if (screenOrientation != Android.Content.PM.ScreenOrientation.Landscape)
63+
throw new InvalidOperationException("Invalid orientation. Set ScreenOrientation in MainActivity to Landscape.");
64+
65+
if (((rotation == SurfaceOrientation.Rotation0 || rotation == SurfaceOrientation.Rotation180) &&
66+
orientation == Orientation.Landscape)
67+
|| ((rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) &&
68+
orientation == Orientation.Portrait))
69+
{
70+
return Orientation.Landscape;
71+
}
72+
else
73+
{
74+
return Orientation.Portrait;
75+
}
76+
}
77+
78+
internal DisplayOrientation GetAbsoluteOrientation(int degrees)
79+
{
80+
// Orientation is reported by the device in degrees compared to the natural orientation
81+
// Some tablets have a natural landscape orientation, which we need to account for
82+
if (NaturalOrientation == Orientation.Landscape)
83+
degrees += 270;
84+
85+
// Round orientation into one of 8 positions, either 0, 45, 90, 135, 180, 225, 270, 315.
86+
degrees = ( ((degrees + 22) / 45) * 45) % 360;
87+
88+
// Surprisingly 90 degree is landscape right, except on Kindle devices
89+
var disporientation = DisplayOrientation.Unknown;
90+
switch (degrees)
91+
{
92+
case 90: disporientation = FlipLandscape ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight;
93+
break;
94+
case 270: disporientation = FlipLandscape ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft;
95+
break;
96+
case 0: disporientation = DisplayOrientation.Portrait;
97+
break;
98+
case 180: disporientation = DisplayOrientation.PortraitDown;
99+
break;
100+
default:
101+
disporientation = DisplayOrientation.Unknown;
102+
break;
103+
}
104+
105+
return disporientation;
106+
}
107+
108+
/// <summary>
109+
/// Get the absolute orientation of the device, accounting for platform differences.
110+
/// </summary>
111+
/// <returns></returns>
112+
[CLSCompliant(false)]
113+
public DisplayOrientation GetAbsoluteOrientation(Activity activity)
114+
{
115+
var orientation = activity.WindowManager.DefaultDisplay.Rotation;
116+
117+
// Landscape degrees (provided by the OrientationListener) are swapped by default
118+
// Since we use the code used by OrientationListener, we have to swap manually
119+
int degrees;
120+
switch (orientation)
121+
{
122+
case SurfaceOrientation.Rotation90:
123+
degrees = 270;
124+
break;
125+
case SurfaceOrientation.Rotation180:
126+
degrees = 180;
127+
break;
128+
case SurfaceOrientation.Rotation270:
129+
degrees = 90;
130+
break;
131+
default:
132+
degrees = 0;
133+
break;
134+
}
135+
136+
return GetAbsoluteOrientation(degrees);
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)