Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ subprojects {

javafx {
version = "20.0.2"
modules 'javafx.graphics'
modules 'javafx.graphics', 'javafx.controls'
}
}

Expand Down
4 changes: 3 additions & 1 deletion gradle/include/android/grandroid_ext.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Gluon
* Copyright (c) 2020, 2026, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -58,9 +58,11 @@ jobject substrateGetActivity();
#ifdef SUBSTRATE
void __attribute__((weak)) attach_setActivityResult(jint requestCode, jint resultCode, jobject intent) {}
void __attribute__((weak)) attach_setLifecycleEvent(const char *event) {}
void __attribute__((weak)) attach_setComposingText(const char *id, const char *text) {}
#else
void attach_setActivityResult(jint requestCode, jint resultCode, jobject intent);
void attach_setLifecycleEvent(const char *event);
void attach_setComposingText(const char *id, const char *text);
#endif

#define ATTACH_GRAAL() \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Gluon
* Copyright (c) 2020, 2026, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -29,6 +29,7 @@

import com.gluonhq.attach.util.Services;
import javafx.beans.property.ReadOnlyFloatProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.scene.Node;
import javafx.scene.Parent;

Expand Down Expand Up @@ -85,4 +86,32 @@ static Optional<KeyboardService> create() {
* @return A ReadOnlyFloatProperty with the height of the soft keyboard
*/
ReadOnlyFloatProperty visibleHeightProperty();

/**
* Assigns a keyboard type to a specific node (typically a {@link javafx.scene.control.TextInputControl}).
* When the node gains gets activated, the keyboard type is applied automatically.
* When the keyboard hides, the keyboard type reverts to {@link KeyboardType#ASCII}.
*
* <p>If nodes are registered, they default to {@link KeyboardType#ASCII}.</p>
*
Comment on lines +90 to +96
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc grammar: "When the node gains gets activated" is likely a typo and reads ambiguously. Consider rephrasing to something like "When the node becomes active" or "gains focus" to match the intended behavior.

Copilot uses AI. Check for mistakes.
* @param node the node (typically a text input control) to configure
* @param type the {@link KeyboardType} to use when this node is active
* @since 4.0.25
*/
void setKeyboardTypeForNode(Node node, KeyboardType type);

/**
* Returns a read-only property that reflects the current composing text for the given node
* (typically a {@link javafx.scene.control.TextInputControl}), as reported by the native IME.
*
* <p>Note that the JavaFX text input control default {@code textProperty()} will still
* catch all the internals of the text composition when predictive text is enabled (that could show
* partial text being removed and added back again while the user is typing)</p>
*
* @param node the node whose text to observe
* @return a ReadOnlyStringProperty with the composed text for the given node
* @since 4.0.25
*/
ReadOnlyStringProperty textPropertyForNode(Node node);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2026, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.gluonhq.attach.keyboard;

/**
* Defines the type of keyboard to display.
*
* <p>On iOS, these map directly to {@code UIKeyboardType} values.
* On Android, they map to the corresponding {@code InputType} flags.</p>
*
* @since 4.0.25
*/
public enum KeyboardType {

/**
* The default keyboard, supporting general text input.
*/
DEFAULT(0),

/**
* A keyboard that displays standard ASCII characters.
*/
ASCII(1),

/**
* A keyboard optimized for number and punctuation entry.
*/
NUMBERS_AND_PUNCTUATION(2),

/**
* A keyboard optimized for URL entry (with {@code .}, {@code /},
* and {@code .com} keys).
*/
URL(3),

/**
* A numeric keypad designed for PIN entry (locale digits 0-9).
*/
NUMBER_PAD(4),

/**
* A keypad designed for entering telephone numbers
* (digits, {@code *}, and {@code #}).
*/
PHONE_PAD(5),

/**
* A keyboard optimized for entering a person's name or phone number.
*/
NAME_PHONE_PAD(6),

/**
* A keyboard optimized for entering email addresses (with {@code @}
* and {@code .} keys).
*/
EMAIL(7),

/**
* A numeric keypad with a decimal point.
*/
DECIMAL_PAD(8),

/**
* A keyboard optimized for Twitter text entry
* (with {@code @} and {@code #} keys).
*/
TWITTER(9),

/**
* A keyboard optimized for web search terms and URL entry.
*/
WEB_SEARCH(10),

/**
* A numeric keypad that outputs only ASCII digits
*/
ASCII_NUMBER_PAD(11);

private final int value;

KeyboardType(int value) {
this.value = value;
}

/**
* Returns the native integer value corresponding to this keyboard type.
*
* @return the native keyboard type value
*/
public int getValue() {
return value;
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022, Gluon
* Copyright (c) 2020, 2026, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -27,25 +27,12 @@
*/
package com.gluonhq.attach.keyboard.impl;

import com.gluonhq.attach.keyboard.KeyboardService;
import com.gluonhq.attach.util.Util;
import javafx.animation.Interpolator;
import javafx.animation.TranslateTransition;
import javafx.application.Platform;
import javafx.beans.property.ReadOnlyFloatProperty;
import javafx.beans.property.ReadOnlyFloatWrapper;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.util.Duration;

import java.util.logging.Level;
import java.util.logging.Logger;

public class AndroidKeyboardService implements KeyboardService {

private static final Logger LOG = Logger.getLogger(AndroidKeyboardService.class.getName());
private static final ReadOnlyFloatWrapper VISIBLE_HEIGHT = new ReadOnlyFloatWrapper();
private static final boolean debug = Util.DEBUG;
public class AndroidKeyboardService extends BaseKeyboardService {

static {
System.loadLibrary("keyboard");
Expand All @@ -69,36 +56,33 @@ public ReadOnlyFloatProperty visibleHeightProperty() {
return VISIBLE_HEIGHT.getReadOnlyProperty();
}

private static void adjustPosition(Node node, Parent parent, double kh) {
if (node == null || node.getScene() == null || node.getScene().getWindow() == null) {
return;
}
double tTot = node.getScene().getHeight();
double ty = node.getLocalToSceneTransform().getTy() + node.getBoundsInParent().getHeight() + 2;
double y = 1;
Parent root = parent == null ? node.getScene().getRoot() : parent;
if (ty > tTot - kh) {
y = tTot - ty - kh;
} else if (kh == 0 && root.getTranslateY() != 0) {
y = 0;
}
if (y <= 0) {
if (debug) {
LOG.log(Level.INFO, String.format("Moving %s %.2f pixels", root, y));
}
final TranslateTransition transition = new TranslateTransition(Duration.millis(50), root);
transition.setFromY(root.getTranslateY());
transition.setToY(y);
transition.setInterpolator(Interpolator.EASE_OUT);
transition.playFromStart();
}
@Override
protected void applyKeyboardType(int nativeValue) {
nativeSetKeyboardType(nativeValue);
}

// callback
@Override
protected void applyActiveNodeId(String id) {
nativeSetActiveNodeId(id);
}

// native
private static native void nativeSetKeyboardType(int keyboardTypeValue);
private static native void nativeSetActiveNodeId(String id);

// callbacks
private static void notifyVisibleHeight(float height) {
if (VISIBLE_HEIGHT.get() != height) {
Platform.runLater(() -> VISIBLE_HEIGHT.set(height));
}
}

/**
* Called from keyboard.c when the native layer receives composing text
* tagged with a node id.
*/
private static void notifyComposingText(String id, String text) {
updateTextForId(id, text);
}

}
Loading
Loading