2023-03-04 12:10:16 +01:00
|
|
|
using Android.App;
|
2020-06-09 18:56:01 +02:00
|
|
|
using Android.Content;
|
2019-09-01 11:56:12 +02:00
|
|
|
using Android.Content.PM;
|
|
|
|
using Android.OS;
|
|
|
|
using Android.Views;
|
2022-09-03 12:31:34 +02:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
2020-04-19 03:20:25 +02:00
|
|
|
using MLEM.Extensions;
|
2020-02-24 14:03:53 +01:00
|
|
|
using MLEM.Misc;
|
2022-07-25 18:23:16 +02:00
|
|
|
using Uri = Android.Net.Uri;
|
2019-09-01 11:56:12 +02:00
|
|
|
|
2022-07-25 18:23:16 +02:00
|
|
|
namespace Demos.Android;
|
2020-04-19 03:20:25 +02:00
|
|
|
|
2022-07-25 18:23:16 +02:00
|
|
|
[Activity(
|
|
|
|
Label = "@string/app_name",
|
|
|
|
MainLauncher = true,
|
|
|
|
Icon = "@drawable/icon",
|
|
|
|
AlwaysRetainTaskState = true,
|
|
|
|
LaunchMode = LaunchMode.SingleInstance,
|
|
|
|
ScreenOrientation = ScreenOrientation.UserLandscape,
|
|
|
|
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize
|
|
|
|
)]
|
|
|
|
public class Activity1 : AndroidGameActivity {
|
2019-09-01 11:56:12 +02:00
|
|
|
|
2022-07-25 18:23:16 +02:00
|
|
|
private GameImpl game;
|
|
|
|
private View view;
|
2020-04-19 03:20:25 +02:00
|
|
|
|
2022-07-25 18:23:16 +02:00
|
|
|
protected override void OnCreate(Bundle bundle) {
|
|
|
|
base.OnCreate(bundle);
|
|
|
|
// render under notches
|
|
|
|
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
|
|
|
|
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
|
2019-09-01 11:56:12 +02:00
|
|
|
|
2022-07-25 18:23:16 +02:00
|
|
|
MlemPlatform.Current = new MlemPlatform.Mobile(KeyboardInput.Show, l => this.StartActivity(new Intent(Intent.ActionView, Uri.Parse(l))));
|
|
|
|
this.game = new GameImpl();
|
|
|
|
// reset MlemGame width and height to use device's aspect ratio
|
|
|
|
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
|
|
|
|
// disable mouse handling for android to make emulator behavior more coherent
|
|
|
|
this.game.OnLoadContent += game => game.InputHandler.HandleMouse = false;
|
|
|
|
// set the game to fullscreen to cause the status bar to be hidden
|
|
|
|
this.game.GraphicsDeviceManager.IsFullScreen = true;
|
|
|
|
this.view = this.game.Services.GetService(typeof(View)) as View;
|
|
|
|
this.SetContentView(this.view);
|
|
|
|
this.game.Run();
|
|
|
|
}
|
2020-05-13 22:11:33 +02:00
|
|
|
|
2022-07-25 18:23:16 +02:00
|
|
|
public override void OnWindowFocusChanged(bool hasFocus) {
|
|
|
|
base.OnWindowFocusChanged(hasFocus);
|
|
|
|
// hide the status bar
|
|
|
|
if (hasFocus) {
|
2023-11-23 22:14:48 +01:00
|
|
|
#pragma warning disable CS0618
|
2022-07-25 18:23:16 +02:00
|
|
|
// TODO this is deprecated, find out how to replace it
|
|
|
|
this.Window.DecorView.SystemUiVisibility = (StatusBarVisibility) (SystemUiFlags.ImmersiveSticky | SystemUiFlags.LayoutStable | SystemUiFlags.LayoutHideNavigation | SystemUiFlags.LayoutFullscreen | SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen);
|
2023-11-23 22:14:48 +01:00
|
|
|
#pragma warning restore CS0618
|
2022-07-25 18:23:16 +02:00
|
|
|
}
|
2019-09-01 11:56:12 +02:00
|
|
|
}
|
2022-07-25 18:23:16 +02:00
|
|
|
|
2022-06-17 18:23:47 +02:00
|
|
|
}
|