Skip to content

Commit

Permalink
Workaround Android handling navigation bar's back vs. edge swipe back…
Browse files Browse the repository at this point in the history
… differently
  • Loading branch information
nirvn committed Jan 2, 2025
1 parent 2bd0b35 commit d57a1d1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions platform/android/src/ch/opengis/qfield/QFieldActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class QFieldActivity extends QtActivity {
public static native void openProject(String url);
public static native void openPath(String path);

public static native void backPressed();
public static native void volumeKeyDown(int volumeKeyCode);
public static native void volumeKeyUp(int volumeKeyCode);

Expand Down Expand Up @@ -208,6 +209,13 @@ public void onNewIntent(Intent intent) {
}
}

@Override
public void onBackPressed() {
// Workaround issue handling navigation bar back vs. edge swipe back
// gesture
backPressed();
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (handleVolumeKeys && (keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
Expand All @@ -216,6 +224,11 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
// Forward volume keys' presses to QField
volumeKeyDown(keyCode);
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
// Workaround issue handling navigation bar back vs. edge swipe back
// gesture
backPressed();
return true;
}
return super.onKeyDown(keyCode, event);
}
Expand All @@ -228,6 +241,8 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
// Forward volume keys's releases to QField
volumeKeyUp(keyCode);
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyUp(keyCode, event);
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/appinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class AppInterface : public QObject
//! Emitted when a volume key is pressed while QField is set to handle those keys.
void volumeKeyUp( int volumeKeyCode );

//! Emitted when the OS 'back' navigation bar or edges swipe gesture has been triggered.
void backPressed();

private:
static AppInterface *sAppInterface;

Expand Down
9 changes: 9 additions & 0 deletions src/core/platforms/android/androidplatformutilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,15 @@ JNIEXPORT void JNICALL JNI_FUNCTION_NAME( APP_PACKAGE_JNI_NAME, QFieldActivity,
#define ANDROID_VOLUME_DOWN 25
#define ANDROID_VOLUME_UP 24

JNIEXPORT void JNICALL JNI_FUNCTION_NAME( APP_PACKAGE_JNI_NAME, QFieldActivity, backPressed )( JNIEnv *env, jobject obj )
{
if ( AppInterface::instance() )
{
emit AppInterface::instance()->backPressed();
}
return;
}

JNIEXPORT void JNICALL JNI_FUNCTION_NAME( APP_PACKAGE_JNI_NAME, QFieldActivity, volumeKeyDown )( JNIEnv *env, jobject obj, int volumeKeyCode )
{
if ( AppInterface::instance() )
Expand Down
6 changes: 6 additions & 0 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ ApplicationWindow {
}

Shortcut {
id: stackShortcut
enabled: true
sequences: ["Escape", StandardKey.Back]
onActivated: {
Expand Down Expand Up @@ -394,6 +395,7 @@ ApplicationWindow {
id: mapCanvas
objectName: "mapCanvas"
clip: true
focus: true

DragHandler {
id: freehandHandler
Expand Down Expand Up @@ -3527,6 +3529,10 @@ ApplicationWindow {
Connections {
target: iface

function onBackPressed() {
stackShortcut.activated();
}

function onVolumeKeyUp(volumeKeyCode) {
if (stateMachine.state === 'browse' || !mapCanvasMap.isEnabled) {
return;
Expand Down

0 comments on commit d57a1d1

Please sign in to comment.