1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00
osu-lazer/osu.Android/GameplayScreenRotationLocker.cs
2020-10-16 19:21:51 +02:00

32 lines
1007 B
C#

// 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(userPlaying => updateLock(userPlaying));
}
private void updateLock(ValueChangedEvent<bool> userPlaying)
{
OsuGameActivity.Activity.RunOnUiThread(() =>
{
OsuGameActivity.Activity.RequestedOrientation = userPlaying.NewValue ? ScreenOrientation.Locked : ScreenOrientation.FullUser;
});
}
}
}