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

[Android] Hide keyboard when user taps outside a TextInputControl

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: openjfx15
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
      None

      Description

      The soft keyboard hides when a TextInputControl loses focus. This works for most cases, but when focus moves from one TextInputControl to another, the keyboard hides and then shows itself.

      Native android apps hide the keyboard when a users taps anywhere on the scene which is not a TextInputControl.

      For this change, the native method `hideSoftwareKeyboard` needs to be made accessible to Scene.

      A MOUSE_CLICKED event filter needs to be added to Scene and focus listeners from both TextFieldSkinAndroid and TextAreaSkinAndroid needs to be removed.

      Expected change:

      ```
      scene.addEventFilter(MouseEvent.MOUSE_CLICKED, evt -> {
              if (!containsTextInputControlInHierarchy(evt.getPickResult().getIntersectedNode())) {
                  hideSoftwareKeyboard();
             }
      });

      ...

      public static boolean containsTextInputControlInHierarchy(Node node) {
          while (node != null) {
              if (node instanceof TextInputControl) {
                  return true;
              }
              node = node.getParent();
          }
          return false;
      }
      ```

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abagarwal Abhinay Agarwal
                Reporter:
                abagarwal Abhinay Agarwal
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: