mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Lock screen rotation while in gameplay.
This commit is contained in:
31
osu.Android/GameplayScreenRotationLocker.cs
Normal file
31
osu.Android/GameplayScreenRotationLocker.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// 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.Content.PM;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game;
|
||||||
|
|
||||||
|
namespace osu.Android
|
||||||
|
{
|
||||||
|
public class GameplayScreenRotationLocker : Component
|
||||||
|
{
|
||||||
|
private Bindable<bool> localUserPlaying;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuGame game)
|
||||||
|
{
|
||||||
|
localUserPlaying = game.LocalUserPlaying.GetBoundCopy();
|
||||||
|
localUserPlaying.BindValueChanged(_ => updateLock());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateLock()
|
||||||
|
{
|
||||||
|
OsuGameActivity.Activity.RunOnUiThread(() =>
|
||||||
|
{
|
||||||
|
OsuGameActivity.Activity.RequestedOrientation = localUserPlaying.Value ? ScreenOrientation.Locked : ScreenOrientation.FullUser;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,10 +12,14 @@ namespace osu.Android
|
|||||||
[Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)]
|
[Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ScreenOrientation = ScreenOrientation.FullUser, SupportsPictureInPicture = false, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, HardwareAccelerated = false)]
|
||||||
public class OsuGameActivity : AndroidGameActivity
|
public class OsuGameActivity : AndroidGameActivity
|
||||||
{
|
{
|
||||||
|
internal static Activity Activity;
|
||||||
|
|
||||||
protected override Framework.Game CreateGame() => new OsuGameAndroid();
|
protected override Framework.Game CreateGame() => new OsuGameAndroid();
|
||||||
|
|
||||||
protected override void OnCreate(Bundle savedInstanceState)
|
protected override void OnCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
|
Activity = this;
|
||||||
|
|
||||||
// The default current directory on android is '/'.
|
// 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.
|
// On some devices '/' maps to the app data directory. On others it maps to the root of the internal storage.
|
||||||
// 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.
|
// 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.
|
||||||
|
@ -55,6 +55,12 @@ namespace osu.Android
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
LoadComponentAsync(new GameplayScreenRotationLocker(), Add);
|
||||||
|
}
|
||||||
|
|
||||||
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
<AndroidLinkTool>r8</AndroidLinkTool>
|
<AndroidLinkTool>r8</AndroidLinkTool>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="GameplayScreenRotationLocker.cs" />
|
||||||
<Compile Include="OsuGameActivity.cs" />
|
<Compile Include="OsuGameActivity.cs" />
|
||||||
<Compile Include="OsuGameAndroid.cs" />
|
<Compile Include="OsuGameAndroid.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -53,4 +54,4 @@
|
|||||||
<AndroidResource Include="Resources\drawable\lazer.png" />
|
<AndroidResource Include="Resources\drawable\lazer.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user