Skip to content

Commit

Permalink
Merge branch 'master' into bindable-nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Jul 7, 2022
2 parents 36a0f6e + 43fd90c commit b5becda
Show file tree
Hide file tree
Showing 89 changed files with 644 additions and 359 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ jobs:
with:
dotnet-version: "6.0.x"

# macOS agents recently have empty NuGet config files, resulting in restore failures,
# see https://github.com/actions/virtual-environments/issues/5768
# Add the global nuget package source manually for now.
- name: Setup NuGet.Config
run: echo '<configuration><packageSources><add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /></packageSources></configuration>' > ~/.config/NuGet/NuGet.Config

# Contrary to seemingly any other msbuild, msbuild running on macOS/Mono
# cannot accept .sln(f) files as arguments.
# Build just the iOS framework project for now.
Expand Down
2 changes: 0 additions & 2 deletions SampleGame.Android/SampleGameActivity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using Android.App;
using osu.Framework;
using osu.Framework.Android;
Expand Down
10 changes: 10 additions & 0 deletions osu-framework.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,16 @@ See the LICENCE file in the repository root for full licence text.&#xD;
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CustomTools/CustomToolsData/@EntryValue"></s:String>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=Java_002EUtil_002ELogging_002E_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=Microsoft_002EExtensions_002ELogging_002E_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=Microsoft_002EToolkit_002EHighPerformance_002EBox_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=NUnit_002EFramework_002EInternal_002ELogger/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=OpenTabletDriver_002EPlugin_002EDependencyInjection_002E_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=Realms_002ELogging_002ELogger/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=System_002EComponentModel_002EContainer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=System_002ENumerics_002E_002A/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=System_002ESecurity_002ECryptography_002ERSA/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/AutoImport2/=CSHARP/BlackLists/=TagLib_002EMpeg4_002EBox/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002EDaemon_002ESettings_002EMigration_002ESwaWarningsModeSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
34 changes: 12 additions & 22 deletions osu.Framework.Android/AndroidGameActivity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using Android.App;
using Android.Content;
using Android.Content.PM;
Expand All @@ -11,7 +9,7 @@
using Android.Views;
using ManagedBass;
using osu.Framework.Bindables;
using Debug = System.Diagnostics.Debug;
using osu.Framework.Extensions.ObjectExtensions;

namespace osu.Framework.Android
{
Expand Down Expand Up @@ -43,30 +41,25 @@ public abstract class AndroidGameActivity : Activity
/// </summary>
public SystemUiFlags UIVisibilityFlags
{
get
{
Debug.Assert(Window != null);
return (SystemUiFlags)Window.DecorView.SystemUiVisibility;
}
get => (SystemUiFlags)Window.AsNonNull().DecorView.SystemUiVisibility;
set
{
Debug.Assert(Window != null);
systemUiFlags = value;
Window.DecorView.SystemUiVisibility = (StatusBarVisibility)value;
Window.AsNonNull().DecorView.SystemUiVisibility = (StatusBarVisibility)value;
}
}

private SystemUiFlags systemUiFlags;

private AndroidGameView gameView;
private AndroidGameView gameView = null!;

public override void OnTrimMemory([GeneratedEnum] TrimMemory level)
{
base.OnTrimMemory(level);
gameView.Host?.Collect();
}

protected override void OnCreate(Bundle savedInstanceState)
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.
Expand All @@ -79,11 +72,9 @@ protected override void OnCreate(Bundle savedInstanceState)

UIVisibilityFlags = SystemUiFlags.LayoutFlags | SystemUiFlags.ImmersiveSticky | SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen;

Debug.Assert(Window != null);

// Firing up the on-screen keyboard (eg: interacting with textboxes) may cause the UI visibility flags to be altered thus showing the navigation bar and potentially the status bar
// This sets back the UI flags to hidden once the interaction with the on-screen keyboard has finished.
Window.DecorView.SystemUiVisibilityChange += (_, e) =>
Window.AsNonNull().DecorView.SystemUiVisibilityChange += (_, e) =>
{
if ((SystemUiFlags)e.Visibility != systemUiFlags)
{
Expand All @@ -93,8 +84,7 @@ protected override void OnCreate(Bundle savedInstanceState)

if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
{
Debug.Assert(Window.Attributes != null);
Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
Window.AsNonNull().Attributes.AsNonNull().LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
}

gameView.HostStarted += host =>
Expand All @@ -104,9 +94,9 @@ protected override void OnCreate(Bundle savedInstanceState)
RunOnUiThread(() =>
{
if (!allow.NewValue)
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
Window?.AddFlags(WindowManagerFlags.KeepScreenOn);
else
Window.ClearFlags(WindowManagerFlags.KeepScreenOn);
Window?.ClearFlags(WindowManagerFlags.KeepScreenOn);
});
}, true);
};
Expand Down Expand Up @@ -141,17 +131,17 @@ public override void OnBackPressed()
// On some devices and keyboard combinations the OnKeyDown event does not propagate the key event to the view.
// Here it is done manually to ensure that the keys actually land in the view.

