mirror of
https://github.com/encounter/SDL.git
synced 2025-12-08 13:15:10 +00:00
Allow trapping the back button so right mouse click can work on some Android systems (thanks Rachel!)
Also, added a function SDL_AndroidBackButton() so applications can respond to the back button directly
This commit is contained in:
@@ -362,6 +362,43 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
SDLActivity.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// Check if we want to block the back button in case of mouse right click.
|
||||
//
|
||||
// If we do, the normal hardware back button will no longer work and people have to use home,
|
||||
// but the mouse right click will work.
|
||||
//
|
||||
String trapBack = SDLActivity.nativeGetHint("SDL_ANDROID_TRAP_BACK_BUTTON");
|
||||
if ((trapBack != null) && trapBack.equals("1")) {
|
||||
// Exit and let the mouse handler handle this button (if appropriate)
|
||||
return;
|
||||
}
|
||||
|
||||
// Default system back button behavior.
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
// Called by JNI from SDL.
|
||||
public static void manualBackButton() {
|
||||
mSingleton.pressBackButton();
|
||||
}
|
||||
|
||||
// Used to get us onto the activity's main thread
|
||||
public void pressBackButton() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SDLActivity.this.superOnBackPressed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Used to access the system back behavior.
|
||||
public void superOnBackPressed() {
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user