Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import android.view.ScaleGestureDetector;
import android.view.View;
import com.jme3.input.JoyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.TouchInput;
import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.system.AppSettings;
import java.util.logging.Logger;

Expand All @@ -60,11 +62,12 @@ public class AndroidInputHandler implements View.OnTouchListener,
protected GLSurfaceView view;
protected AndroidTouchInput touchInput;
protected AndroidJoyInput joyInput;

protected MouseInput mouseInput;

public AndroidInputHandler() {
touchInput = new AndroidTouchInput(this);
joyInput = new AndroidJoyInput(this);
mouseInput = new DummyMouseInput();
}

public void setView(View view) {
Expand Down Expand Up @@ -118,6 +121,10 @@ public JoyInput getJoyInput() {
return joyInput;
}

public MouseInput getMouseInput() {
return mouseInput;
}

/*
* Android input events include the source from which the input came from.
* We must look at the source of the input event to determine which type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

import com.jme3.system.AppSettings;

import java.util.logging.Logger;

/**
Expand All @@ -55,6 +58,7 @@ public class AndroidInputHandler14 extends AndroidInputHandler implements View.O
public AndroidInputHandler14() {
touchInput = new AndroidTouchInput14(this);
joyInput = new AndroidJoyInput14(this);
mouseInput = new AndroidMouseInput14(this);
}

@Override
Expand All @@ -71,6 +75,12 @@ protected void addListeners(GLSurfaceView view) {
view.setOnGenericMotionListener(this);
}

@Override
public void loadSettings(AppSettings settings) {
super.loadSettings(settings);
((AndroidMouseInput14)mouseInput).loadSettings(settings);
}

@Override
public boolean onHover(View view, MotionEvent event) {
if (view != getView()) {
Expand All @@ -91,6 +101,12 @@ public boolean onHover(View view, MotionEvent event) {
consumed = ((AndroidTouchInput14)touchInput).onHover(event);
}

boolean isMouse = ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE);
if (isMouse && mouseInput != null) {
// send the event to the mouse processor
consumed = ((AndroidMouseInput14)mouseInput).onHover(event);
}

return consumed;
}

Expand All @@ -116,6 +132,28 @@ public boolean onGenericMotion(View view, MotionEvent event) {
consumed = consumed || ((AndroidJoyInput14)joyInput).onGenericMotion(event);
}

if((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
consumed = consumed || ((AndroidMouseInput14)mouseInput).onGenericMotion(event);
}

return consumed;
}

@Override
public boolean onTouch(View view, MotionEvent event) {
if (view != getView()) {
return false;
}

boolean consumed = super.onTouch(view, event);

// Mouse movement while button down is received as onTouch event instead
boolean isMouse = ((event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE);
if (isMouse && mouseInput != null) {
// send the event to the mouse processor
consumed |= ((AndroidMouseInput14)mouseInput).onGenericMotion(event);
}

return consumed;
}

Expand Down Expand Up @@ -154,7 +192,6 @@ public boolean onKey(View view, int keyCode, KeyEvent event) {
}

return consumed;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2009-2026 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jme3.input.android;

/**
* <code>AndroidInputHandler24</code> extends <code>AndroidInputHandler14</code> to
* use AndroidMouseInput24 which adds usage of newer events and also enables cursor visibility
* and cursor image change.
*
* @author joliver82
*/
public class AndroidInputHandler24 extends AndroidInputHandler14 {

public AndroidInputHandler24() {
super();
mouseInput = new AndroidMouseInput24(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2009-2026 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jme3.input.android;

import android.opengl.GLSurfaceView;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;

/**
* <code>AndroidInputHandler26</code> extends <code>AndroidInputHandler24</code> to
* add the onCapturedPointer events that where added in Android rev 26.<br>
* The onCapturedPointer events are received when mouse is grabbed/captured.
*
* @author joliver82
*/
public class AndroidInputHandler26 extends AndroidInputHandler24 implements View.OnCapturedPointerListener {

public AndroidInputHandler26() {
super();
mouseInput = new AndroidMouseInput26(this);
}

protected void removeListeners(GLSurfaceView view) {
super.removeListeners(view);
view.setOnCapturedPointerListener(null);
}

@Override
protected void addListeners(GLSurfaceView view) {
super.addListeners(view);
view.setOnCapturedPointerListener(this);
}

@Override
public boolean onCapturedPointer(View view, MotionEvent event) {
if (view != getView()) {
return false;
}

boolean consumed = false;
boolean isMouse = ((event.getSource() & InputDevice.SOURCE_MOUSE_RELATIVE) == InputDevice.SOURCE_MOUSE_RELATIVE);
if (isMouse && mouseInput != null) {
consumed = ((AndroidMouseInput26)mouseInput).onCapturedPointer(event);
}

return consumed;
}
}
Loading