remove showVirtualKeyboard from TouchInput

experimental
iwgeric 10 years ago
parent 7040e32cc4
commit 249f62fe95
  1. 6
      jme3-android/src/main/java/com/jme3/input/android/AndroidInput.java
  2. 59
      jme3-android/src/main/java/com/jme3/input/android/AndroidInputHandler.java
  3. 52
      jme3-android/src/main/java/com/jme3/input/android/AndroidKeyHandler.java
  4. 24
      jme3-core/src/main/java/com/jme3/input/TouchInput.java
  5. 31
      jme3-ios/src/main/java/com/jme3/input/ios/IosInputHandler.java

@ -400,7 +400,7 @@ public class AndroidInput implements
if(eventQueue.size()< MAX_EVENTS){ if(eventQueue.size()< MAX_EVENTS){
eventQueue.push(event); eventQueue.push(event);
} }
} }
} }
@ -679,8 +679,4 @@ public class AndroidInput implements
return mouseEventsEnabled; return mouseEventsEnabled;
} }
public void showVirtualKeyboard(boolean visible) {
throw new UnsupportedOperationException("Not supported yet.");
}
} }

@ -56,7 +56,7 @@ import java.util.logging.Logger;
*/ */
public class AndroidInputHandler implements TouchInput { public class AndroidInputHandler implements TouchInput {
private static final Logger logger = Logger.getLogger(AndroidInputHandler.class.getName()); private static final Logger logger = Logger.getLogger(AndroidInputHandler.class.getName());
// Custom settings // Custom settings
private boolean mouseEventsEnabled = true; private boolean mouseEventsEnabled = true;
private boolean mouseEventsInvertX = false; private boolean mouseEventsInvertX = false;
@ -64,8 +64,8 @@ public class AndroidInputHandler implements TouchInput {
private boolean keyboardEventsEnabled = false; private boolean keyboardEventsEnabled = false;
private boolean joystickEventsEnabled = false; private boolean joystickEventsEnabled = false;
private boolean dontSendHistory = false; private boolean dontSendHistory = false;
// Internal // Internal
private GLSurfaceView view; private GLSurfaceView view;
private AndroidTouchHandler touchHandler; private AndroidTouchHandler touchHandler;
@ -78,8 +78,8 @@ public class AndroidInputHandler implements TouchInput {
private final TouchEventPool touchEventPool = new TouchEventPool(MAX_TOUCH_EVENTS); private final TouchEventPool touchEventPool = new TouchEventPool(MAX_TOUCH_EVENTS);
private float scaleX = 1f; private float scaleX = 1f;
private float scaleY = 1f; private float scaleY = 1f;
public AndroidInputHandler() { public AndroidInputHandler() {
int buildVersion = Build.VERSION.SDK_INT; int buildVersion = Build.VERSION.SDK_INT;
logger.log(Level.INFO, "Android Build Version: {0}", buildVersion); logger.log(Level.INFO, "Android Build Version: {0}", buildVersion);
@ -94,14 +94,14 @@ public class AndroidInputHandler implements TouchInput {
keyHandler = new AndroidKeyHandler(this); keyHandler = new AndroidKeyHandler(this);
} }
} }
public AndroidInputHandler(AndroidTouchHandler touchInput, public AndroidInputHandler(AndroidTouchHandler touchInput,
AndroidKeyHandler keyInput, AndroidGestureHandler gestureHandler) { AndroidKeyHandler keyInput, AndroidGestureHandler gestureHandler) {
this.touchHandler = touchInput; this.touchHandler = touchInput;
this.keyHandler = keyInput; this.keyHandler = keyInput;
this.gestureHandler = gestureHandler; this.gestureHandler = gestureHandler;
} }
public void setView(View view) { public void setView(View view) {
if (touchHandler != null) { if (touchHandler != null) {
touchHandler.setView(view); touchHandler.setView(view);
@ -114,27 +114,27 @@ public class AndroidInputHandler implements TouchInput {
} }
this.view = (GLSurfaceView)view; this.view = (GLSurfaceView)view;
} }
public View getView() { public View getView() {
return view; return view;
} }
public float invertX(float origX) { public float invertX(float origX) {
return getJmeX(view.getWidth()) - origX; return getJmeX(view.getWidth()) - origX;
} }
public float invertY(float origY) { public float invertY(float origY) {
return getJmeY(view.getHeight()) - origY; return getJmeY(view.getHeight()) - origY;
} }
public float getJmeX(float origX) { public float getJmeX(float origX) {
return origX * scaleX; return origX * scaleX;
} }
public float getJmeY(float origY) { public float getJmeY(float origY) {
return origY * scaleY; return origY * scaleY;
} }
public void loadSettings(AppSettings settings) { public void loadSettings(AppSettings settings) {
// TODO: add simulate keyboard to settings // TODO: add simulate keyboard to settings
// keyboardEventsEnabled = true; // keyboardEventsEnabled = true;
@ -142,15 +142,15 @@ public class AndroidInputHandler implements TouchInput {
mouseEventsInvertX = settings.isEmulateMouseFlipX(); mouseEventsInvertX = settings.isEmulateMouseFlipX();
mouseEventsInvertY = settings.isEmulateMouseFlipY(); mouseEventsInvertY = settings.isEmulateMouseFlipY();
joystickEventsEnabled = settings.useJoysticks(); joystickEventsEnabled = settings.useJoysticks();
// view width and height are 0 until the view is displayed on the screen // view width and height are 0 until the view is displayed on the screen
if (view.getWidth() != 0 && view.getHeight() != 0) { if (view.getWidth() != 0 && view.getHeight() != 0) {
scaleX = (float)settings.getWidth() / (float)view.getWidth(); scaleX = (float)settings.getWidth() / (float)view.getWidth();
scaleY = (float)settings.getHeight() / (float)view.getHeight(); scaleY = (float)settings.getHeight() / (float)view.getHeight();
} }
logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}", logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}",
new Object[]{scaleX, scaleY}); new Object[]{scaleX, scaleY});
} }
// ----------------------------------------- // -----------------------------------------
@ -167,14 +167,14 @@ public class AndroidInputHandler implements TouchInput {
if (gestureHandler != null) { if (gestureHandler != null) {
gestureHandler.initialize(); gestureHandler.initialize();
} }
initialized = true; initialized = true;
} }
@Override @Override
public void destroy() { public void destroy() {
initialized = false; initialized = false;
touchEventPool.destroy(); touchEventPool.destroy();
if (touchHandler != null) { if (touchHandler != null) {
touchHandler.destroy(); touchHandler.destroy();
@ -185,7 +185,7 @@ public class AndroidInputHandler implements TouchInput {
if (gestureHandler != null) { if (gestureHandler != null) {
gestureHandler.destroy(); gestureHandler.destroy();
} }
setView(null); setView(null);
} }
@ -203,11 +203,11 @@ public class AndroidInputHandler implements TouchInput {
public long getInputTimeNanos() { public long getInputTimeNanos() {
return System.nanoTime(); return System.nanoTime();
} }
public void update() { public void update() {
if (listener != null) { if (listener != null) {
InputEvent inputEvent; InputEvent inputEvent;
while ((inputEvent = inputEventQueue.poll()) != null) { while ((inputEvent = inputEventQueue.poll()) != null) {
if (inputEvent instanceof TouchEvent) { if (inputEvent instanceof TouchEvent) {
listener.onTouchEvent((TouchEvent)inputEvent); listener.onTouchEvent((TouchEvent)inputEvent);
@ -223,11 +223,11 @@ public class AndroidInputHandler implements TouchInput {
} }
// ----------------------------------------- // -----------------------------------------
public TouchEvent getFreeTouchEvent() { public TouchEvent getFreeTouchEvent() {
return touchEventPool.getNextFreeEvent(); return touchEventPool.getNextFreeEvent();
} }
public void addEvent(InputEvent event) { public void addEvent(InputEvent event) {
inputEventQueue.add(event); inputEventQueue.add(event);
if (event instanceof TouchEvent) { if (event instanceof TouchEvent) {
@ -246,7 +246,7 @@ public class AndroidInputHandler implements TouchInput {
public boolean getSimulateMouse() { public boolean getSimulateMouse() {
return mouseEventsEnabled; return mouseEventsEnabled;
} }
public boolean isMouseEventsInvertX() { public boolean isMouseEventsInvertX() {
return mouseEventsInvertX; return mouseEventsInvertX;
} }
@ -254,7 +254,7 @@ public class AndroidInputHandler implements TouchInput {
public boolean isMouseEventsInvertY() { public boolean isMouseEventsInvertY() {
return mouseEventsInvertY; return mouseEventsInvertY;
} }
public void setSimulateKeyboard(boolean simulate) { public void setSimulateKeyboard(boolean simulate) {
this.keyboardEventsEnabled = simulate; this.keyboardEventsEnabled = simulate;
} }
@ -263,11 +263,4 @@ public class AndroidInputHandler implements TouchInput {
this.dontSendHistory = dontSendHistory; this.dontSendHistory = dontSendHistory;
} }
public void showVirtualKeyboard(boolean visible) {
if (keyHandler != null) {
keyHandler.showVirtualKeyboard(visible);
}
}
} }

@ -45,29 +45,29 @@ import java.util.logging.Logger;
* the jME KeyEvents. onKey is used by Android to receive keys from the keyboard * the jME KeyEvents. onKey is used by Android to receive keys from the keyboard
* or device buttons. All key events are consumed by jME except for the Volume * or device buttons. All key events are consumed by jME except for the Volume
* buttons and menu button. * buttons and menu button.
* *
* This class also provides the functionality to display or hide the soft keyboard * This class also provides the functionality to display or hide the soft keyboard
* for inputing single key events. Use OGLESContext to display an dialog to type * for inputing single key events. Use OGLESContext to display an dialog to type
* in complete strings. * in complete strings.
* *
* @author iwgeric * @author iwgeric
*/ */
public class AndroidKeyHandler implements View.OnKeyListener { public class AndroidKeyHandler implements View.OnKeyListener {
private static final Logger logger = Logger.getLogger(AndroidKeyHandler.class.getName()); private static final Logger logger = Logger.getLogger(AndroidKeyHandler.class.getName());
private AndroidInputHandler androidInput; private AndroidInputHandler androidInput;
private boolean sendKeyEvents = true; private boolean sendKeyEvents = true;
public AndroidKeyHandler(AndroidInputHandler androidInput) { public AndroidKeyHandler(AndroidInputHandler androidInput) {
this.androidInput = androidInput; this.androidInput = androidInput;
} }
public void initialize() { public void initialize() {
} }
public void destroy() { public void destroy() {
} }
public void setView(View view) { public void setView(View view) {
if (view != null) { if (view != null) {
view.setOnKeyListener(this); view.setOnKeyListener(this);
@ -75,7 +75,7 @@ public class AndroidKeyHandler implements View.OnKeyListener {
androidInput.getView().setOnKeyListener(null); androidInput.getView().setOnKeyListener(null);
} }
} }
/** /**
* onKey gets called from android thread on key events * onKey gets called from android thread on key events
*/ */
@ -83,7 +83,7 @@ public class AndroidKeyHandler implements View.OnKeyListener {
if (androidInput.isInitialized() && view != androidInput.getView()) { if (androidInput.isInitialized() && view != androidInput.getView()) {
return false; return false;
} }
TouchEvent evt; TouchEvent evt;
// TODO: get touch event from pool // TODO: get touch event from pool
if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
@ -107,50 +107,32 @@ public class AndroidKeyHandler implements View.OnKeyListener {
androidInput.addEvent(evt); androidInput.addEvent(evt);
} }
KeyInputEvent kie; KeyInputEvent kie;
char unicodeChar = (char)event.getUnicodeChar(); char unicodeChar = (char)event.getUnicodeChar();
int jmeKeyCode = AndroidKeyMapping.getJmeKey(keyCode); int jmeKeyCode = AndroidKeyMapping.getJmeKey(keyCode);
boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN; boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
boolean repeating = pressed && event.getRepeatCount() > 0; boolean repeating = pressed && event.getRepeatCount() > 0;
kie = new KeyInputEvent(jmeKeyCode, unicodeChar, pressed, repeating); kie = new KeyInputEvent(jmeKeyCode, unicodeChar, pressed, repeating);
kie.setTime(event.getEventTime()); kie.setTime(event.getEventTime());
androidInput.addEvent(kie); androidInput.addEvent(kie);
// logger.log(Level.FINE, "onKey keyCode: {0}, jmeKeyCode: {1}, pressed: {2}, repeating: {3}", // logger.log(Level.FINE, "onKey keyCode: {0}, jmeKeyCode: {1}, pressed: {2}, repeating: {3}",
// new Object[]{keyCode, jmeKeyCode, pressed, repeating}); // new Object[]{keyCode, jmeKeyCode, pressed, repeating});
// logger.log(Level.FINE, "creating KeyInputEvent: {0}", kie); // logger.log(Level.FINE, "creating KeyInputEvent: {0}", kie);
// consume all keys ourself except Volume Up/Down and Menu // consume all keys ourself except Volume Up/Down and Menu
// Don't do Menu so that typical Android Menus can be created and used // Don't do Menu so that typical Android Menus can be created and used
// by the user in MainActivity // by the user in MainActivity
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) ||
(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ||
(keyCode == KeyEvent.KEYCODE_MENU)) { (keyCode == KeyEvent.KEYCODE_MENU)) {
return false; return false;
} else { } else {
return true; return true;
} }
} }
public void showVirtualKeyboard (final boolean visible) {
androidInput.getView().getHandler().post(new Runnable() {
public void run() {
InputMethodManager manager =
(InputMethodManager)androidInput.getView().getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (visible) {
manager.showSoftInput(androidInput.getView(), 0);
sendKeyEvents = true;
} else {
manager.hideSoftInputFromWindow(androidInput.getView().getWindowToken(), 0);
sendKeyEvents = false;
}
}
});
}
} }

@ -59,27 +59,27 @@ public interface TouchInput extends Input {
/** /**
* Volume up key. * Volume up key.
*/ */
public static final int KEYCODE_VOLUME_UP = 0x18; public static final int KEYCODE_VOLUME_UP = 0x18;
/** /**
* Volume down key. * Volume down key.
*/ */
public static final int KEYCODE_VOLUME_DOWN = 0x19; public static final int KEYCODE_VOLUME_DOWN = 0x19;
/** /**
* Set if mouse events should be generated * Set if mouse events should be generated
* *
* @param simulate if mouse events should be generated * @param simulate if mouse events should be generated
*/ */
public void setSimulateMouse(boolean simulate); public void setSimulateMouse(boolean simulate);
/** /**
* Get if mouse events are generated * Get if mouse events are generated
* @deprecated Use {@link #isSimulateMouse() }. * @deprecated Use {@link #isSimulateMouse() }.
*/ */
@Deprecated @Deprecated
public boolean getSimulateMouse(); public boolean getSimulateMouse();
/** /**
* @return true if mouse event simulation is enabled, false otherwise. * @return true if mouse event simulation is enabled, false otherwise.
*/ */
@ -87,11 +87,11 @@ public interface TouchInput extends Input {
/** /**
* Set if keyboard events should be generated * Set if keyboard events should be generated
* *
* @param simulate if keyboard events should be generated * @param simulate if keyboard events should be generated
*/ */
public void setSimulateKeyboard(boolean simulate); public void setSimulateKeyboard(boolean simulate);
/** /**
* Set if historic android events should be transmitted, can be used to get better performance and less mem * Set if historic android events should be transmitted, can be used to get better performance and less mem
* @see <a href="http://developer.android.com/reference/android/view/MotionEvent.html#getHistoricalX%28int,%20int%29"> * @see <a href="http://developer.android.com/reference/android/view/MotionEvent.html#getHistoricalX%28int,%20int%29">
@ -99,11 +99,5 @@ public interface TouchInput extends Input {
* @param dontSendHistory turn of historic events if true, false else and default * @param dontSendHistory turn of historic events if true, false else and default
*/ */
public void setOmitHistoricEvents(boolean dontSendHistory); public void setOmitHistoricEvents(boolean dontSendHistory);
/**
* Displays or hides the onscreen soft keyboard
* @param visible
*/
public void showVirtualKeyboard (final boolean visible);
} }

@ -49,11 +49,11 @@ public class IosInputHandler implements TouchInput {
@Override @Override
public void update() { public void update() {
logger.log(Level.FINE, "InputEvent update : {0}", logger.log(Level.FINE, "InputEvent update : {0}",
new Object[]{listener}); new Object[]{listener});
if (listener != null) { if (listener != null) {
InputEvent inputEvent; InputEvent inputEvent;
while ((inputEvent = inputEventQueue.poll()) != null) { while ((inputEvent = inputEventQueue.poll()) != null) {
if (inputEvent instanceof TouchEvent) { if (inputEvent instanceof TouchEvent) {
listener.onTouchEvent((TouchEvent)inputEvent); listener.onTouchEvent((TouchEvent)inputEvent);
@ -117,20 +117,15 @@ public class IosInputHandler implements TouchInput {
this.dontSendHistory = dontSendHistory; this.dontSendHistory = dontSendHistory;
} }
@Override
public void showVirtualKeyboard(boolean visible) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
// ---------------- // ----------------
public void loadSettings(AppSettings settings) { public void loadSettings(AppSettings settings) {
// TODO: add simulate keyboard to settings // TODO: add simulate keyboard to settings
// keyboardEventsEnabled = true; // keyboardEventsEnabled = true;
mouseEventsEnabled = true;//settings.isEmulateMouse(); mouseEventsEnabled = true;//settings.isEmulateMouse();
mouseEventsInvertX = settings.isEmulateMouseFlipX(); mouseEventsInvertX = settings.isEmulateMouseFlipX();
mouseEventsInvertY = settings.isEmulateMouseFlipY(); mouseEventsInvertY = settings.isEmulateMouseFlipY();
// view width and height are 0 until the view is displayed on the screen // view width and height are 0 until the view is displayed on the screen
//if (view.getWidth() != 0 && view.getHeight() != 0) { //if (view.getWidth() != 0 && view.getHeight() != 0) {
// scaleX = (float)settings.getWidth() / (float)view.getWidth(); // scaleX = (float)settings.getWidth() / (float)view.getWidth();
@ -140,10 +135,10 @@ public class IosInputHandler implements TouchInput {
scaleY = 1.0f; scaleY = 1.0f;
width = settings.getWidth(); width = settings.getWidth();
height = settings.getHeight(); height = settings.getHeight();
logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}, width: {2}, height: {3}", logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}, width: {2}, height: {3}",
new Object[]{scaleX, scaleY, width, height}); new Object[]{scaleX, scaleY, width, height});
} }
public boolean isMouseEventsInvertX() { public boolean isMouseEventsInvertX() {
return mouseEventsInvertX; return mouseEventsInvertX;
} }
@ -151,19 +146,19 @@ public class IosInputHandler implements TouchInput {
public boolean isMouseEventsInvertY() { public boolean isMouseEventsInvertY() {
return mouseEventsInvertY; return mouseEventsInvertY;
} }
public float invertX(float origX) { public float invertX(float origX) {
return getJmeX(width) - origX; return getJmeX(width) - origX;
} }
public float invertY(float origY) { public float invertY(float origY) {
return getJmeY(height) - origY; return getJmeY(height) - origY;
} }
public float getJmeX(float origX) { public float getJmeX(float origX) {
return origX * scaleX; return origX * scaleX;
} }
public float getJmeY(float origY) { public float getJmeY(float origY) {
return origY * scaleY; return origY * scaleY;
} }
@ -171,7 +166,7 @@ public class IosInputHandler implements TouchInput {
public TouchEvent getFreeTouchEvent() { public TouchEvent getFreeTouchEvent() {
return touchEventPool.getNextFreeEvent(); return touchEventPool.getNextFreeEvent();
} }
public void addEvent(InputEvent event) { public void addEvent(InputEvent event) {
inputEventQueue.add(event); inputEventQueue.add(event);
if (event instanceof TouchEvent) { if (event instanceof TouchEvent) {
@ -180,9 +175,9 @@ public class IosInputHandler implements TouchInput {
} }
// ---------------- // ----------------
public void injectTouchDown(int pointerId, long time, float x, float y) { public void injectTouchDown(int pointerId, long time, float x, float y) {
logger.log(Level.FINE, "Using input scaling, scaleX: {0}, scaleY: {1}, width: {2}, height: {3}", logger.log(Level.FINE, "Using input scaling, scaleX: {0}, scaleY: {1}, width: {2}, height: {3}",
new Object[]{scaleX, scaleY, width, height}); new Object[]{scaleX, scaleY, width, height});
if (touchHandler != null) { if (touchHandler != null) {
touchHandler.actionDown(pointerId, time, x, y); touchHandler.actionDown(pointerId, time, x, y);

Loading…
Cancel
Save