Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8098132

[Android, Ensemble8] App should react to hardware buttons on Android

XMLWordPrintable

      As reported in https://bitbucket.org/javafxports/android/issue/20/ensemble8-app-should-react-to-hardware Ensemble8 on Android should react to the (hardware) menu and back buttons.

      The following patch implements the these actions:
      1. (Hardware) Menu button: open/close menu (depends on RT-35146)
      2. (Hardware) Back button:
         - If menu is open -> close menu
         - If back button is enabled -> go back
         - If clicked twice -> exit app

      Note that the proposed change is currently not restricted to embedded mode.
      Therefore the "windows" menu button (available on some keyboards) and the esc button trigger the same actions on desktops.

      diff -r 22f7e87e105b -r ac3dd00995ba apps/samples/Ensemble8/src/app/java/ensemble/EnsembleApp.java
      --- a/apps/samples/Ensemble8/src/app/java/ensemble/EnsembleApp.java Sat Dec 28 04:28:42 2013 +0100
      +++ b/apps/samples/Ensemble8/src/app/java/ensemble/EnsembleApp.java Sat Dec 28 04:39:10 2013 +0100
      @@ -36,6 +36,7 @@
       import ensemble.control.SearchBox;
       import ensemble.control.TitledToolBar;
       import ensemble.generated.Samples;
      +
       import java.io.BufferedReader;
       import java.io.IOException;
       import java.io.Reader;
      @@ -45,6 +46,7 @@
       import java.nio.channels.ReadableByteChannel;
       import java.util.logging.Level;
       import java.util.logging.Logger;
      +
       import javafx.application.Application;
       import javafx.application.Platform;
       import javafx.event.ActionEvent;
      @@ -56,6 +58,8 @@
       import javafx.scene.Parent;
       import javafx.scene.Scene;
       import javafx.scene.control.*;
      +import javafx.scene.input.KeyCode;
      +import javafx.scene.input.KeyEvent;
       import javafx.scene.input.MouseEvent;
       import javafx.scene.layout.HBox;
       import javafx.scene.layout.Pane;
      @@ -231,6 +235,50 @@
                   }
               });
               
      + // create AndroidStyle Menuhandling
      + root.setOnKeyReleased(new EventHandler<KeyEvent>() {
      + private int exitCount = 0;
      +
      + @Override
      + public void handle(KeyEvent event) {
      + if (event.getCode() == KeyCode.ESCAPE) {
      + if (sampleListPopover.isVisible()) {
      + sampleListPopover.hide();
      + event.consume();
      + return;
      + }
      +
      + if (!backButton.isDisabled()) {
      + pageBrowser.backward();
      + event.consume();
      + return;
      + }
      + exitCount++;
      + if (exitCount == 2) {
      + System.exit(0);
      + }
      + } else {
      + exitCount = 0;
      + }
      +
      + if (event.getCode() == KeyCode.CONTEXT_MENU) {
      + if (sampleListPopover.isVisible()) {
      + sampleListPopover.hide();
      + } else {
      + sampleListPopover.clearPages();
      + sampleListPopover.pushPage(rootPage);
      + sampleListPopover.show(new Runnable() {
      + @Override
      + public void run() {
      + listButton.setSelected(false);
      + }
      + });
      + }
      + event.consume();
      + }
      + }
      + });
      +
               // create and setup search popover
               searchPopover = new SearchPopover(searchBox,pageBrowser);
               root.getChildren().add(searchPopover);

            snorthov Steve Northover (Inactive)
            sfuchsjfx Stefan Fuchs (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: