Skip to content

Commit

Permalink
8242163: Android keyboard integration fails
Browse files Browse the repository at this point in the history
Reviewed-by: kcr
  • Loading branch information
Johan Vos committed Apr 7, 2020
1 parent 364c64a commit 844460b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@
* questions.
*/

package com.sun.javafx.scene.control.skin;
package javafx.scene.control.skin;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
Expand All @@ -40,12 +40,16 @@ public void changed(ObservableValue<? extends Boolean> observable,
Boolean wasFocused, Boolean isFocused) {
if (textArea.isEditable()) {
if (isFocused) {
com.sun.glass.ui.android.SoftwareKeyboard.show();
showSoftwareKeyboard();
} else {
com.sun.glass.ui.android.SoftwareKeyboard.hide();
hideSoftwareKeyboard();
}
}
}
});
}

native void showSoftwareKeyboard();
native void hideSoftwareKeyboard();

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@
* questions.
*/

package com.sun.javafx.scene.control.skin;
package javafx.scene.control.skin;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
Expand All @@ -42,16 +42,16 @@ public void changed(ObservableValue<? extends Boolean> observable,
Boolean wasFocused, Boolean isFocused) {
if (textField.isEditable()) {
if (isFocused) {
com.sun.glass.ui.android.SoftwareKeyboard.show();
showSoftwareKeyboard();
} else {
com.sun.glass.ui.android.SoftwareKeyboard.hide();
hideSoftwareKeyboard();
}
}
}
});
}

public TextFieldSkinAndroid(final TextField textField, final TextFieldBehavior behavior) {
super(textField, behavior);
}
native void showSoftwareKeyboard();
native void hideSoftwareKeyboard();

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -37,7 +37,7 @@
******************************************************************************/

.text-field {
-fx-skin: "com.sun.javafx.scene.control.skin.TextFieldSkinAndroid";
-fx-skin: "javafx.scene.control.skin.TextFieldSkinAndroid";
}


Expand All @@ -48,6 +48,6 @@
******************************************************************************/

.text-area {
-fx-skin: "com.sun.javafx.scene.control.skin.TextAreaSkinAndroid";
-fx-skin: "javafx.scene.control.skin.TextAreaSkinAndroid";
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -37,7 +37,7 @@
******************************************************************************/

.text-field {
-fx-skin: "com.sun.javafx.scene.control.skin.TextFieldSkinAndroid";
-fx-skin: "javafx.scene.control.skin.TextFieldSkinAndroid";
}


Expand All @@ -48,6 +48,6 @@
******************************************************************************/

.text-area {
-fx-skin: "com.sun.javafx.scene.control.skin.TextAreaSkinAndroid";
-fx-skin: "javafx.scene.control.skin.TextAreaSkinAndroid";
}

Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ private void gotTouchEvent(TouchState touchState) {
}


public static void dispatchKeyEventFromNative(int type, int key, char[] chars, int modifiers) {
instance.processor.dispatchKeyEvent(type, key, chars, modifiers);
}

public static void gotKeyEventFromNative(int action, int linuxKey) {
instance.gotKeyEvent (action, linuxKey);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,8 @@
*/
package com.sun.glass.ui.monocle;

import javafx.application.Platform;

class AndroidInputProcessor {

private final AndroidInputDevice device;
Expand Down Expand Up @@ -54,4 +56,18 @@ synchronized void pushKeyEvent(KeyState keyState) {
keyInput.setState(keyState);
}

synchronized void dispatchKeyEvent(int type, int key, char[] chars, int modifiers) {
Platform.runLater( () -> {
MonocleWindow window = (MonocleWindow) MonocleWindowManager.getInstance().getFocusedWindow();
if (window == null) {
return;
}
MonocleView view = (MonocleView) window.getView();
if (view == null) {
return;
}
RunnableProcessor.runLater( () -> view.notifyKey(type, key, chars, modifiers));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static jclass jAndroidInputDeviceRegistryClass;
static jclass jMonocleWindowManagerClass;

static jmethodID monocle_gotTouchEventFromNative;
static jmethodID monocle_gotKeyEventFromNative;
static jmethodID monocle_dispatchKeyEventFromNative;
static jmethodID monocle_repaintAll;
static jmethodID monocle_registerDevice;

Expand All @@ -57,9 +57,9 @@ void initializeFromJava (JNIEnv *env) {
monocle_gotTouchEventFromNative = (*env)->GetStaticMethodID(
env, jAndroidInputDeviceRegistryClass, "gotTouchEventFromNative",
"(I[I[I[I[II)V");
monocle_gotKeyEventFromNative = (*env)->GetStaticMethodID(
env, jAndroidInputDeviceRegistryClass, "gotKeyEventFromNative",
"(II)V");
monocle_dispatchKeyEventFromNative = (*env)->GetStaticMethodID(
env, jAndroidInputDeviceRegistryClass, "dispatchKeyEventFromNative",
"(II[CI)V");
monocle_registerDevice = (*env)->GetStaticMethodID(env, jAndroidInputDeviceRegistryClass, "registerDevice","()V");
GLASS_LOG_FINE("Initializing native Android Bridge done");
}
Expand Down Expand Up @@ -116,7 +116,23 @@ void androidJfx_gotTouchEvent (int count, int* actions, int* ids, int* xs, int*

(*javaEnv)->CallStaticVoidMethod(javaEnv, jAndroidInputDeviceRegistryClass, monocle_gotTouchEventFromNative,
jcount, jactions, jids, jxs, jys, primary);
}

void androidJfx_gotKeyEvent (int action, int keyCode, jchar* chars, int count, int mods) {
initializeFromNative();
if (javaEnv == NULL) {
GLASS_LOG_FINE("javaEnv still null, not ready to process touch events");
return;
}
if (deviceRegistered == 0) {
deviceRegistered = 1;
GLASS_LOG_FINE("This is the first time we have a touch even, register device now");
(*javaEnv)->CallStaticVoidMethod(javaEnv, jAndroidInputDeviceRegistryClass, monocle_registerDevice);
}
jcharArray jchars = (*javaEnv)->NewCharArray(javaEnv, count);
(*javaEnv)->SetCharArrayRegion(javaEnv, jchars, 0, count, chars);
(*javaEnv)->CallStaticVoidMethod(javaEnv, jAndroidInputDeviceRegistryClass, monocle_dispatchKeyEventFromNative,
action, keyCode, jchars, mods);
}

void androidJfx_requestGlassToRedraw() {
Expand Down

0 comments on commit 844460b

Please sign in to comment.