Reputation: 53
I've recently migrated our javafx mobile app from Java 8 to 11. And finally configured Gluon client plugin and built APK.
To handle back button events in android device, I've already added 'Esc' key event handler to the scene as suggested in this answer. Below is how I added the keyevent handler to the scene(print statements are for debugging purposes).
scene.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
System.out.println("Key Pressed event is called");
if (event.getCode() == KeyCode.ESCAPE) {
System.out.println("Escape key is pressed");
if (currentView != null) {
System.out.println("Going Back : currentView.getPresenter().goBack()");
currentView.getPresenter().goBack();
} else {
System.out.println("Going Back : StageManager.getInstance().goBackInternal()");
StageManager.getInstance().goBackInternal();
}
}
});
Previously(Java 8 + JavaFXPorts), with this same handler, back button handling was working with no issues.
With the migrated app(Java 11 + Gluon Client), back button is working at first; but after opening and closing a dialog box(javafx.scene.control.Dialog), the key event handler isn't getting called anymore.
I've put some print statements in the key event handler(as shown in the code snippet above) and tested. Those statements are not executed after an interaction with a 'Dialog'.
Before interacting with a dialog (in Android device):-
2021-06-15 20:17:57.338 25707-25707/com.fivedtech.parent.app V/GraalActivity: Activity, process get key event, action = 0
2021-06-15 20:17:57.338 25707-25707/com.fivedtech.parent.app I/System.out: KeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=158, metaState=0, flags=0x48, repeatCount=0, eventTime=770684447, downTime=770684447, deviceId=6, source=0x101 } with action = 0
2021-06-15 20:17:57.348 25707-25707/com.fivedtech.parent.app I/System.out: [JVDBG] eventkeycode = 4 and jfxkc = ESCAPE with code 27
2021-06-15 20:17:57.348 25707-25707/com.fivedtech.parent.app E/GraalGluon: Native Dalvik layer has to dispatch key event, pass to native Graal layer with 1 chars...
2021-06-15 20:17:57.348 25707-25707/com.fivedtech.parent.app E/GraalGluon: passed count = 1 and realcount = 1
2021-06-15 20:17:57.348 25707-25707/com.fivedtech.parent.app E/GraalGluon: c0 = and c1 = �
2021-06-15 20:17:57.348 25707-25707/com.fivedtech.parent.app E/GraalGluon: c0 = 1b and c1 = 5ac5
2021-06-15 20:17:57.349 25707-25728/com.fivedtech.parent.app D/GraalCompiled: Key Pressed event is called
2021-06-15 20:17:57.349 25707-25728/com.fivedtech.parent.app D/GraalCompiled: Escape key is pressed
2021-06-15 20:17:57.349 25707-25728/com.fivedtech.parent.app D/GraalCompiled: Going Back : currentView.getPresenter().goBack()
2021-06-15 20:17:57.438 1551-1665/? W/BaseMiuiPhoneWindowManager: keyCode:4 down:false eventTime:770684556 downTime:770684447 policyFlags:22000002 flags:48 deviceId:6 isScreenOn:true keyguardActive:false repeatCount:0
2021-06-15 20:17:57.440 25707-25707/com.fivedtech.parent.app V/GraalActivity: Activity, process get key event, action = 1
2021-06-15 20:17:57.440 25707-25707/com.fivedtech.parent.app I/System.out: KeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=158, metaState=0, flags=0x48, repeatCount=0, eventTime=770684556, downTime=770684447, deviceId=6, source=0x101 } with action = 1
2021-06-15 20:17:57.440 25707-25707/com.fivedtech.parent.app E/GraalGluon: Native Dalvik layer has to dispatch key event, pass to native Graal layer with 1 chars...
2021-06-15 20:17:57.440 25707-25707/com.fivedtech.parent.app E/GraalGluon: passed count = 1 and realcount = 1
2021-06-15 20:17:57.440 25707-25707/com.fivedtech.parent.app E/GraalGluon: c0 = and c1 =
2021-06-15 20:17:57.440 25707-25707/com.fivedtech.parent.app E/GraalGluon: c0 = 1b and c1 = 0
After interacting with a dialog (in Android device):-
2021-06-15 20:20:21.060 25707-25707/com.fivedtech.parent.app V/GraalActivity: Activity, process get key event, action = 0
2021-06-15 20:20:21.061 25707-25707/com.fivedtech.parent.app I/System.out: KeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=158, metaState=0, flags=0x48, repeatCount=0, eventTime=770828175, downTime=770828175, deviceId=6, source=0x101 } with action = 0
2021-06-15 20:20:21.061 25707-25707/com.fivedtech.parent.app I/System.out: [JVDBG] eventkeycode = 4 and jfxkc = ESCAPE with code 27
2021-06-15 20:20:21.061 25707-25707/com.fivedtech.parent.app E/GraalGluon: Native Dalvik layer has to dispatch key event, pass to native Graal layer with 1 chars...
2021-06-15 20:20:21.061 25707-25707/com.fivedtech.parent.app E/GraalGluon: passed count = 1 and realcount = 1
2021-06-15 20:20:21.061 25707-25707/com.fivedtech.parent.app E/GraalGluon: c0 = and c1 =
2021-06-15 20:20:21.061 25707-25707/com.fivedtech.parent.app E/GraalGluon: c0 = 1b and c1 = 0
2021-06-15 20:20:21.097 1551-1665/? W/BaseMiuiPhoneWindowManager: keyCode:4 down:false eventTime:770828215 downTime:770828175 policyFlags:22000002 flags:48 deviceId:6 isScreenOn:true keyguardActive:false repeatCount:0
2021-06-15 20:20:21.100 25707-25707/com.fivedtech.parent.app V/GraalActivity: Activity, process get key event, action = 1
2021-06-15 20:20:21.100 25707-25707/com.fivedtech.parent.app I/System.out: KeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=158, metaState=0, flags=0x48, repeatCount=0, eventTime=770828215, downTime=770828175, deviceId=6, source=0x101 } with action = 1
2021-06-15 20:20:21.100 25707-25707/com.fivedtech.parent.app E/GraalGluon: Native Dalvik layer has to dispatch key event, pass to native Graal layer with 1 chars...
2021-06-15 20:20:21.100 25707-25707/com.fivedtech.parent.app E/GraalGluon: passed count = 1 and realcount = 1
2021-06-15 20:20:21.100 25707-25707/com.fivedtech.parent.app E/GraalGluon: c0 = and c1 =
2021-06-15 20:20:21.100 25707-25707/com.fivedtech.parent.app E/GraalGluon: c0 = 1b and c1 = 0
Since the back button handling was working with java8+javafxports, is this some issue related to building APK with Gluon Client Plugin? Is there any fix this issue?
UPDATE #1:- The 'Esc' key handler assigned to the scene isn't getting called after interacting with a dialog ONLY in android device. When I run the app in desktop this key handler works fine. Below is a code snippet that shows a dialog in one of the screens.
@FXML
private void cancelButtonClicked() {
System.out.println("Before showing dialog...");
FDTDialog dialog = new FDTDialog(FDTDialogType.CONFIRMATION);
dialog.setAlertTitle("");
dialog.setAlertMessage(UPDATE_CANCELLED_MESSAGE);
dialog.setAlertImage(new Image("/images/warning_img.png"));
Optional<ButtonType> result = dialog.showAndWait();
if (result != null && result.isPresent()) {
if (result.get() == ButtonType.YES) {
StageManager.showBody(new HomeView());
}
System.out.println("Dialog is hidden");
}
}
Here's the console output in which we can see that the handler works even after closing a dialog.
Key Pressed event is called
Escape key is pressed
Going Back : currentView.getPresenter().goBack()
Before showing dialog...
Dialog is hidden
Key Pressed event is called
Escape key is pressed
Going Back : currentView.getPresenter().goBack()
From the above console output, I can say that the scene is same and the event also exists. So, why does this issue occur only in mobile?
Upvotes: 0
Views: 120