forked from libgdx/libgdx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for predictive back gestures (libgdx#7429)
* Remove back/menu methods (deprecated 5 years ago) * Add enableOnBackInvokedCallback to gdx-tests manifest * Add back invoke support and test * Update CHANGES * Apply formatter * Realised where I went wrong with inner class * No-one else is using @nullable so I guess I shouldn't either * Suppose it covers GWT as well * Undo constructor nonsense * Fix malformed Javadoc * Apply formatter * Continuation of e074acc reversion, nearly forgot * Revisit BackTest * Apply formatter * Make test exclusive to Android It doesn't make sense for different platforms. Input.Keys.BACK doesn't catch the browser back button on GWT. * Less ambiguous class name * Apply formatter * Less dumb-dumb anchor * final PredictiveBackHandler * Apply formatter * Mostly revert 5b2d072 * Remove unneeded `if` nesting --------- Co-authored-by: GitHub Action <[email protected]>
- Loading branch information
1 parent
c856c16
commit 892dee6
Showing
10 changed files
with
127 additions
and
112 deletions.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
package com.badlogic.gdx.tests; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.Input; | ||
import com.badlogic.gdx.InputAdapter; | ||
import com.badlogic.gdx.graphics.Color; | ||
import com.badlogic.gdx.graphics.g2d.BitmapFont; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.tests.utils.GdxTest; | ||
import com.badlogic.gdx.utils.ScreenUtils; | ||
import com.badlogic.gdx.utils.viewport.FitViewport; | ||
import com.badlogic.gdx.utils.viewport.Viewport; | ||
|
||
/** Check if predictive back gesture works, loosely modeled upon Android's back stack. Tap the screen to increment the counter. Go | ||
* back to decrement the counter. If the counter is 0, the test will be exited. */ | ||
public class BackTest extends GdxTest { | ||
|
||
private SpriteBatch batch; | ||
private BitmapFont font; | ||
private final Viewport viewport = new FitViewport(160, 90); | ||
|
||
private int stackDepth; | ||
|
||
@Override | ||
public void create () { | ||
batch = new SpriteBatch(); | ||
font = new BitmapFont(); | ||
Gdx.input.setInputProcessor(new InputAdapter() { | ||
|
||
@Override | ||
public boolean touchDown (int screenX, int screenY, int pointer, int button) { | ||
int screenWidth = Gdx.graphics.getBackBufferWidth(); | ||
float safeZone = screenWidth * .1f; | ||
if (screenX >= safeZone && screenX < screenWidth - safeZone) { | ||
stackDepth++; | ||
Gdx.input.setCatchKey(Input.Keys.BACK, stackDepth > 0); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean keyDown (int keycode) { | ||
if (keycode == Input.Keys.BACK) { | ||
stackDepth--; | ||
Gdx.input.setCatchKey(Input.Keys.BACK, stackDepth > 0); | ||
return true; | ||
} | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void render () { | ||
ScreenUtils.clear(Color.BLACK); | ||
batch.begin(); | ||
font.draw(batch, "Stack depth: " + stackDepth, 20, 50); | ||
batch.end(); | ||
} | ||
|
||
@Override | ||
public void resize (int width, int height) { | ||
viewport.update(width, height, true); | ||
batch.setProjectionMatrix(viewport.getCamera().combined); | ||
} | ||
|
||
} |