Android: Remove unused property to track if joysticks are enabled.

experimental
iwgeric 10 years ago
parent 4102e91456
commit 47e9b9ba16
  1. 528
      jme3-android/src/main/java/com/jme3/input/android/AndroidInputHandler.java

@ -1,265 +1,263 @@
/* /*
* Copyright (c) 2009-2012 jMonkeyEngine * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
* met: * met:
* *
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* *
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* *
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jme3.input.android; package com.jme3.input.android;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Build; import android.os.Build;
import android.view.View; import android.view.View;
import com.jme3.input.RawInputListener; import com.jme3.input.RawInputListener;
import com.jme3.input.TouchInput; import com.jme3.input.TouchInput;
import com.jme3.input.event.InputEvent; import com.jme3.input.event.InputEvent;
import com.jme3.input.event.KeyInputEvent; import com.jme3.input.event.KeyInputEvent;
import com.jme3.input.event.MouseButtonEvent; import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent; import com.jme3.input.event.MouseMotionEvent;
import com.jme3.input.event.TouchEvent; import com.jme3.input.event.TouchEvent;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* <code>AndroidInput</code> is the main class that connects the Android system * <code>AndroidInput</code> is the main class that connects the Android system
* inputs to jME. It serves as the manager that gathers inputs from the various * inputs to jME. It serves as the manager that gathers inputs from the various
* Android input methods and provides them to jME's <code>InputManager</code>. * Android input methods and provides them to jME's <code>InputManager</code>.
* *
* @author iwgeric * @author iwgeric
*/ */
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;
private boolean mouseEventsInvertY = false; private boolean mouseEventsInvertY = false;
private boolean keyboardEventsEnabled = false; private boolean keyboardEventsEnabled = 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; private AndroidKeyHandler keyHandler;
private AndroidKeyHandler keyHandler; private AndroidGestureHandler gestureHandler;
private AndroidGestureHandler gestureHandler; private boolean initialized = false;
private boolean initialized = false; private RawInputListener listener = null;
private RawInputListener listener = null; private ConcurrentLinkedQueue<InputEvent> inputEventQueue = new ConcurrentLinkedQueue<InputEvent>();
private ConcurrentLinkedQueue<InputEvent> inputEventQueue = new ConcurrentLinkedQueue<InputEvent>(); private final static int MAX_TOUCH_EVENTS = 1024;
private final static int MAX_TOUCH_EVENTS = 1024; 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); if (buildVersion >= 14) {
if (buildVersion >= 14) { // add support for onHover and GenericMotionEvent (ie. gamepads)
// add support for onHover and GenericMotionEvent (ie. gamepads) gestureHandler = new AndroidGestureHandler(this);
gestureHandler = new AndroidGestureHandler(this); touchHandler = new AndroidTouchHandler14(this, gestureHandler);
touchHandler = new AndroidTouchHandler14(this, gestureHandler); keyHandler = new AndroidKeyHandler(this);
keyHandler = new AndroidKeyHandler(this); } else if (buildVersion >= 8){
} else if (buildVersion >= 8){ gestureHandler = new AndroidGestureHandler(this);
gestureHandler = new AndroidGestureHandler(this); touchHandler = new AndroidTouchHandler(this, gestureHandler);
touchHandler = new AndroidTouchHandler(this, gestureHandler); 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); }
} if (keyHandler != null) {
if (keyHandler != null) { keyHandler.setView(view);
keyHandler.setView(view); }
} if (gestureHandler != null) {
if (gestureHandler != null) { gestureHandler.setView(view);
gestureHandler.setView(view); }
} 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) { keyboardEventsEnabled = settings.isEmulateKeyboard();
keyboardEventsEnabled = settings.isEmulateKeyboard(); mouseEventsEnabled = settings.isEmulateMouse();
mouseEventsEnabled = settings.isEmulateMouse(); mouseEventsInvertX = settings.isEmulateMouseFlipX();
mouseEventsInvertX = settings.isEmulateMouseFlipX(); mouseEventsInvertY = settings.isEmulateMouseFlipY();
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) {
// view width and height are 0 until the view is displayed on the screen scaleX = (float)settings.getWidth() / (float)view.getWidth();
if (view.getWidth() != 0 && view.getHeight() != 0) { scaleY = (float)settings.getHeight() / (float)view.getHeight();
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}",
} new Object[]{scaleX, scaleY});
logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}",
new Object[]{scaleX, scaleY}); }
} // -----------------------------------------
// JME3 Input interface
// ----------------------------------------- @Override
// JME3 Input interface public void initialize() {
@Override touchEventPool.initialize();
public void initialize() { if (touchHandler != null) {
touchEventPool.initialize(); touchHandler.initialize();
if (touchHandler != null) { }
touchHandler.initialize(); if (keyHandler != null) {
} keyHandler.initialize();
if (keyHandler != null) { }
keyHandler.initialize(); if (gestureHandler != null) {
} gestureHandler.initialize();
if (gestureHandler != null) { }
gestureHandler.initialize();
} initialized = true;
}
initialized = true;
} @Override
public void destroy() {
@Override initialized = false;
public void destroy() {
initialized = false; touchEventPool.destroy();
if (touchHandler != null) {
touchEventPool.destroy(); touchHandler.destroy();
if (touchHandler != null) { }
touchHandler.destroy(); if (keyHandler != null) {
} keyHandler.destroy();
if (keyHandler != null) { }
keyHandler.destroy(); if (gestureHandler != null) {
} gestureHandler.destroy();
if (gestureHandler != null) { }
gestureHandler.destroy();
} setView(null);
}
setView(null);
} @Override
public boolean isInitialized() {
@Override return initialized;
public boolean isInitialized() { }
return initialized;
} @Override
public void setInputListener(RawInputListener listener) {
@Override this.listener = listener;
public void setInputListener(RawInputListener listener) { }
this.listener = listener;
} @Override
public long getInputTimeNanos() {
@Override return System.nanoTime();
public long getInputTimeNanos() { }
return System.nanoTime();
} public void update() {
if (listener != null) {
public void update() { InputEvent inputEvent;
if (listener != null) {
InputEvent inputEvent; while ((inputEvent = inputEventQueue.poll()) != null) {
if (inputEvent instanceof TouchEvent) {
while ((inputEvent = inputEventQueue.poll()) != null) { listener.onTouchEvent((TouchEvent)inputEvent);
if (inputEvent instanceof TouchEvent) { } else if (inputEvent instanceof MouseButtonEvent) {
listener.onTouchEvent((TouchEvent)inputEvent); listener.onMouseButtonEvent((MouseButtonEvent)inputEvent);
} else if (inputEvent instanceof MouseButtonEvent) { } else if (inputEvent instanceof MouseMotionEvent) {
listener.onMouseButtonEvent((MouseButtonEvent)inputEvent); listener.onMouseMotionEvent((MouseMotionEvent)inputEvent);
} else if (inputEvent instanceof MouseMotionEvent) { } else if (inputEvent instanceof KeyInputEvent) {
listener.onMouseMotionEvent((MouseMotionEvent)inputEvent); listener.onKeyEvent((KeyInputEvent)inputEvent);
} else if (inputEvent instanceof KeyInputEvent) { }
listener.onKeyEvent((KeyInputEvent)inputEvent); }
} }
} }
}
} // -----------------------------------------
// ----------------------------------------- public TouchEvent getFreeTouchEvent() {
return touchEventPool.getNextFreeEvent();
public TouchEvent getFreeTouchEvent() { }
return touchEventPool.getNextFreeEvent();
} public void addEvent(InputEvent event) {
inputEventQueue.add(event);
public void addEvent(InputEvent event) { if (event instanceof TouchEvent) {
inputEventQueue.add(event); touchEventPool.storeEvent((TouchEvent)event);
if (event instanceof TouchEvent) { }
touchEventPool.storeEvent((TouchEvent)event); }
}
} public void setSimulateMouse(boolean simulate) {
this.mouseEventsEnabled = simulate;
public void setSimulateMouse(boolean simulate) { }
this.mouseEventsEnabled = simulate;
} public boolean isSimulateMouse() {
return mouseEventsEnabled;
public boolean isSimulateMouse() { }
return mouseEventsEnabled;
} public boolean isMouseEventsInvertX() {
return mouseEventsInvertX;
public boolean isMouseEventsInvertX() { }
return mouseEventsInvertX;
} public boolean isMouseEventsInvertY() {
return mouseEventsInvertY;
public boolean isMouseEventsInvertY() { }
return mouseEventsInvertY;
} public void setSimulateKeyboard(boolean simulate) {
this.keyboardEventsEnabled = simulate;
public void setSimulateKeyboard(boolean simulate) { }
this.keyboardEventsEnabled = simulate;
} public boolean isSimulateKeyboard() {
return keyboardEventsEnabled;
public boolean isSimulateKeyboard() { }
return keyboardEventsEnabled;
} public void setOmitHistoricEvents(boolean dontSendHistory) {
this.dontSendHistory = dontSendHistory;
public void setOmitHistoricEvents(boolean dontSendHistory) { }
this.dontSendHistory = dontSendHistory;
} }
}

Loading…
Cancel
Save