Replies: 5 comments 5 replies
-
Any update? |
Beta Was this translation helpful? Give feedback.
-
Just want to add that I'm in a very similar position to @dominiks' - I'd like to move a bunch of UI above the virtual keyboard when it's open. |
Beta Was this translation helpful? Give feedback.
-
Any update guys? |
Beta Was this translation helpful? Give feedback.
-
I don't think anyone has gotten around to implementing this |
Beta Was this translation helpful? Give feedback.
-
We have implemented this in a custom internal java android plugin. It's got some hacks in it that may not be needed anymore, also I copied and pasted this out of a larger plugin, so it may not be a complete example, but here is how we did it: public class MonitorKeyboardAndroid extends GodotPlugin {
private static final String TAG = "MonitorKeyboardAndroid ";
int mVirtualKeyboardHeight;
int mVirtualKeyboardHeightError;
boolean mKeyboardShownOnce = false;
@Nullable
public View onMainCreate(Activity activity) {
// listen for layout changes which generally indicates keyboard being shown/hidden and emit signals
getGodot().getRenderView().getView().getViewTreeObserver().addOnGlobalLayoutListener(() -> {
// Calculate keyboard height, this is copied from Godot.java::onVideoInit
// It however is wrong, see https://github.com/godotengine/godot/issues/41388
// Apparently it doesn't add the height of the android navigation bar
// on my Pixel 5a with Android 12 the nav bar is a black bar with a down arrow to hide keyboard
// When the keyboard is hidden keyboardHeight will be negative, it happens that this is the height
// of the nav bar, so adding it to keyboardHeight fixes it. Hopefully we can remove this when 41388 is fixed
Point fullSize = new Point();
getGodot().getActivity().getWindowManager().getDefaultDisplay().getSize(fullSize);
Rect gameSize = new Rect();
getGodot().getRenderView().getView().getWindowVisibleDisplayFrame(gameSize);
final int keyboardHeight = fullSize.y - gameSize.bottom;
if(keyboardHeight <= 0) {
mVirtualKeyboardHeightError = keyboardHeight;
mVirtualKeyboardHeight = 0;
}
if(android.os.Build.MANUFACTURER.equals("Amazon") && isTV() && keyboardHeight > fullSize.y * 0.75)
{
// Amazon Fire TV will trigger this callback when the keyboard is being hidden with mVirtualKeyboardHeight between 1027 and 1080
// It causes our boxes to resizes rreally small and then large again causing a flicker, so just ignore it
//Log.w(TAG, String.format("MonitorKeyboardAndroid::addOnGlobalLayoutListener ignoring large keyboard on Amazon Fire TV"));
}
else if(keyboardHeight > 0) {
mVirtualKeyboardHeight = keyboardHeight + Math.abs(mVirtualKeyboardHeightError);
mKeyboardShownOnce = true;
emitSignal("keyboard_shown");
}
else {
// only emit hidden signal if keyboard has been shown at least once. This hopefully fixes exception starting game where it
// immediately tried to emit signal before signal was registered
if(mKeyboardShownOnce)
emitSignal("keyboard_hidden");
}
});
}
public boolean isTV() {
PackageManager packageManager = getGodot().getActivity().getPackageManager();
return packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
}
@NonNull
@Override
public String getPluginName() {
return "MonitorKeyboardAndroid ";
}
@NonNull
@Override
public Set<SignalInfo> getPluginSignals() {
Set<SignalInfo> signals = new ArraySet<>();
signals.add(new SignalInfo("keyboard_shown"));
signals.add(new SignalInfo("keyboard_hidden"));
return signals;
}
} |
Beta Was this translation helpful? Give feedback.
-
Working on a mobile app I encountered the issue that the virtual keyboard that opens when editing a
LineEdit
blocks the user's view of the UI. It would be easy to fix this by adding a spacerControl
that takes the height ofDisplayServer.virtual_keyboard_get_height()
(/ get_window().content_scale_factor
actually) to move all content out of that zone but there is no way to be notified when the view opens. You can enable this spacer element when theLineEdit
receives focus and hide it when the focus is lost but the virtual keyboard can open and close without losing focus of the control.Therefore I think it would be good to have a signal or a notification whenever the virtual keyboard is opened or closed. Currently the
DisplayServer
handles everything regarding the virtual keyboard but servers don't send signals, I think. Alternatively the event could be emitted byLineEdit
andTextEdit
as they automatically open the keyboard.Beta Was this translation helpful? Give feedback.
All reactions