Merge pull request #12119 from RameshRavone/patch-12

export onBackPress for Android Module
This commit is contained in:
Rémi Verschelde 2017-10-15 10:11:29 +02:00 committed by GitHub
commit 8b95e3bf11
2 changed files with 10 additions and 8 deletions

View File

@ -191,6 +191,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
protected void onMainPause() {} protected void onMainPause() {}
protected void onMainResume() {} protected void onMainResume() {}
protected void onMainDestroy() {} protected void onMainDestroy() {}
protected boolean onMainBackPressed() { return false; }
protected void onGLDrawFrame(GL10 gl) {} protected void onGLDrawFrame(GL10 gl) {}
protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call
@ -767,9 +768,16 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
*/ */
@Override public void onBackPressed() { @Override public void onBackPressed() {
boolean shouldQuit = true;
for(int i=0;i<singleton_count;i++) {
if (singletons[i].onMainBackPressed()) {
shouldQuit = false;
}
}
System.out.printf("** BACK REQUEST!\n"); System.out.printf("** BACK REQUEST!\n");
if (mView != null) { if (shouldQuit && mView != null) {
mView.queueEvent(new Runnable() { mView.queueEvent(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -285,13 +285,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
@Override public boolean onKeyDown(final int keyCode, KeyEvent event) { @Override public boolean onKeyDown(final int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
queueEvent(new Runnable() { activity.onBackPressed();
@Override
public void run() {
GodotLib.back();
}
});
// press 'back' button should not terminate program // press 'back' button should not terminate program
//normal handle 'back' event in game logic //normal handle 'back' event in game logic
return true; return true;