aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-06-21 19:43:59 +0200
committerSven Gothel <[email protected]>2012-06-21 19:43:59 +0200
commit533e072a592826df53b90491bcaa606dfddaf646 (patch)
treecab29af1a38b2c0f51e85063a111c41ed69ba933 /src/newt/classes/jogamp
parentf5c9f5b2fb6bccb923d053f558b924c2ed19b57a (diff)
NEWT: Add virtual on-screen keyboard visibility interface methods incl. Android implementation.
Note: Currently only w/ Android implementation. Note: On Android there is no way to reliably be notified of the current keyboard state. It would be best, if your code does not rely on this information Window adds: - setKeyboardVisible(boolean) - isKeyboardVisible() // unreliable on Android
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java35
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java50
2 files changed, 83 insertions, 2 deletions
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
//