TouchyTickets/Android/Activity1.cs

64 lines
2.4 KiB
C#
Raw Normal View History

2020-05-30 19:41:49 +02:00
using Android.App;
2020-06-09 19:03:55 +02:00
using Android.Content;
2020-05-30 19:41:49 +02:00
using Android.Content.PM;
using Android.OS;
using Android.Views;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
2020-05-30 19:41:49 +02:00
using MLEM.Extensions;
using MLEM.Misc;
2020-06-01 17:39:57 +02:00
using TouchyTickets;
2020-06-10 23:03:48 +02:00
using Uri = Android.Net.Uri;
2020-05-30 19:41:49 +02:00
2023-03-04 10:50:45 +01:00
namespace Android;
2020-05-30 19:41:49 +02:00
2023-02-11 10:16:42 +01:00
[Activity(
Label = "@string/app_name",
MainLauncher = true,
Icon = "@drawable/icon",
AlwaysRetainTaskState = true,
LaunchMode = LaunchMode.SingleInstance,
ScreenOrientation = ScreenOrientation.UserPortrait,
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize
)]
public class Activity1 : AndroidGameActivity {
2020-05-30 19:41:49 +02:00
2023-02-11 10:16:42 +01:00
private GameImpl game;
private AndroidPlatform platform;
2023-03-04 10:50:45 +01:00
private View view;
2020-05-30 19:41:49 +02:00
2023-02-11 10:16:42 +01:00
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
2023-02-11 10:16:42 +01:00
// set up the game
MlemPlatform.Current = new MlemPlatform.Mobile(KeyboardInput.Show, l => this.StartActivity(new Intent(Intent.ActionView, Uri.Parse(l))));
2023-03-04 10:50:45 +01:00
this.platform = new AndroidPlatform(this);
2023-02-11 10:16:42 +01:00
this.game = new GameImpl(this.platform);
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
this.game.GraphicsDeviceManager.IsFullScreen = true;
this.game.OnLoadContent += game => game.InputHandler.HandleMouse = false;
2020-07-21 20:26:52 +02:00
2023-02-11 10:16:42 +01:00
var gameView = this.game.Services.GetService(typeof(View)) as View;
gameView.LayoutChange += (_, args) => {
// force the game size to update when the ad size changes
this.game.GraphicsDeviceManager.PreferredBackBufferWidth = args.Right - args.Left;
this.game.GraphicsDeviceManager.PreferredBackBufferHeight = args.Bottom - args.Top;
this.game.GraphicsDeviceManager.ApplyChanges();
};
2020-07-21 20:26:52 +02:00
2023-03-04 10:50:45 +01:00
this.view = this.game.Services.GetService(typeof(View)) as View;
this.SetContentView(this.view);
2020-05-30 19:41:49 +02:00
2023-02-11 10:16:42 +01:00
this.game.Run();
}
2020-07-21 20:26:52 +02:00
2023-02-11 10:16:42 +01:00
public override void OnWindowFocusChanged(bool hasFocus) {
base.OnWindowFocusChanged(hasFocus);
#pragma warning disable CS0618
// hide the status bar
if (hasFocus)
this.Window.DecorView.SystemUiVisibility = (StatusBarVisibility) (SystemUiFlags.ImmersiveSticky | SystemUiFlags.LayoutStable | SystemUiFlags.LayoutHideNavigation | SystemUiFlags.LayoutFullscreen | SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen);
#pragma warning restore CS0618
2020-05-30 19:41:49 +02:00
}
2023-02-11 10:16:42 +01:00
2020-05-30 19:41:49 +02:00
}