2019-01-31 00:07:32 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2019-01-06 04:15:09 +00:00
|
|
|
|
|
2022-02-03 12:28:49 +00:00
|
|
|
|
using System;
|
2020-12-16 19:33:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-12-19 06:43:12 +00:00
|
|
|
|
using System.Reflection;
|
2020-12-08 18:46:55 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-01-06 04:15:09 +00:00
|
|
|
|
using Android.App;
|
2020-12-01 19:12:09 +00:00
|
|
|
|
using Android.Content;
|
2019-01-06 04:15:09 +00:00
|
|
|
|
using Android.Content.PM;
|
2022-02-03 12:28:49 +00:00
|
|
|
|
using Android.Graphics;
|
2019-01-31 00:07:32 +00:00
|
|
|
|
using Android.OS;
|
|
|
|
|
using Android.Views;
|
2019-01-06 04:15:09 +00:00
|
|
|
|
using osu.Framework.Android;
|
2023-06-24 15:05:52 +00:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2020-12-16 13:28:16 +00:00
|
|
|
|
using osu.Game.Database;
|
2022-02-03 12:28:49 +00:00
|
|
|
|
using Debug = System.Diagnostics.Debug;
|
|
|
|
|
using Uri = Android.Net.Uri;
|
2019-01-06 04:15:09 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Android
|
|
|
|
|
{
|
2022-02-03 12:28:49 +00:00
|
|
|
|
[Activity(ConfigurationChanges = DEFAULT_CONFIG_CHANGES, Exported = true, LaunchMode = DEFAULT_LAUNCH_MODE, MainLauncher = true)]
|
2020-12-28 14:54:21 +00:00
|
|
|
|
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataPathPattern = ".*\\\\.osz", DataHost = "*", DataMimeType = "*/*")]
|
|
|
|
|
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataPathPattern = ".*\\\\.osk", DataHost = "*", DataMimeType = "*/*")]
|
2021-11-02 01:51:54 +00:00
|
|
|
|
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataPathPattern = ".*\\\\.osr", DataHost = "*", DataMimeType = "*/*")]
|
2021-08-23 07:55:42 +00:00
|
|
|
|
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataMimeType = "application/x-osu-beatmap-archive")]
|
|
|
|
|
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataMimeType = "application/x-osu-skin-archive")]
|
|
|
|
|
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataMimeType = "application/x-osu-replay")]
|
|
|
|
|
[IntentFilter(new[] { Intent.ActionSend, Intent.ActionSendMultiple }, Categories = new[] { Intent.CategoryDefault }, DataMimeTypes = new[]
|
|
|
|
|
{
|
|
|
|
|
"application/zip",
|
|
|
|
|
"application/octet-stream",
|
|
|
|
|
"application/download",
|
|
|
|
|
"application/x-zip",
|
|
|
|
|
"application/x-zip-compressed",
|
|
|
|
|
// newer official mime types (see https://osu.ppy.sh/wiki/en/osu%21_File_Formats).
|
|
|
|
|
"application/x-osu-beatmap-archive",
|
|
|
|
|
"application/x-osu-skin-archive",
|
|
|
|
|
"application/x-osu-replay",
|
|
|
|
|
})]
|
2020-12-23 23:17:26 +00:00
|
|
|
|
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault }, DataSchemes = new[] { "osu", "osump" })]
|
2019-01-06 04:15:09 +00:00
|
|
|
|
public class OsuGameActivity : AndroidGameActivity
|
|
|
|
|
{
|
2020-12-23 23:17:26 +00:00
|
|
|
|
private static readonly string[] osu_url_schemes = { "osu", "osump" };
|
2020-12-23 12:31:27 +00:00
|
|
|
|
|
2022-02-03 12:55:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The default screen orientation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>Adjusted on startup to match expected UX for the current device type (phone/tablet).</remarks>
|
|
|
|
|
public ScreenOrientation DefaultOrientation = ScreenOrientation.Unspecified;
|
2022-02-03 12:28:49 +00:00
|
|
|
|
|
2023-06-24 15:05:52 +00:00
|
|
|
|
private OsuGameAndroid game = null!;
|
2020-12-02 17:03:49 +00:00
|
|
|
|
|
|
|
|
|
protected override Framework.Game CreateGame() => game = new OsuGameAndroid(this);
|
2019-01-31 00:07:32 +00:00
|
|
|
|
|
2023-06-24 15:05:52 +00:00
|
|
|
|
protected override void OnCreate(Bundle? savedInstanceState)
|
2019-01-31 00:07:32 +00:00
|
|
|
|
{
|
|
|
|
|
base.OnCreate(savedInstanceState);
|
|
|
|
|
|
2020-12-14 19:23:49 +00:00
|
|
|
|
// OnNewIntent() only fires for an activity if it's *re-launched* while it's on top of the activity stack.
|
|
|
|
|
// on first launch we still have to fire manually.
|
|
|
|
|
// reference: https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent)
|
|
|
|
|
handleIntent(Intent);
|
2020-12-02 17:03:49 +00:00
|
|
|
|
|
2022-02-03 12:28:49 +00:00
|
|
|
|
Debug.Assert(Window != null);
|
|
|
|
|
|
2019-01-31 00:07:32 +00:00
|
|
|
|
Window.AddFlags(WindowManagerFlags.Fullscreen);
|
|
|
|
|
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
|
2022-02-03 12:28:49 +00:00
|
|
|
|
|
|
|
|
|
Debug.Assert(WindowManager?.DefaultDisplay != null);
|
|
|
|
|
Debug.Assert(Resources?.DisplayMetrics != null);
|
|
|
|
|
|
|
|
|
|
Point displaySize = new Point();
|
2024-02-01 17:18:22 +00:00
|
|
|
|
#pragma warning disable CA1422 // GetSize is deprecated
|
2022-02-03 12:28:49 +00:00
|
|
|
|
WindowManager.DefaultDisplay.GetSize(displaySize);
|
2024-02-01 17:18:22 +00:00
|
|
|
|
#pragma warning restore CA1422
|
2022-02-03 12:28:49 +00:00
|
|
|
|
float smallestWidthDp = Math.Min(displaySize.X, displaySize.Y) / Resources.DisplayMetrics.Density;
|
|
|
|
|
bool isTablet = smallestWidthDp >= 600f;
|
|
|
|
|
|
2022-02-03 12:55:04 +00:00
|
|
|
|
RequestedOrientation = DefaultOrientation = isTablet ? ScreenOrientation.FullUser : ScreenOrientation.SensorLandscape;
|
2022-12-19 06:43:12 +00:00
|
|
|
|
|
|
|
|
|
// Currently (SDK 6.0.200), BundleAssemblies is not runnable for net6-android.
|
|
|
|
|
// The assembly files are not available as files either after native AOT.
|
|
|
|
|
// 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");
|
2019-01-31 00:07:32 +00:00
|
|
|
|
}
|
2020-12-02 17:03:49 +00:00
|
|
|
|
|
2023-06-24 15:05:52 +00:00
|
|
|
|
protected override void OnNewIntent(Intent? intent) => handleIntent(intent);
|
2020-12-14 19:23:49 +00:00
|
|
|
|
|
2023-06-24 15:05:52 +00:00
|
|
|
|
private void handleIntent(Intent? intent)
|
2020-12-02 17:03:49 +00:00
|
|
|
|
{
|
2023-06-24 15:05:52 +00:00
|
|
|
|
switch (intent?.Action)
|
2020-12-02 17:03:49 +00:00
|
|
|
|
{
|
2020-12-14 09:12:23 +00:00
|
|
|
|
case Intent.ActionDefault:
|
|
|
|
|
if (intent.Scheme == ContentResolver.SchemeContent)
|
2023-06-24 15:05:52 +00:00
|
|
|
|
handleImportFromUris(intent.Data.AsNonNull());
|
2020-12-23 23:17:26 +00:00
|
|
|
|
else if (osu_url_schemes.Contains(intent.Scheme))
|
|
|
|
|
game.HandleLink(intent.DataString);
|
2020-12-14 09:12:23 +00:00
|
|
|
|
break;
|
2020-12-04 21:07:45 +00:00
|
|
|
|
|
2020-12-14 09:12:23 +00:00
|
|
|
|
case Intent.ActionSend:
|
2020-12-16 19:33:29 +00:00
|
|
|
|
case Intent.ActionSendMultiple:
|
|
|
|
|
{
|
|
|
|
|
var uris = new List<Uri>();
|
2021-08-23 07:55:42 +00:00
|
|
|
|
|
2020-12-16 19:33:29 +00:00
|
|
|
|
for (int i = 0; i < intent.ClipData?.ItemCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var content = intent.ClipData?.GetItemAt(i);
|
|
|
|
|
if (content != null)
|
2023-06-24 15:05:52 +00:00
|
|
|
|
uris.Add(content.Uri.AsNonNull());
|
2020-12-16 19:33:29 +00:00
|
|
|
|
}
|
2021-08-23 07:55:42 +00:00
|
|
|
|
|
2020-12-16 19:33:29 +00:00
|
|
|
|
handleImportFromUris(uris.ToArray());
|
2020-12-14 09:12:23 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-05 17:30:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 19:33:29 +00:00
|
|
|
|
private void handleImportFromUris(params Uri[] uris) => Task.Factory.StartNew(async () =>
|
2020-12-05 17:30:40 +00:00
|
|
|
|
{
|
2020-12-16 19:33:29 +00:00
|
|
|
|
var tasks = new List<ImportTask>();
|
2020-12-14 09:12:23 +00:00
|
|
|
|
|
2020-12-16 19:33:29 +00:00
|
|
|
|
await Task.WhenAll(uris.Select(async uri =>
|
|
|
|
|
{
|
2023-01-22 21:47:16 +00:00
|
|
|
|
var task = await AndroidImportTask.Create(ContentResolver!, uri).ConfigureAwait(false);
|
2020-12-14 09:12:23 +00:00
|
|
|
|
|
2023-01-22 21:47:16 +00:00
|
|
|
|
if (task != null)
|
2020-12-16 19:33:29 +00:00
|
|
|
|
{
|
2023-01-22 21:47:16 +00:00
|
|
|
|
lock (tasks)
|
|
|
|
|
{
|
|
|
|
|
tasks.Add(task);
|
|
|
|
|
}
|
2020-12-16 19:33:29 +00:00
|
|
|
|
}
|
2021-03-08 06:17:10 +00:00
|
|
|
|
})).ConfigureAwait(false);
|
2020-12-14 19:11:53 +00:00
|
|
|
|
|
2021-03-08 06:17:10 +00:00
|
|
|
|
await game.Import(tasks.ToArray()).ConfigureAwait(false);
|
2020-12-15 20:25:53 +00:00
|
|
|
|
}, TaskCreationOptions.LongRunning);
|
2019-01-06 04:15:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|