diff options
Diffstat (limited to 'src/newt')
4 files changed, 119 insertions, 9 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 3c5441bf7..136c19ff8 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -106,11 +106,11 @@ public interface Window extends NativeWindow, WindowClosingProtocol { void destroy(); /** - * <p> * <code>setVisible</code> makes the window and children visible if <code>visible</code> is true, - * otherwise the window and children becomes invisible.<br></p> + * otherwise the window and children becomes invisible. * <p> - * The <code>setVisible(true)</code> is responsible to actual create the native window.<br></p> + * The <code>setVisible(true)</code> is responsible to actual create the native window. + * </p> * <p> * Zero size semantics are respected, see {@link #setSize(int,int)}:<br> * <pre> @@ -125,10 +125,11 @@ public interface Window extends NativeWindow, WindowClosingProtocol { * } * </pre></p> * <p> - * In case this window is a child window and a parent {@link javax.media.nativewindow.NativeWindow} is being used,<br> - * the parent's {@link javax.media.nativewindow.NativeWindow} handle is retrieved via {@link javax.media.nativewindow.NativeWindow#getWindowHandle()}.<br> - * If this action fails, ie if the parent {@link javax.media.nativewindow.NativeWindow} is not valid yet,<br> - * no native window is created yet and <code>setVisible(true)</code> shall be repeated when it is.<br></p> + * In case this window is a child window and has a {@link javax.media.nativewindow.NativeWindow} parent,<br> + * <code>setVisible(true)</code> has no effect as long the parent's is not valid yet, + * i.e. {@link javax.media.nativewindow.NativeWindow#getWindowHandle()} returns <code>null</code>.<br> + * <code>setVisible(true)</code> shall be repeated when the parent becomes valid. + * </p> */ void setVisible(boolean visible); @@ -399,7 +400,27 @@ public interface Window extends NativeWindow, WindowClosingProtocol { // KeyListener // + /** + * In case the platform supports or even requires a virtual on-screen keyboard, + * this method shows or hide it depending on whether <code>visible</code> is <code>true</code> + * or <code>false</code>. + * <p> + * One known platform where NEWT supports this feature is <code>Android</code>. + * </p> + */ + void setKeyboardVisible(boolean visible); + /** + * Return <code>true</code> if the virtual on-screen keyboard is visible, otherwise <code>false</code>. + * <p> + * Currently on <code>Android</code>, the only supported platform right now, + * there is no way to reliably be notified of the current keyboard state.<br> + * It would be best, if your code does not rely on this information. + * </p> + * @see #setKeyboardVisible(boolean) + */ + boolean isKeyboardVisible(); + /** * * Appends the given {@link com.jogamp.newt.event.KeyListener} to the end of diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index f89193754..a3adf5090 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -790,6 +790,14 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSC window.addWindowListener(index, l); } + public final void setKeyboardVisible(boolean visible) { + window.setKeyboardVisible(visible); + } + + public final boolean isKeyboardVisible() { + return window.isKeyboardVisible(); + } + public final void addKeyListener(KeyListener l) { window.addKeyListener(l); } diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 074f635e4..68a2430f7 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -303,6 +303,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer setTitleImpl(title); setPointerVisibleImpl(pointerVisible); confinePointerImpl(pointerConfined); + setKeyboardVisible(keyboardVisible); if(waitForVisible(true, false)) { if(isFullscreen()) { synchronized(fullScreenAction) { @@ -2182,6 +2183,36 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer addKeyListener(-1, l); } + public final void setKeyboardVisible(boolean visible) { + if(isNativeValid()) { + // We don't skip the impl. if it seems that there is no state change, + // since we cannot assume the impl. reliably gives us it's current state. + final boolean n = setKeyboardVisibleImpl(visible); + if(DEBUG_IMPLEMENTATION || DEBUG_KEY_EVENT) { + System.err.println("setKeyboardVisible(native): visible "+keyboardVisible+" -> "+visible +" -> "+n); + } + keyboardVisible = n; + } else { + keyboardVisible = visible; // earmark for creation + } + } + public final boolean isKeyboardVisible() { + return keyboardVisible; + } + protected boolean setKeyboardVisibleImpl(boolean visible) { + return false; // nop + } + /** Triggered by implementation's WM events to update the virtual on-screen keyboard's visibility state. */ + protected void keyboardVisibilityChanged(boolean visible) { + if(keyboardVisible != visible) { + if(DEBUG_IMPLEMENTATION || DEBUG_KEY_EVENT) { + System.err.println("keyboardVisibilityChanged: "+keyboardVisible+" -> "+visible); + } + keyboardVisible = visible; + } + } + protected boolean keyboardVisible = false; + public void addKeyListener(int index, KeyListener l) { if(l == null) { return; @@ -2356,8 +2387,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer enqueueWindowEvent(false, evt); } } - } - + } + /** Triggered by implementation's WM events to update the visibility state. */ protected void visibleChanged(boolean defer, boolean visible) { if(this.visible != visible) { diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java index 63d5f7003..73192a07f 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java @@ -48,10 +48,14 @@ import jogamp.opengl.egl.EGLGraphicsConfigurationFactory; import android.content.Context; import android.graphics.PixelFormat; +import android.os.Bundle; +import android.os.IBinder; +import android.os.ResultReceiver; import android.util.Log; import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceHolder.Callback2; +import android.view.inputmethod.InputMethodManager; import android.view.SurfaceView; import android.view.View; @@ -317,6 +321,52 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { } //---------------------------------------------------------------------- + // Virtual On-Screen Keyboard / SoftInput + // + + private class KeyboardVisibleReceiver extends ResultReceiver { + public KeyboardVisibleReceiver() { + super(null); + } + + @Override + public void onReceiveResult(int r, Bundle data) { + boolean v = false; + + switch(r) { + case InputMethodManager.RESULT_UNCHANGED_SHOWN: + case InputMethodManager.RESULT_SHOWN: + v = true; + break; + case InputMethodManager.RESULT_HIDDEN: + case InputMethodManager.RESULT_UNCHANGED_HIDDEN: + v = false; + break; + } + Log.d(MD.TAG, "keyboardVisible: "+v); + keyboardVisibilityChanged(v); + } + } + private KeyboardVisibleReceiver keyboardVisibleReceiver = new KeyboardVisibleReceiver(); + + protected final boolean setKeyboardVisibleImpl(boolean visible) { + if(null != androidView) { + final InputMethodManager imm = (InputMethodManager) getAndroidView().getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + final IBinder winid = getAndroidView().getWindowToken(); + if(visible) { + // Show soft-keyboard: + imm.showSoftInput(androidView, 0, keyboardVisibleReceiver); + } else { + // hide keyboard : + imm.hideSoftInputFromWindow(winid, 0, keyboardVisibleReceiver); + } + return visible; + } else { + return false; // nop + } + } + + //---------------------------------------------------------------------- // Surface Callbacks // |