public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent? e)
{
return gameView.OnKeyDown(keyCode, e);
}

public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent e)
public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent? e)
{
return gameView.OnKeyUp(keyCode, e);
}

public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent e)
public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent? e)
{
return gameView.OnKeyLongPress(keyCode, e);
}
Expand Down
5 changes: 2 additions & 3 deletions osu.Framework.Android/AndroidGameHost.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System.Collections.Generic;
using System.IO;
using Android.App;
Expand All @@ -11,6 +9,7 @@
using osu.Framework.Android.Graphics.Video;
using osu.Framework.Android.Input;
using osu.Framework.Configuration;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.Video;
using osu.Framework.Input;
Expand Down Expand Up @@ -65,7 +64,7 @@ protected override IEnumerable<InputHandler> CreateAvailableInputHandlers() =>
public override IEnumerable<string> UserStoragePaths => new[]
{
// not null as internal "external storage" is always available.
Application.Context.GetExternalFilesDir(string.Empty)!.ToString(),
Application.Context.GetExternalFilesDir(string.Empty).AsNonNull().ToString(),
};

public override bool OpenFileExternally(string filename) => false;
Expand Down
46 changes: 25 additions & 21 deletions osu.Framework.Android/AndroidGameView.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using Android.Content;
using Android.Graphics;
Expand All @@ -15,19 +13,19 @@
using osu.Framework.Android.Input;
using osu.Framework.Logging;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Platform;
using osuTK.Graphics;
using Debug = System.Diagnostics.Debug;

namespace osu.Framework.Android
{
public class AndroidGameView : osuTK.Android.AndroidGameView
{
public AndroidGameHost Host { get; private set; }
public AndroidGameHost? Host { get; private set; }

public AndroidGameActivity Activity { get; }
public AndroidGameActivity Activity { get; } = null!;

public BindableSafeArea SafeAreaPadding { get; } = new BindableSafeArea();

Expand Down Expand Up @@ -62,9 +60,9 @@ public bool PointerCapture
}
}

private readonly Game game;
private readonly Game game = null!;

private InputMethodManager inputMethodManager;
private InputMethodManager? inputMethodManager;

/// <summary>
/// Whether <see cref="AndroidTextInput"/> is active.
Expand Down Expand Up @@ -128,8 +126,10 @@ public bool OnCommitText(string text)
return false;
}

public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent? e)
{
if (e == null) return base.OnKeyDown(keyCode, e);

switch (keyCode)
{
// Do not consume Volume keys, so the system can handle them
Expand All @@ -151,14 +151,18 @@ public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
}
}

public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent e)
public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent? e)
{
if (e == null) return base.OnKeyLongPress(keyCode, e);

KeyLongPress?.Invoke(keyCode, e);
return true;
}

