mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Put generalized activity in the framework. Do not use a static field as a hack
This commit is contained in:
@@ -12,8 +12,7 @@
|
||||
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="SampleGameView.cs" />
|
||||
<Compile Include="SampleGameActivity.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Properties\AndroidManifest.xml" />
|
||||
|
||||
17
SampleGame.Android/SampleGameActivity.cs
Normal file
17
SampleGame.Android/SampleGameActivity.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
||||
|
||||
using Android.App;
|
||||
using Android.Content.PM;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Android;
|
||||
|
||||
namespace SampleGame.Android
|
||||
{
|
||||
[Activity(MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, Theme = "@android:style/Theme.NoTitleBar")]
|
||||
public class SampleGameActivity : AndroidGameActivity
|
||||
{
|
||||
protected override Game CreateGame()
|
||||
=> new SampleGameGame();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
||||
|
||||
using Android.Content;
|
||||
using Android.Util;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Android;
|
||||
|
||||
namespace SampleGame.Android
|
||||
{
|
||||
public class SampleGameView : AndroidGameView
|
||||
{
|
||||
public SampleGameView(Context context, IAttributeSet attrs) :
|
||||
base(context, attrs)
|
||||
{
|
||||
}
|
||||
|
||||
public SampleGameView(Context context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public override Game CreateGame() => new SampleGameGame();
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
using Android.App;
|
||||
using Android.OS;
|
||||
using Android.Content.PM;
|
||||
using Android.Views;
|
||||
|
||||
namespace SampleGame.Android
|
||||
namespace osu.Framework.Android
|
||||
{
|
||||
[Activity(ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, MainLauncher = true, Theme = "@android:style/Theme.NoTitleBar")]
|
||||
public class MainActivity : Activity
|
||||
public abstract class AndroidGameActivity : Activity
|
||||
{
|
||||
protected abstract Game CreateGame();
|
||||
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
@@ -18,7 +18,7 @@ namespace SampleGame.Android
|
||||
Window.AddFlags(WindowManagerFlags.Fullscreen);
|
||||
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
|
||||
|
||||
SetContentView(new SampleGameView(this));
|
||||
SetContentView(new AndroidGameView(this, CreateGame()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,7 @@ namespace osu.Framework.Android
|
||||
public AndroidGameHost(AndroidGameView gameView)
|
||||
{
|
||||
this.gameView = gameView;
|
||||
AndroidGameWindow.view = gameView;
|
||||
Window = new AndroidGameWindow();
|
||||
Window = new AndroidGameWindow(gameView);
|
||||
}
|
||||
|
||||
public override ITextInputSource GetTextInput()
|
||||
|
||||
@@ -9,14 +9,14 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Framework.Android
|
||||
{
|
||||
public abstract class AndroidGameView : osuTK.Android.AndroidGameView
|
||||
public class AndroidGameView : osuTK.Android.AndroidGameView
|
||||
{
|
||||
private AndroidGameHost host;
|
||||
private Game game;
|
||||
|
||||
public abstract Game CreateGame();
|
||||
|
||||
public AndroidGameView(Context context) : base(context)
|
||||
public AndroidGameView(Context context, Game game) : base(context)
|
||||
{
|
||||
this.game = game;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace osu.Framework.Android
|
||||
public void RenderGame()
|
||||
{
|
||||
host = new AndroidGameHost(this);
|
||||
host.Run(CreateGame());
|
||||
host.Run(game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ namespace osu.Framework.Android
|
||||
{
|
||||
public class AndroidGameWindow : GameWindow
|
||||
{
|
||||
internal static AndroidGameView view;
|
||||
public override IGraphicsContext Context
|
||||
=> Implementation.GraphicsContext;
|
||||
|
||||
public override IGraphicsContext Context => view.GraphicsContext;
|
||||
protected new AndroidGameView Implementation
|
||||
=> base.Implementation as AndroidGameView;
|
||||
|
||||
public override bool Focused
|
||||
=> true;
|
||||
@@ -21,7 +23,7 @@ namespace osu.Framework.Android
|
||||
set { }
|
||||
}
|
||||
|
||||
public AndroidGameWindow() : base(view)
|
||||
public AndroidGameWindow(AndroidGameView view) : base(view)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
||||
|
||||
using Android.App;
|
||||
using Android.Content.PM;
|
||||
using Android.OS;
|
||||
using Android.Views;
|
||||
|
||||
namespace osu.Framework.Tests.Android
|
||||
{
|
||||
[Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
|
||||
public class MainActivity : Activity
|
||||
{
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
base.OnCreate(savedInstanceState);
|
||||
|
||||
Window.AddFlags(WindowManagerFlags.Fullscreen);
|
||||
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
|
||||
|
||||
SetContentView(new TestGameView(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
16
osu.Framework.Tests.Android/TestGameActivity.cs
Normal file
16
osu.Framework.Tests.Android/TestGameActivity.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
||||
|
||||
using Android.App;
|
||||
using Android.Content.PM;
|
||||
using osu.Framework.Android;
|
||||
|
||||
namespace osu.Framework.Tests.Android
|
||||
{
|
||||
[Activity(MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, Theme = "@android:style/Theme.NoTitleBar")]
|
||||
public class TestGameActivity : AndroidGameActivity
|
||||
{
|
||||
protected override Game CreateGame()
|
||||
=> new VisualTestGame();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
||||
|
||||
using Android.Content;
|
||||
using Android.Util;
|
||||
|
||||
using osu.Framework.Android;
|
||||
|
||||
namespace osu.Framework.Tests.Android
|
||||
{
|
||||
public class TestGameView : AndroidGameView
|
||||
{
|
||||
public TestGameView(Context context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public TestGameView(Context context, IAttributeSet attrs) : base(context, attrs)
|
||||
{
|
||||
}
|
||||
|
||||
public override Game CreateGame() => new VisualTestGame();
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,7 @@
|
||||
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="TestGameView.cs" />
|
||||
<Compile Include="TestGameActivity.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Properties\AndroidManifest.xml" />
|
||||
|
||||
Reference in New Issue
Block a user