Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8245053: Keyboard doesn't show when TextInputControl has focus #219

Closed
wants to merge 5 commits into from
@@ -26,27 +26,56 @@
package javafx.scene.control.skin;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.WeakChangeListener;
import javafx.event.EventHandler;
import javafx.scene.control.TextArea;
import javafx.scene.control.skin.TextAreaSkin;
import javafx.scene.input.MouseEvent;

public class TextAreaSkinAndroid extends TextAreaSkin {

/**************************************************************************
*
* Private fields
*
**************************************************************************/

private final EventHandler<MouseEvent> mouseEventListener = e -> {
if (getSkinnable().isEditable() && getSkinnable().isFocused()) {
showSoftwareKeyboard();
}
};

private final ChangeListener<Boolean> focusChangeListener = (observable, wasFocused, isFocused) -> {
if (wasFocused && !isFocused) {
hideSoftwareKeyboard();
}
};
private final WeakChangeListener<Boolean> weakFocusChangeListener = new WeakChangeListener<>(focusChangeListener);

/**************************************************************************
*
* Constructors
*
**************************************************************************/

public TextAreaSkinAndroid(final TextArea textArea) {
super(textArea);
textArea.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseEventListener);
textArea.focusedProperty().addListener(weakFocusChangeListener);
}

/***************************************************************************
* *
* Public API *
* *
**************************************************************************/

textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> observable,
Boolean wasFocused, Boolean isFocused) {
if (textArea.isEditable()) {
if (isFocused) {
showSoftwareKeyboard();
} else {
hideSoftwareKeyboard();
}
}
}
});
/** {@inheritDoc} */
@Override public void dispose() {
if (getSkinnable() == null) return;
getSkinnable().removeEventHandler(MouseEvent.MOUSE_CLICKED, mouseEventListener);
getSkinnable().focusedProperty().removeListener(weakFocusChangeListener);
super.dispose();
}

native void showSoftwareKeyboard();
@@ -26,29 +26,57 @@
package javafx.scene.control.skin;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.WeakChangeListener;
import javafx.event.EventHandler;
import javafx.scene.control.TextField;

import com.sun.javafx.scene.control.behavior.TextFieldBehavior;
import javafx.scene.control.skin.TextFieldSkin;
import javafx.scene.input.MouseEvent;

public class TextFieldSkinAndroid extends TextFieldSkin {

/**************************************************************************
*
* Private fields
*
**************************************************************************/

private final EventHandler<MouseEvent> mouseEventListener = e -> {
if (getSkinnable().isEditable() && getSkinnable().isFocused()) {
showSoftwareKeyboard();
}
};

private final ChangeListener<Boolean> focusChangeListener = (observable, wasFocused, isFocused) -> {
if (wasFocused && !isFocused) {
hideSoftwareKeyboard();
}
};
private final WeakChangeListener<Boolean> weakFocusChangeListener = new WeakChangeListener<>(focusChangeListener);

/**************************************************************************
*
* Constructors
*
**************************************************************************/

public TextFieldSkinAndroid(final TextField textField) {
super(textField);

textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> observable,
Boolean wasFocused, Boolean isFocused) {
if (textField.isEditable()) {
if (isFocused) {
showSoftwareKeyboard();
} else {
hideSoftwareKeyboard();
}
}
}
});
textField.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseEventListener);
textField.focusedProperty().addListener(weakFocusChangeListener);
}

/***************************************************************************
* *
* Public API *
* *
**************************************************************************/

/** {@inheritDoc} */
@Override public void dispose() {
if (getSkinnable() == null) return;
getSkinnable().removeEventHandler(MouseEvent.MOUSE_CLICKED, mouseEventListener);
getSkinnable().focusedProperty().removeListener(weakFocusChangeListener);
super.dispose();
}

native void showSoftwareKeyboard();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.