public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent e)
public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent? e)
{
if (e == null) return base.OnKeyUp(keyCode, e);

KeyUp?.Invoke(keyCode, e);
return true;
}
Expand Down Expand Up @@ -206,12 +210,10 @@ private bool handleException(Exception ex)
/// </summary>
private void updateSafeArea()
{
Debug.Assert(Display != null);

// compute the usable screen area.

var screenSize = new Point();
Display.GetRealSize(screenSize);
Display.AsNonNull().GetRealSize(screenSize);
var screenArea = new RectangleI(0, 0, screenSize.X, screenSize.Y);
var usableScreenArea = screenArea;

Expand Down Expand Up @@ -257,8 +259,10 @@ private void updateSafeArea()
public override bool OnCheckIsTextEditor() => textInputActive;

/// <returns><c>null</c> to disable input methods</returns>
public override IInputConnection OnCreateInputConnection(EditorInfo outAttrs)
public override IInputConnection? OnCreateInputConnection(EditorInfo? outAttrs)
{
if (outAttrs == null) throw new ArgumentNullException(nameof(outAttrs));

// Properly disable native input methods so that the software keyboard doesn't unexpectedly open.
// Eg. when pressing keys on a hardware keyboard.
if (!textInputActive)
Expand All @@ -274,7 +278,7 @@ internal void StartTextInput()
textInputActive = true;
Activity.RunOnUiThread(() =>
{
inputMethodManager.RestartInput(this); // this syncs the Android input method state with `OnCreateInputConnection()`.
inputMethodManager?.RestartInput(this); // this syncs the Android input method state with `OnCreateInputConnection()`.
RequestFocus();
inputMethodManager?.ShowSoftInput(this, 0);
});
Expand All @@ -285,7 +289,7 @@ internal void StopTextInput()
textInputActive = false;
Activity.RunOnUiThread(() =>
{
inputMethodManager.RestartInput(this);
inputMethodManager?.RestartInput(this);
inputMethodManager?.HideSoftInputFromWindow(WindowToken, HideSoftInputFlags.None);
ClearFocus();
});
Expand Down Expand Up @@ -316,27 +320,27 @@ public override void SwapBuffers()
/// <summary>
/// Invoked on a key down event.
/// </summary>
public new event Action<Keycode, KeyEvent> KeyDown;
public new event Action<Keycode, KeyEvent>? KeyDown;

/// <summary>
/// Invoked on a key up event.
/// </summary>
public new event Action<Keycode, KeyEvent> KeyUp;
public new event Action<Keycode, KeyEvent>? KeyUp;

/// <summary>
/// Invoked on a key long press event.
/// </summary>
public event Action<Keycode, KeyEvent> KeyLongPress;
public event Action<Keycode, KeyEvent>? KeyLongPress;

/// <summary>
/// Invoked when text is committed by an <see cref="AndroidInputConnection"/>.
/// </summary>
public event Action<string> CommitText;
public event Action<string>? CommitText;

/// <summary>
/// Invoked when the <see cref="game"/> has been started on the <see cref="Host"/>.
/// </summary>
public event Action<AndroidGameHost> HostStarted;
public event Action<AndroidGameHost>? HostStarted;

#endregion
}
Expand Down
4 changes: 1 addition & 3 deletions osu.Framework.Android/AndroidGameWindow.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using osu.Framework.Bindables;
Expand All @@ -29,7 +27,7 @@ public override Platform.WindowState WindowState
set { }
}

public event Action CursorStateChanged;
public event Action? CursorStateChanged;

public override CursorState CursorState
{
Expand Down
2 changes: 0 additions & 2 deletions osu.Framework.Android/AndroidStorage.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Platform;

namespace osu.Framework.Android
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.IO;
using Android.Graphics;
Expand Down
10 changes: 3 additions & 7 deletions osu.Framework.Android/Graphics/Video/AndroidVideoDecoder.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using Android.Runtime;
using FFmpeg.AutoGen;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics.Video;
using osu.Framework.Logging;

Expand Down Expand Up @@ -151,11 +149,9 @@ public AndroidVideoDecoder(Stream videoStream)
const string java_vm_field_name = "java_vm";

var jvmPtrInfo = typeof(JNIEnv).GetField(java_vm_field_name, BindingFlags.NonPublic | BindingFlags.Static);
object jvmPtrObj = jvmPtrInfo?.GetValue(null);

Debug.Assert(jvmPtrObj != null);
object? jvmPtrObj = jvmPtrInfo?.GetValue(null);

int result = av_jni_set_java_vm((void*)(IntPtr)jvmPtrObj, null);
int result = av_jni_set_java_vm((void*)(IntPtr)jvmPtrObj.AsNonNull(), null);
if (result < 0)
throw new InvalidOperationException($"Couldn't pass Java VM handle to FFmpeg: ${result}");
}
Expand Down
Loading

0 comments on commit b5becda

Please sign in to comment.