Skip to content

Commit 2679b45

Browse files
author
Chris Warren-Smith
committed
ANDROID: updated back-key handling to avoid potential double action
1 parent 0a77735 commit 2679b45

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SmallBASIC is a fast and easy to learn BASIC language interpreter ideal for ever
99
Ubuntu
1010

1111
```
12-
sudo apt-get install git autotools-dev automake gcc g++ libsdl2-dev libfreetype6-dev libfontconfig1-dev xxd
12+
sudo apt-get install git autotools-dev automake gcc g++ libsdl2-dev libfreetype6-dev libfontconfig1-dev xxd make
1313
```
1414

1515
Manjaro (Arch)

images/keypad/build.sh renamed to keypad/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ do
3535
xxd -n img_${imageFile} -i ${imageFile}.png >> keypad_icons.h
3636
done
3737

38-
mv keypad_icons.h ../../src/ui
38+
mv keypad_icons.h ../src/ui
3939

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ public int getWindowHeight() {
429429
return rect.height();
430430
}
431431

432+
public boolean isPredictiveBack() {
433+
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
434+
}
435+
432436
public boolean loadModules() {
433437
Log.i(TAG, "loadModules: " + getActivity());
434438
boolean result;
@@ -1063,7 +1067,7 @@ private void setImmersiveMode() {
10631067
// Hook into Predictive Back (Android 13+)
10641068
//
10651069
private void setupPredictiveBack() {
1066-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
1070+
if (isPredictiveBack()) {
10671071
getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
10681072
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
10691073
new OnBackInvokedCallback() {

src/platform/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:8.11.1'
8+
classpath 'com.android.tools.build:gradle:8.12.0'
99
}
1010
}
1111

src/platform/android/jni/runtime.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Runtime *runtime = nullptr;
3333
// Pipe file descriptors: g_backPipe[0] is read-end, g_backPipe[1] is write-end
3434
static int g_backPipe[2] = {-1, -1};
3535

36+
// whether native back key handling is active
37+
static bool g_predictiveBack = false;
38+
3639
// the sensorTypes corresponding to _sensors[] positions
3740
constexpr int SENSOR_TYPES[MAX_SENSORS] = {
3841
ASENSOR_TYPE_ACCELEROMETER,
@@ -159,7 +162,7 @@ static void process_input(android_app *app, android_poll_source *source) {
159162
AKeyEvent_getKeyCode(event) == AKEYCODE_BACK) {
160163
// prevent AInputQueue_preDispatchEvent from attempting to close
161164
// the keypad here to avoid a crash in android 4.2 + 4.3.
162-
if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN && runtime->isActive()) {
165+
if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN && runtime->isActive() && !g_predictiveBack) {
163166
pushBackEvent();
164167
}
165168
AInputQueue_finishEvent(app->inputQueue, event, true);
@@ -287,7 +290,10 @@ Runtime::Runtime(android_app *app) :
287290
_looper = ALooper_forThread();
288291
_sensorManager = ASensorManager_getInstance();
289292
memset(&_sensors, 0, sizeof(_sensors));
290-
setupBackWakePipe(_looper);
293+
g_predictiveBack = getBoolean("isPredictiveBack");
294+
if (g_predictiveBack) {
295+
setupBackWakePipe(_looper);
296+
}
291297
}
292298

293299
Runtime::~Runtime() {

0 commit comments

Comments
 (0)