-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to exit/minimize the app on Android when back is pressed #5044
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
479ce6c
Remove unused using
Susko3 f6d99c7
Add a way to allow exiting the app on Android
Susko3 7367e79
Add test
Susko3 abcbb12
Revert changes
Susko3 0c2bfdf
Add `SuspendToBackground()` to GameHost, implemented on Android
Susko3 215d09d
Merge remote-tracking branch 'upstream/master' into android-back
Susko3 c5ea315
Use return value instead of throwing
Susko3 39d4b01
Merge branch 'master' into android-back
peppy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
osu.Framework.Tests/Visual/Platform/TestSceneAllowExitingAndroid.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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 NUnit.Framework; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Input.Events; | ||
using osu.Framework.Platform; | ||
using osuTK.Graphics; | ||
using osuTK.Input; | ||
|
||
namespace osu.Framework.Tests.Visual.Platform | ||
{ | ||
public class TestSceneAllowExitingAndroid : FrameworkTestScene | ||
{ | ||
[Resolved] | ||
private GameHost host { get; set; } | ||
|
||
private readonly BindableBool allowExit = new BindableBool(true); | ||
|
||
public TestSceneAllowExitingAndroid() | ||
{ | ||
Children = new Drawable[] | ||
{ | ||
new ExitVisualiser | ||
{ | ||
Width = 0.5f, | ||
RelativeSizeAxes = Axes.Both, | ||
}, | ||
new EscapeVisualizer | ||
{ | ||
Colour = Color4.Black, | ||
RelativeSizeAxes = Axes.Both, | ||
Width = 0.5f, | ||
Anchor = Anchor.TopRight, | ||
Origin = Anchor.TopRight, | ||
}, | ||
}; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
host.AllowExitingAndroid.AddSource(allowExit); | ||
} | ||
|
||
[Test] | ||
public void TestToggleSuspension() | ||
{ | ||
AddToggleStep("toggle allow exit", v => allowExit.Value = v); | ||
} | ||
|
||
protected override void Dispose(bool isDisposing) | ||
{ | ||
host.AllowExitingAndroid.RemoveSource(allowExit); | ||
base.Dispose(isDisposing); | ||
} | ||
|
||
private class ExitVisualiser : Box | ||
{ | ||
private readonly IBindable<bool> allowExit = new Bindable<bool>(); | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(GameHost host) | ||
{ | ||
allowExit.BindTo(host.AllowExitingAndroid.Result); | ||
allowExit.BindValueChanged(v => Colour = v.NewValue ? Color4.Green : Color4.Red, true); | ||
} | ||
} | ||
|
||
private class EscapeVisualizer : Box | ||
{ | ||
protected override bool OnKeyDown(KeyDownEvent e) | ||
{ | ||
if (e.Key == Key.Escape) | ||
this.FlashColour(Color4.Blue, 700, Easing.OutQuart); | ||
|
||
return base.OnKeyDown(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to rename to
AllowSuspendingAndroid
(AllowSuspendToBackground
without the android suffix maybe?) as it isn't really an exit operation. Not 100% on having android specific variables in here, but I guess it'll have to do for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked and the Android docs seem to call it "stopping the activity" and "moving to background". So
AllowSuspendToBackground
could work. Maybe there's a better name that would encompass the "when back is pressed" part of this.How about
AllowNativeBackNavigation
?