Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 53 additions & 28 deletions osu.Android/OsuGameActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
namespace osu.Android
{
[global::Android.App.Activity(ConfigurationChanges = global::Android.Content.PM.ConfigChanges.Orientation | global::Android.Content.PM.ConfigChanges.ScreenSize | global::Android.Content.PM.ConfigChanges.UiMode, Exported = true, LaunchMode = global::Android.Content.PM.LaunchMode.SingleInstance, MainLauncher = true)]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataPathPattern = ".*\\\\.osz", DataHost = "*", DataMimeType = "*/*")]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataPathPattern = ".*\\\\.osk", DataHost = "*", DataMimeType = "*/*")]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataPathPattern = ".*\\\\.osr", DataHost = "*", DataMimeType = "*/*")]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataPathPattern = ".*\\.osz", DataHost = "*", DataMimeType = "*/*")]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataPathPattern = ".*\\.osk", DataHost = "*", DataMimeType = "*/*")]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataPathPattern = ".*\\.osr", DataHost = "*", DataMimeType = "*/*")]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataMimeType = "application/x-osu-beatmap-archive")]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataMimeType = "application/x-osu-skin-archive")]
[global::Android.App.IntentFilter(new[] { "android.intent.action.VIEW" }, Categories = new[] { "android.intent.category.DEFAULT" }, DataScheme = "content", DataMimeType = "application/x-osu-replay")]
Expand Down Expand Up @@ -159,20 +159,29 @@
// reference: https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent)
handleIntent(Intent);

Debug.Assert(Window != null);

Window.AddFlags(global::Android.Views.WindowManagerFlags.Fullscreen);
Window.AddFlags(global::Android.Views.WindowManagerFlags.KeepScreenOn);

Debug.Assert(WindowManager?.DefaultDisplay != null);
Debug.Assert(Resources?.DisplayMetrics != null);
if (Window != null)
{
Window.AddFlags(global::Android.Views.WindowManagerFlags.Fullscreen);
Window.AddFlags(global::Android.Views.WindowManagerFlags.KeepScreenOn);
}
else
{
global::Android.Util.Log.Warn("OsuGameActivity", "Window is null in OnCreate, flags not set.");
}

global::Android.Graphics.Point displaySize = new global::Android.Graphics.Point();
if (WindowManager?.DefaultDisplay != null && Resources?.DisplayMetrics != null)
{
global::Android.Graphics.Point displaySize = new global::Android.Graphics.Point();
#pragma warning disable CA1422 // GetSize is deprecated
WindowManager.DefaultDisplay.GetSize(displaySize);
WindowManager.DefaultDisplay.GetSize(displaySize);
#pragma warning restore CA1422
float smallestWidthDp = Math.Min(displaySize.X, displaySize.Y) / Resources.DisplayMetrics.Density;
IsTablet = smallestWidthDp >= 600f;
float smallestWidthDp = Math.Min(displaySize.X, displaySize.Y) / Resources.DisplayMetrics.Density;
IsTablet = smallestWidthDp >= 600f;
}
else
{
global::Android.Util.Log.Warn("OsuGameActivity", "WindowManager.DefaultDisplay or Resources.DisplayMetrics is null in OnCreate.");
}

RequestedOrientation = DefaultOrientation = IsTablet ? global::Android.Content.PM.ScreenOrientation.FullUser : global::Android.Content.PM.ScreenOrientation.SensorLandscape;

Expand All @@ -181,10 +190,18 @@
// Manually load them so that they can be loaded by RulesetStore.loadFromAppDomain.
// REMEMBER to fully uninstall previous version every time when investigating this!
// Don't forget osu.Game.Tests.Android too.
Assembly.Load("osu.Game.Rulesets.Osu");
Assembly.Load("osu.Game.Rulesets.Taiko");
Assembly.Load("osu.Game.Rulesets.Catch");
Assembly.Load("osu.Game.Rulesets.Mania");
try
{
// Using typeof() ensures the linker preserves the assemblies.
Assembly.Load(typeof(osu.Game.Rulesets.Osu.OsuRuleset).Assembly.FullName);

Check warning on line 196 in osu.Android/OsuGameActivity.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'assemblyString' in 'Assembly Assembly.Load(string assemblyString)'.

Check warning on line 196 in osu.Android/OsuGameActivity.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'assemblyString' in 'Assembly Assembly.Load(string assemblyString)'.
Assembly.Load(typeof(osu.Game.Rulesets.Taiko.TaikoRuleset).Assembly.FullName);

Check warning on line 197 in osu.Android/OsuGameActivity.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'assemblyString' in 'Assembly Assembly.Load(string assemblyString)'.

Check warning on line 197 in osu.Android/OsuGameActivity.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'assemblyString' in 'Assembly Assembly.Load(string assemblyString)'.
Assembly.Load(typeof(osu.Game.Rulesets.Catch.CatchRuleset).Assembly.FullName);

Check warning on line 198 in osu.Android/OsuGameActivity.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'assemblyString' in 'Assembly Assembly.Load(string assemblyString)'.

Check warning on line 198 in osu.Android/OsuGameActivity.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'assemblyString' in 'Assembly Assembly.Load(string assemblyString)'.
Assembly.Load(typeof(osu.Game.Rulesets.Mania.ManiaRuleset).Assembly.FullName);

Check warning on line 199 in osu.Android/OsuGameActivity.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'assemblyString' in 'Assembly Assembly.Load(string assemblyString)'.

Check warning on line 199 in osu.Android/OsuGameActivity.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'assemblyString' in 'Assembly Assembly.Load(string assemblyString)'.
}
catch (Exception e)
{
global::Android.Util.Log.Error("OsuGameActivity", $"Failed to load rulesets: {e}");
}
}

protected override void OnResume()
Expand Down Expand Up @@ -275,22 +292,30 @@

private void handleImportFromUris(params global::Android.Net.Uri[] uris) => Task.Factory.StartNew(async () =>
{
var tasks = new List<ImportTask>();

await Task.WhenAll(uris.Select(async uri =>
try
{
var task = await AndroidImportTask.Create(ContentResolver!, uri).ConfigureAwait(false);
var tasks = new List<ImportTask>();

if (task != null)
await Task.WhenAll(uris.Select(async uri =>
{
lock (tasks)
if (ContentResolver == null) return;
var task = await AndroidImportTask.Create(ContentResolver, uri).ConfigureAwait(false);

if (task != null)
{
tasks.Add(task);
lock (tasks)
{
tasks.Add(task);
}
}
}
})).ConfigureAwait(false);
})).ConfigureAwait(false);

await game.Import(tasks.ToArray()).ConfigureAwait(false);
await game.Import(tasks.ToArray()).ConfigureAwait(false);
}
catch (Exception ex)
{
global::Android.Util.Log.Error("OsuGameActivity", $"Failed to handle imports: {ex}");
}
}, TaskCreationOptions.LongRunning);

public global::Android.Views.Surface? GetSurface()
Expand Down