summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/WindowDriver.java39
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java88
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java2
3 files changed, 94 insertions, 35 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java
index a85febca0..c5371ae9c 100644
--- a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java
@@ -30,6 +30,7 @@ package jogamp.newt.driver.android;
import jogamp.common.os.android.StaticContext;
import jogamp.newt.WindowImpl;
+import jogamp.newt.driver.android.event.AndroidNewtEventFactory;
import jogamp.newt.driver.android.event.AndroidNewtEventTranslator;
import javax.media.nativewindow.Capabilities;
@@ -65,6 +66,8 @@ import android.view.SurfaceHolder.Callback2;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.view.SurfaceView;
+import android.view.KeyEvent;
+
public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 {
static {
@@ -573,10 +576,8 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 {
@Override
public final void surfaceDestroyed(SurfaceHolder holder) {
Log.d(MD.TAG, "surfaceDestroyed - on thread "+Thread.currentThread().getName());
- if(WindowImpl.DEBUG_IMPLEMENTATION) {
- Thread.dumpStack();
- }
windowDestroyNotify(true); // actually too late .. however ..
+ Thread.dumpStack();
}
@Override
@@ -585,6 +586,27 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 {
windowRepaint(0, 0, getWidth(), getHeight());
}
+ protected boolean handleKeyCodeBack(KeyEvent.DispatcherState state, android.view.KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
+ state.startTracking(event, this);
+ } else if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled() && state.isTracking(event)) {
+ if( isKeyboardVisible() ) {
+ keyboardVisibilityChanged(false);
+ enqueueAKey2NKeyUpDown(event);
+ } else {
+ Log.d(MD.TAG, "handleKeyCodeBack : "+event);
+ windowDestroyNotify(true);
+ }
+ }
+ return false; // cont. processing
+ }
+ private void enqueueAKey2NKeyUpDown(android.view.KeyEvent aEvent) {
+ final com.jogamp.newt.event.KeyEvent eDown = AndroidNewtEventFactory.createKeyEvent(aEvent, com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED, this, true);
+ final com.jogamp.newt.event.KeyEvent eUp = AndroidNewtEventFactory.createKeyEvent(aEvent, com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED, this, true);
+ enqueueEvent(false, eDown);
+ enqueueEvent(false, eUp);
+ }
+
private boolean added2StaticViewGroup;
private MSurfaceView androidView;
private int nativeFormat; // chosen current native PixelFormat (suitable for EGL)
@@ -600,6 +622,17 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 {
setBackgroundDrawable(null);
// setBackgroundColor(Color.TRANSPARENT);
}
+
+ @Override
+ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
+ if ( event.getKeyCode() == KeyEvent.KEYCODE_BACK ) {
+ final KeyEvent.DispatcherState state = getKeyDispatcherState();
+ if (state != null) {
+ return handleKeyCodeBack(state, event);
+ }
+ }
+ return false; // cont. processing
+ }
}
//----------------------------------------------------------------------
// Internals only
diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
index 4f19e9c4d..a9c642d8c 100644
--- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
@@ -31,6 +31,7 @@ package jogamp.newt.driver.android.event;
import com.jogamp.common.os.AndroidVersion;
import com.jogamp.newt.Window;
import com.jogamp.newt.event.InputEvent;
+import com.jogamp.newt.event.NEWTEvent;
public class AndroidNewtEventFactory {
@@ -86,7 +87,7 @@ public class AndroidNewtEventFactory {
return (short)0;
}
- private static final short aKeyCode2NewtKeyCode(int androidKeyCode) {
+ private static final short aKeyCode2NewtKeyCode(int androidKeyCode, boolean inclSysKeys) {
if(android.view.KeyEvent.KEYCODE_0 <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_9) {
return (short) ( com.jogamp.newt.event.KeyEvent.VK_0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_0 ) );
}
@@ -122,11 +123,19 @@ public class AndroidNewtEventFactory {
// case android.view.KeyEvent.KEYCODE_MUTE: ??
case android.view.KeyEvent.KEYCODE_PAGE_UP: return com.jogamp.newt.event.KeyEvent.VK_PAGE_UP;
case android.view.KeyEvent.KEYCODE_PAGE_DOWN: return com.jogamp.newt.event.KeyEvent.VK_PAGE_DOWN;
- // case android.view.KeyEvent.KEYCODE_HOME: return com.jogamp.newt.event.KeyEvent.VK_HOME;
- // case android.view.KeyEvent.KEYCODE_BACK: return com.jogamp.newt.event.KeyEvent.VK_BACK_SPACE;
case android.view.KeyEvent.KEYCODE_ESCAPE: return com.jogamp.newt.event.KeyEvent.VK_ESCAPE;
case android.view.KeyEvent.KEYCODE_CTRL_LEFT: return com.jogamp.newt.event.KeyEvent.VK_CONTROL;
case android.view.KeyEvent.KEYCODE_CTRL_RIGHT: return com.jogamp.newt.event.KeyEvent.VK_CONTROL; // ??
+ case android.view.KeyEvent.KEYCODE_BACK:
+ if( inclSysKeys ) {
+ return com.jogamp.newt.event.KeyEvent.VK_KEYBOARD_INVISIBLE;
+ }
+ break;
+ case android.view.KeyEvent.KEYCODE_HOME:
+ if( inclSysKeys ) {
+ return com.jogamp.newt.event.KeyEvent.VK_HOME;
+ }
+ break;
}
return (short)0;
}
@@ -140,19 +149,7 @@ public class AndroidNewtEventFactory {
return newtMods;
}
- private final NewtGestureListener gestureListener;
- private final android.view.GestureDetector gestureDetector;
- private final float touchSlop;
-
- public AndroidNewtEventFactory(android.content.Context context, android.os.Handler handler) {
- gestureListener = new NewtGestureListener();
- gestureDetector = new android.view.GestureDetector(context, gestureListener, handler, false /* ignoreMultitouch */);
- gestureDetector.setIsLongpressEnabled(false); // favor scroll event!
- final android.view.ViewConfiguration configuration = android.view.ViewConfiguration.get(context);
- touchSlop = configuration.getScaledTouchSlop();
- }
-
- public com.jogamp.newt.event.WindowEvent createWindowEvent(android.view.accessibility.AccessibilityEvent event, com.jogamp.newt.Window newtSource) {
+ public static com.jogamp.newt.event.WindowEvent createWindowEvent(android.view.accessibility.AccessibilityEvent event, com.jogamp.newt.Window newtSource) {
final int aType = event.getEventType();
final short nType = aAccessibilityEventType2Newt(aType);
@@ -163,25 +160,54 @@ public class AndroidNewtEventFactory {
}
- public com.jogamp.newt.event.KeyEvent createKeyEvent(int keyCode, android.view.KeyEvent event, com.jogamp.newt.Window newtSource) {
- final short type = aKeyEventType2NewtEventType(event.getAction());
- if(Window.DEBUG_MOUSE_EVENT) {
- System.err.println("createKeyEvent: type 0x"+Integer.toHexString(type)+", keyCode 0x"+Integer.toHexString(keyCode)+", "+event);
+ public static com.jogamp.newt.event.KeyEvent createKeyEvent(android.view.KeyEvent aEvent, com.jogamp.newt.Window newtSource, boolean inclSysKeys) {
+ final com.jogamp.newt.event.KeyEvent res;
+ final short newtType = aKeyEventType2NewtEventType(aEvent.getAction());
+ if( (short)0 != newtType) {
+ final short newtKeyCode = aKeyCode2NewtKeyCode(aEvent.getKeyCode(), inclSysKeys);
+ res = createKeyEventImpl(aEvent, newtType, newtKeyCode, newtSource);
+ } else {
+ res = null;
}
- if( (short)0 != type) {
- final short newtKeyCode = aKeyCode2NewtKeyCode(keyCode);
- if( (short)0 != newtKeyCode ) {
- final Object src = (null==newtSource)?null:(Object)newtSource;
- final long unixTime = System.currentTimeMillis() + ( event.getEventTime() - android.os.SystemClock.uptimeMillis() );
- final int newtMods = aKeyModifiers2Newt(event.getMetaState());
-
- return new com.jogamp.newt.event.KeyEvent(
- type, src, unixTime, newtMods, newtKeyCode, newtKeyCode, (char) event.getUnicodeChar());
- }
+ if(Window.DEBUG_KEY_EVENT) {
+ System.err.println("createKeyEvent0: "+aEvent+" -> "+res);
}
- return null;
+ return res;
}
+ public static com.jogamp.newt.event.KeyEvent createKeyEvent(android.view.KeyEvent aEvent, short newtType, com.jogamp.newt.Window newtSource, boolean inclSysKeys) {
+ final short newtKeyCode = aKeyCode2NewtKeyCode(aEvent.getKeyCode(), inclSysKeys);
+ final com.jogamp.newt.event.KeyEvent res = createKeyEventImpl(aEvent, newtType, newtKeyCode, newtSource);
+ if(Window.DEBUG_KEY_EVENT) {
+ System.err.println("createKeyEvent1: newtType "+NEWTEvent.toHexString(newtType)+", "+aEvent+" -> "+res);
+ }
+ return res;
+ }
+
+ private static com.jogamp.newt.event.KeyEvent createKeyEventImpl(android.view.KeyEvent aEvent, short newtType, short newtKeyCode, com.jogamp.newt.Window newtSource) {
+ if( (short)0 != newtType && (short)0 != newtKeyCode ) {
+ final Object src = null==newtSource ? null : newtSource;
+ final long unixTime = System.currentTimeMillis() + ( aEvent.getEventTime() - android.os.SystemClock.uptimeMillis() );
+ final int newtMods = aKeyModifiers2Newt(aEvent.getMetaState());
+
+ return new com.jogamp.newt.event.KeyEvent(
+ newtType, src, unixTime, newtMods, newtKeyCode, newtKeyCode, (char) aEvent.getUnicodeChar());
+ }
+ return null;
+ }
+
+ private final NewtGestureListener gestureListener;
+ private final android.view.GestureDetector gestureDetector;
+ private final float touchSlop;
+
+ public AndroidNewtEventFactory(android.content.Context context, android.os.Handler handler) {
+ gestureListener = new NewtGestureListener();
+ gestureDetector = new android.view.GestureDetector(context, gestureListener, handler, false /* ignoreMultitouch */);
+ gestureDetector.setIsLongpressEnabled(false); // favor scroll event!
+ final android.view.ViewConfiguration configuration = android.view.ViewConfiguration.get(context);
+ touchSlop = configuration.getScaledTouchSlop();
+ }
+
private int gestureScrollPointerDown = 0;
public com.jogamp.newt.event.MouseEvent[] createMouseEvents(boolean isOnTouchEvent,
diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java
index 2d972f752..93735863e 100644
--- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java
+++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java
@@ -38,7 +38,7 @@ public class AndroidNewtEventTranslator implements View.OnKeyListener, View.OnTo
@Override
public boolean onKey(View v, int keyCode, android.view.KeyEvent event) {
- final com.jogamp.newt.event.KeyEvent newtEvent = factory.createKeyEvent(keyCode, event, newtWindow);
+ final com.jogamp.newt.event.KeyEvent newtEvent = AndroidNewtEventFactory.createKeyEvent(event, newtWindow, false /* no system keys */);
if(null != newtEvent) {
newtWindow.enqueueEvent(false, newtEvent);
return true;