2019-01-31 08:07:32 +08: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 12:15:09 +08:00
|
|
|
|
|
2020-12-03 01:03:49 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-01-06 12:15:09 +08:00
|
|
|
|
using Android.App;
|
2020-12-02 03:12:09 +08:00
|
|
|
|
using Android.Content;
|
2019-01-06 12:15:09 +08:00
|
|
|
|
using Android.Content.PM;
|
2019-01-31 08:07:32 +08:00
|
|
|
|
using Android.OS;
|
|
|
|
|
using Android.Views;
|
2019-01-06 12:15:09 +08:00
|
|
|
|
using osu.Framework.Android;
|
|
|
|
|
|
|
|
|
|
namespace osu.Android
|
|
|
|
|
{
|
2020-12-02 03:12:09 +08:00
|
|
|
|
|
2020-10-03 15:48:49 +08:00
|
|
|
|
[Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)]
|
2020-12-03 01:03:49 +08:00
|
|
|
|
[IntentFilter(new[] { Intent.ActionDefault }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "content", DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")]
|
2019-01-06 12:15:09 +08:00
|
|
|
|
public class OsuGameActivity : AndroidGameActivity
|
|
|
|
|
{
|
2020-12-03 01:03:49 +08:00
|
|
|
|
private OsuGameAndroid game;
|
|
|
|
|
|
|
|
|
|
protected override Framework.Game CreateGame() => game = new OsuGameAndroid(this);
|
2019-01-31 08:07:32 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnCreate(Bundle savedInstanceState)
|
|
|
|
|
{
|
2019-10-15 03:46:01 +08:00
|
|
|
|
// The default current directory on android is '/'.
|
|
|
|
|
// On some devices '/' maps to the app data directory. On others it maps to the root of the internal storage.
|
2019-10-21 04:29:29 +08:00
|
|
|
|
// In order to have a consistent current directory on all devices the full path of the app data directory is set as the current directory.
|
2019-10-15 03:46:01 +08:00
|
|
|
|
System.Environment.CurrentDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
|
|
|
|
|
|
2019-01-31 08:07:32 +08:00
|
|
|
|
base.OnCreate(savedInstanceState);
|
|
|
|
|
|
2020-12-03 01:03:49 +08:00
|
|
|
|
OnNewIntent(Intent);
|
|
|
|
|
|
2019-01-31 08:07:32 +08:00
|
|
|
|
Window.AddFlags(WindowManagerFlags.Fullscreen);
|
|
|
|
|
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
|
|
|
|
|
}
|
2020-12-03 01:03:49 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnNewIntent(Intent intent)
|
|
|
|
|
{
|
|
|
|
|
if (intent.Action == Intent.ActionView)
|
|
|
|
|
{
|
|
|
|
|
var filename = intent.Data.Path.Split('/').Last();
|
|
|
|
|
var stream = ContentResolver.OpenInputStream(intent.Data);
|
|
|
|
|
if (stream != null)
|
|
|
|
|
// intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import
|
|
|
|
|
game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, filename)));
|
|
|
|
|
}
|
|
|
|
|
base.OnNewIntent(intent);
|
|
|
|
|
}
|
2019-01-06 12:15:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|