-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.cs
98 lines (80 loc) · 3 KB
/
MainActivity.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Views;
using Microsoft.Xna.Framework;
namespace AndroidSpaceShip
{
[Activity(
Label = "@string/app_name",
Theme = "@style/AppTheme.Splash",
MainLauncher = true,
Icon = "@drawable/icon",
AlwaysRetainTaskState = true,
LaunchMode = LaunchMode.SingleInstance,
ScreenOrientation = ScreenOrientation.Portrait,
Immersive = true,
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize | ConfigChanges.ScreenLayout | ConfigChanges.UiMode | ConfigChanges.SmallestScreenSize
)]
public class MainActivity : AndroidGameActivity
{
private GameRoot gameRoot;
private View gameView;
private Vibrator vibrator;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
{
Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.Always;
Window.AddFlags(WindowManagerFlags.Fullscreen);
Window.AddFlags(WindowManagerFlags.HardwareAccelerated);
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
}
gameRoot = new GameRoot();
gameView = gameRoot.Services.GetService(typeof(View)) as View;
try
{
this.vibrator = (Vibrator)this.GetSystemService("vibrator");
gameRoot.Vibrate = this.Vibrate;
}
catch { }
SetContentView(gameView);
gameRoot.Run();
}
public override void OnWindowFocusChanged(bool hasFocus)
{
if(hasFocus)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
StatusBarVisibility visibility = (StatusBarVisibility)(SystemUiFlags.LayoutStable | SystemUiFlags.LayoutHideNavigation | SystemUiFlags.LayoutFullscreen | SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen | SystemUiFlags.ImmersiveSticky);
this.gameView.SystemUiVisibility = visibility;
}
}
}
public void Vibrate(long duration)
{
if(this.vibrator != null)
{
VibrationEffect vibrationEffect = VibrationEffect.CreateOneShot(duration, VibrationEffect.EffectDoubleClick);
this.vibrator.Vibrate(vibrationEffect);
}
}
protected override void OnPause()
{
base.OnPause();
gameRoot.OnPause();
}
protected override void OnResume()
{
base.OnResume();
gameRoot.OnResume();
}
protected override void OnRestart()
{
base.OnRestart();
gameRoot.OnRestart();
}
}
}