Skip to content

Commit

Permalink
Added "Trap Back button" option to Android prelaunch menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg committed Feb 20, 2020
1 parent 55cabb7 commit 6169bce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class SplashScreen extends Activity {
private static final int INSTALL_DIALOG_ID = 0;
private ProgressDialog installDialog;

public CharSequence[] mSettingsNames = { "Software rendering", "Force fullscreen" };
public boolean[] mSettingsValues = { false, false};
public CharSequence[] mSettingsNames = { "Software rendering", "Force fullscreen", "Trap Back button" };
public boolean[] mSettingsValues = { false, false, true };

private String getVersionName() {
try {
Expand Down
6 changes: 6 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,12 @@ void options_manager::add_options_android()

add_empty_line();

add( "ANDROID_TRAP_BACK_BUTTON", "android", translate_marker( "Trap Back button" ),
translate_marker( "If true, the back button will NOT back out of the app and will be passed to the application as SDL_SCANCODE_AC_BACK. Requires restart." ),
// take default setting from pre-game settings screen - important as there are issues with Back button on Android 9 with specific devices
android_get_default_setting( "Trap Back button", true )
);

add( "ANDROID_AUTO_KEYBOARD", "android", translate_marker( "Auto-manage virtual keyboard" ),
translate_marker( "If true, automatically show/hide the virtual keyboard when necessary based on context. If false, virtual keyboard must be toggled manually." ),
true
Expand Down
6 changes: 6 additions & 0 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ static void WinCreate()
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );

// Fix Back button crash on Android 9
#if defined(SDL_HINT_ANDROID_TRAP_BACK_BUTTON )
const bool trap_back_button = get_option<bool>( "ANDROID_TRAP_BACK_BUTTON" );
SDL_SetHint( SDL_HINT_ANDROID_TRAP_BACK_BUTTON, trap_back_button ? "1" : "0" );
#endif

// Prevent mouse|touch input confusion
#if defined(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH)
SDL_SetHint( SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, "1" );
Expand Down

0 comments on commit 6169bce

Please sign in to comment.