1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00
osu-lazer/osu.Android/OsuGameActivity.cs

64 lines
2.6 KiB
C#
Raw Normal View History

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.
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Net;
2019-01-31 08:07:32 +08:00
using Android.OS;
using Android.Provider;
2019-01-31 08:07:32 +08:00
using Android.Views;
using osu.Framework.Android;
namespace osu.Android
{
[Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)]
[IntentFilter(new[] { Intent.ActionDefault, Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataPathPatterns = new[] { ".*\\.osz", ".*\\.osk" }, DataMimeType = "application/*")]
public class OsuGameActivity : AndroidGameActivity
{
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)
{
// 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.
System.Environment.CurrentDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
2019-01-31 08:07:32 +08:00
base.OnCreate(savedInstanceState);
OnNewIntent(Intent);
2019-01-31 08:07:32 +08:00
Window.AddFlags(WindowManagerFlags.Fullscreen);
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
}
protected override void OnNewIntent(Intent intent)
{
2020-12-06 03:42:07 +08:00
if (intent.Action == Intent.ActionDefault && intent.Scheme == ContentResolver.SchemeContent)
{
2020-12-06 03:42:07 +08:00
handleImportFromUri(intent.Data);
}
2020-12-05 05:07:45 +08:00
if (intent.Action == Intent.ActionSend)
{
var content = intent.ClipData.GetItemAt(0);
handleImportFromUri(content.Uri);
}
}
private void handleImportFromUri(Uri uri)
{
2020-12-06 03:42:07 +08:00
var cursor = ContentResolver.Query(uri, new[] { OpenableColumns.DisplayName }, null, null);
var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName);
cursor.MoveToFirst();
var stream = ContentResolver.OpenInputStream(uri);
if (stream != null)
2020-12-06 03:42:07 +08:00
game.ScheduleImport(stream, cursor.GetString(filename_column));
}
}
}