Skip to content

Commit ab54490

Browse files
committed
disable AndroidSensorJoyInput
1 parent 8725dad commit ab54490

4 files changed

Lines changed: 27 additions & 17 deletions

File tree

jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.jme3.scene.Mesh;
1818
import com.jme3.scene.shape.Box;
1919
import com.jme3.scene.shape.Line;
20+
import com.jme3.system.AppSettings;
2021
import com.jme3.texture.Texture;
2122
import com.jme3.util.IntMap;
2223

@@ -79,6 +80,12 @@ public class TestAndroidSensors extends SimpleApplication implements ActionListe
7980

8081
// Make sure to set joystickEventsEnabled = true in MainActivity for Android
8182

83+
public static void configureSettings(AppSettings settings) {
84+
settings.setUseJoysticks(true);
85+
settings.setUseAndroidSensorJoystick(true);
86+
settings.setVirtualJoystick(AppSettings.VIRTUAL_JOYSTICK_DISABLED);
87+
}
88+
8289
private float toDegrees(float rad) {
8390
return rad * FastMath.RAD_TO_DEG;
8491
}
@@ -311,4 +318,4 @@ public void onAnalog(String string, float value, float tpf) {
311318
}
312319

313320
}
314-
}
321+
}

jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import androidx.fragment.app.Fragment;
4343
import com.jme3.audio.AudioRenderer;
4444
import com.jme3.input.JoyInput;
45-
import com.jme3.input.android.AndroidSensorJoyInput;
45+
import com.jme3.input.android.AndroidJoyInput;
4646
import com.jme3.system.AppSettings;
4747
import com.jme3.system.SystemListener;
4848
import com.jme3.system.android.JmeAndroidSystem;
@@ -269,8 +269,8 @@ public void gainFocus() {
269269
}
270270

271271
JoyInput joyInput = app.getContext() != null ? app.getContext().getJoyInput() : null;
272-
if (joyInput instanceof AndroidSensorJoyInput) {
273-
((AndroidSensorJoyInput) joyInput).resumeSensors();
272+
if (joyInput instanceof AndroidJoyInput) {
273+
((AndroidJoyInput) joyInput).resumeJoysticks();
274274
}
275275

276276
app.gainFocus();
@@ -295,8 +295,8 @@ public void loseFocus() {
295295
}
296296

297297
JoyInput joyInput = app.getContext() != null ? app.getContext().getJoyInput() : null;
298-
if (joyInput instanceof AndroidSensorJoyInput) {
299-
((AndroidSensorJoyInput) joyInput).pauseSensors();
298+
if (joyInput instanceof AndroidJoyInput) {
299+
((AndroidJoyInput) joyInput).pauseJoysticks();
300300
}
301301
}
302302
}

jme3-android/src/main/java/com/jme3/input/android/AndroidJoyInput.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@
5050
import java.util.logging.Logger;
5151

5252
/**
53-
* Main class that manages various joystick devices. Joysticks can be many forms
54-
* including a simulated joystick to communicate the device orientation as well
55-
* as physical joysticks. <br>
53+
* Main class that manages joystick devices. Joysticks can be physical gamepads,
54+
* the on-screen virtual joystick, or an explicitly-enabled sensor joystick. <br>
5655
* This class manages all the joysticks and feeds the inputs from each back
5756
* to jME's InputManager.
5857
*
@@ -81,7 +80,6 @@
8180
*/
8281
public class AndroidJoyInput implements JoyInput {
8382
private static final Logger logger = Logger.getLogger(AndroidJoyInput.class.getName());
84-
public static boolean disableSensors = false;
8583

8684
protected AndroidInputHandler inputHandler;
8785
protected List<Joystick> joystickList = new ArrayList<>();
@@ -96,16 +94,18 @@ public class AndroidJoyInput implements JoyInput {
9694
private boolean onDeviceJoystickRumble = false;
9795
private String virtualJoystickMode = AppSettings.VIRTUAL_JOYSTICK_AUTO_MINIMIZED;
9896
private boolean useJoysticks = true;
97+
private boolean useAndroidSensorJoystick = false;
9998
private boolean physicalJoystickAvailable = false;
10099
private boolean keyboardSuppressedAutoJoystick = false;
101100
private VirtualJoystick virtualJoystick;
101+
private GLSurfaceView view;
102102

103103
public AndroidJoyInput(AndroidInputHandler inputHandler) {
104104
this.inputHandler = inputHandler;
105-
sensorJoyInput = new AndroidSensorJoyInput(this);
106105
}
107106

108107
public void setView(GLSurfaceView view) {
108+
this.view = view;
109109
if (sensorJoyInput != null) {
110110
sensorJoyInput.setView(view);
111111
}
@@ -115,6 +115,7 @@ public void loadSettings(AppSettings settings) {
115115
onDeviceJoystickRumble = settings.isOnDeviceJoystickRumble();
116116
virtualJoystickMode = settings.getVirtualJoystickMode();
117117
useJoysticks = settings.useJoysticks();
118+
useAndroidSensorJoystick = settings.useAndroidSensorJoystick();
118119
}
119120

120121
boolean isOnDeviceJoystickRumble() {
@@ -150,7 +151,6 @@ public void resumeJoysticks() {
150151
if (sensorJoyInput != null) {
151152
sensorJoyInput.resumeSensors();
152153
}
153-
154154
}
155155

156156
@Override
@@ -166,12 +166,11 @@ public boolean isInitialized() {
166166
@Override
167167
public void destroy() {
168168
initialized = false;
169-
170169
if (sensorJoyInput != null) {
171170
sensorJoyInput.destroy();
171+
sensorJoyInput = null;
172172
}
173-
174-
setView(null);
173+
view = null;
175174
}
176175

177176
@Override
@@ -204,7 +203,11 @@ public Joystick[] loadJoysticks(InputManager inputManager) {
204203
logger.log(Level.INFO, "loading joysticks for {0}", this.getClass().getName());
205204
}
206205
joystickList.clear();
207-
if (!disableSensors) {
206+
if (useJoysticks && useAndroidSensorJoystick) {
207+
if (sensorJoyInput == null) {
208+
sensorJoyInput = new AndroidSensorJoyInput(this);
209+
sensorJoyInput.setView(view);
210+
}
208211
joystickList.add(sensorJoyInput.loadJoystick(joystickList.size(), inputManager));
209212
}
210213
physicalJoystickAvailable = false;

jme3-android/src/main/java/com/jme3/input/android/AndroidJoyInput14.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void destroy() {
9090

9191
@Override
9292
public Joystick[] loadJoysticks(InputManager inputManager) {
93-
// load the simulated joystick for device orientation
93+
// load virtual joystick if enabled
9494
super.loadJoysticks(inputManager);
9595
// load physical gamepads/joysticks
9696
int beforePhysicalJoysticks = joystickList.size();

0 commit comments

Comments
 (0)