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){
eventQueue.push(event);
}
}
}
@ -679,8 +679,4 @@ public class AndroidInput implements
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 {
private static final Logger logger = Logger.getLogger(AndroidInputHandler.class.getName());
// Custom settings
private boolean mouseEventsEnabled = true;
private boolean mouseEventsInvertX = false;
@ -64,8 +64,8 @@ public class AndroidInputHandler implements TouchInput {
private boolean keyboardEventsEnabled = false;
private boolean joystickEventsEnabled = false;
private boolean dontSendHistory = false;
// Internal
private GLSurfaceView view;
private AndroidTouchHandler touchHandler;
@ -78,8 +78,8 @@ public class AndroidInputHandler implements TouchInput {
private final TouchEventPool touchEventPool = new TouchEventPool(MAX_TOUCH_EVENTS);
private float scaleX = 1f;
private float scaleY = 1f;
public AndroidInputHandler() {
int buildVersion = Build.VERSION.SDK_INT;
logger.log(Level.INFO, "Android Build Version: {0}", buildVersion);
@ -94,14 +94,14 @@ public class AndroidInputHandler implements TouchInput {
keyHandler = new AndroidKeyHandler(this);
}
}
public AndroidInputHandler(AndroidTouchHandler touchInput,
public AndroidInputHandler(AndroidTouchHandler touchInput,
AndroidKeyHandler keyInput, AndroidGestureHandler gestureHandler) {
this.touchHandler = touchInput;
this.keyHandler = keyInput;
this.gestureHandler = gestureHandler;
}
public void setView(View view) {
if (touchHandler != null) {
touchHandler.setView(view);
@ -114,27 +114,27 @@ public class AndroidInputHandler implements TouchInput {
}
this.view = (GLSurfaceView)view;
}
public View getView() {
return view;
}
public float invertX(float origX) {
return getJmeX(view.getWidth()) - origX;
}
public float invertY(float origY) {
return getJmeY(view.getHeight()) - origY;
}
public float getJmeX(float origX) {
return origX * scaleX;
}
public float getJmeY(float origY) {
return origY * scaleY;
}
public void loadSettings(AppSettings settings) {
// TODO: add simulate keyboard to settings
// keyboardEventsEnabled = true;
@ -142,15 +142,15 @@ public class AndroidInputHandler implements TouchInput {
mouseEventsInvertX = settings.isEmulateMouseFlipX();
mouseEventsInvertY = settings.isEmulateMouseFlipY();
joystickEventsEnabled = settings.useJoysticks();
// view width and height are 0 until the view is displayed on the screen
if (view.getWidth() != 0 && view.getHeight() != 0) {
scaleX = (float)settings.getWidth() / (float)view.getWidth();
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});
}
// -----------------------------------------
@ -167,14 +167,14 @@ public class AndroidInputHandler implements TouchInput {
if (gestureHandler != null) {
gestureHandler.initialize();
}
initialized = true;
}
@Override
public void destroy() {
initialized = false;
touchEventPool.destroy();
if (touchHandler != null) {
touchHandler.destroy();
@ -185,7 +185,7 @@ public class AndroidInputHandler implements TouchInput {
if (gestureHandler != null) {
gestureHandler.destroy();
}
setView(null);
}
@ -203,11 +203,11 @@ public class AndroidInputHandler implements TouchInput {
public long getInputTimeNanos() {
return System.nanoTime();
}
public void update() {
if (listener != null) {
InputEvent inputEvent;
while ((inputEvent = inputEventQueue.poll()) != null) {
if (inputEvent instanceof TouchEvent) {
listener.onTouchEvent((TouchEvent)inputEvent);
@ -223,11 +223,11 @@ public class AndroidInputHandler implements TouchInput {
}
// -----------------------------------------
public TouchEvent getFreeTouchEvent() {
return touchEventPool.getNextFreeEvent();
}
public void addEvent(InputEvent event) {
inputEventQueue.add(event);
if (event instanceof TouchEvent) {
@ -246,7 +246,7 @@ public class AndroidInputHandler implements TouchInput {
public boolean getSimulateMouse() {
return mouseEventsEnabled;
}
public boolean isMouseEventsInvertX() {
return mouseEventsInvertX;
}
@ -254,7 +254,7 @@ public class AndroidInputHandler implements TouchInput {
public boolean isMouseEventsInvertY() {
return mouseEventsInvertY;
}
public void setSimulateKeyboard(boolean simulate) {
this.keyboardEventsEnabled = simulate;
}
@ -263,11 +263,4 @@ public class AndroidInputHandler implements TouchInput {
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
* or device buttons. All key events are consumed by jME except for the Volume
* buttons and menu button.
*
*
* 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
* in complete strings.
*
*
* @author iwgeric
*/
public class AndroidKeyHandler implements View.OnKeyListener {
private static final Logger logger = Logger.getLogger(AndroidKeyHandler.class.getName());
private AndroidInputHandler androidInput;
private boolean sendKeyEvents = true;
public AndroidKeyHandler(AndroidInputHandler androidInput) {
this.androidInput = androidInput;
}
public void initialize() {
}
public void destroy() {
}
public void setView(View view) {
if (view != null) {
view.setOnKeyListener(this);
@ -75,7 +75,7 @@ public class AndroidKeyHandler implements View.OnKeyListener {
androidInput.getView().setOnKeyListener(null);
}
}
/**
* 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()) {
return false;
}
TouchEvent evt;
// TODO: get touch event from pool
if (event.getAction() == KeyEvent.ACTION_DOWN) {
@ -107,50 +107,32 @@ public class AndroidKeyHandler implements View.OnKeyListener {
androidInput.addEvent(evt);
}
KeyInputEvent kie;
char unicodeChar = (char)event.getUnicodeChar();
int jmeKeyCode = AndroidKeyMapping.getJmeKey(keyCode);
boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
boolean repeating = pressed && event.getRepeatCount() > 0;
kie = new KeyInputEvent(jmeKeyCode, unicodeChar, pressed, repeating);
kie.setTime(event.getEventTime());
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});
// logger.log(Level.FINE, "creating KeyInputEvent: {0}", kie);
// consume all keys ourself except Volume Up/Down and Menu
// Don't do Menu so that typical Android Menus can be created and used
// by the user in MainActivity
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) ||
(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ||
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) ||
(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ||
(keyCode == KeyEvent.KEYCODE_MENU)) {
return false;
} else {
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.
*/
public static final int KEYCODE_VOLUME_UP = 0x18;
public static final int KEYCODE_VOLUME_UP = 0x18;
/**
* 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
*
*
* @param simulate if mouse events should be generated
*/
public void setSimulateMouse(boolean simulate);
/**
* Get if mouse events are generated
* @deprecated Use {@link #isSimulateMouse() }.
*/
@Deprecated
public boolean getSimulateMouse();
/**
* @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
*
*
* @param simulate if keyboard events should be generated
*/
public void setSimulateKeyboard(boolean simulate);
/**
* 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">
@ -99,11 +99,5 @@ public interface TouchInput extends Input {
* @param dontSendHistory turn of historic events if true, false else and default
*/
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
public void update() {
logger.log(Level.FINE, "InputEvent update : {0}",
logger.log(Level.FINE, "InputEvent update : {0}",
new Object[]{listener});
if (listener != null) {
InputEvent inputEvent;
while ((inputEvent = inputEventQueue.poll()) != null) {
if (inputEvent instanceof TouchEvent) {
listener.onTouchEvent((TouchEvent)inputEvent);
@ -117,20 +117,15 @@ public class IosInputHandler implements TouchInput {
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) {
// TODO: add simulate keyboard to settings
// keyboardEventsEnabled = true;
mouseEventsEnabled = true;//settings.isEmulateMouse();
mouseEventsInvertX = settings.isEmulateMouseFlipX();
mouseEventsInvertY = settings.isEmulateMouseFlipY();
// view width and height are 0 until the view is displayed on the screen
//if (view.getWidth() != 0 && view.getHeight() != 0) {
// scaleX = (float)settings.getWidth() / (float)view.getWidth();
@ -140,10 +135,10 @@ public class IosInputHandler implements TouchInput {
scaleY = 1.0f;
width = settings.getWidth();
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});
}
public boolean isMouseEventsInvertX() {
return mouseEventsInvertX;
}
@ -151,19 +146,19 @@ public class IosInputHandler implements TouchInput {
public boolean isMouseEventsInvertY() {
return mouseEventsInvertY;
}
public float invertX(float origX) {
return getJmeX(width) - origX;
}
public float invertY(float origY) {
return getJmeY(height) - origY;
}
public float getJmeX(float origX) {
return origX * scaleX;
}
public float getJmeY(float origY) {
return origY * scaleY;
}
@ -171,7 +166,7 @@ public class IosInputHandler implements TouchInput {
public TouchEvent getFreeTouchEvent() {
return touchEventPool.getNextFreeEvent();
}
public void addEvent(InputEvent event) {
inputEventQueue.add(event);
if (event instanceof TouchEvent) {
@ -180,9 +175,9 @@ public class IosInputHandler implements TouchInput {
}
// ----------------
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});
if (touchHandler != null) {
touchHandler.actionDown(pointerId, time, x, y);

Loading…
Cancel
Save