summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2019-11-01 17:03:05 +0100
committerJosJuice <josjuice@gmail.com>2019-11-20 18:22:21 +0100
commita548489aaf6a0e30a478b473334b7cfa2e22b2f4 (patch)
tree1fccbd3dab16745f6c30275f69d0cae3f65cedd0 /Source/Android/app/src/main/java
parent455790138243a0bb53b298cba7626bd1e1d529df (diff)
Android: Adjust accel/gyro data for screen orientation
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java38
1 files changed, 30 insertions, 8 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java
index 98ee46a40e..e0d8d68b98 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java
@@ -1,16 +1,19 @@
package org.dolphinemu.dolphinemu.utils;
+import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
+import android.view.Surface;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.NativeLibrary.ButtonType;
public class MotionListener implements SensorEventListener
{
+ private final Activity mActivity;
private final SensorManager mSensorManager;
private final Sensor mAccelSensor;
private final Sensor mGyroSensor;
@@ -18,9 +21,10 @@ public class MotionListener implements SensorEventListener
// The same sampling period as for Wii Remotes
private static final int SAMPLING_PERIOD_US = 1000000 / 200;
- public MotionListener(Context context)
+ public MotionListener(Activity activity)
{
- mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ mActivity = activity;
+ mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
}
@@ -28,11 +32,32 @@ public class MotionListener implements SensorEventListener
@Override
public void onSensorChanged(SensorEvent sensorEvent)
{
+ float x, y;
+ float z = sensorEvent.values[2];
+ int orientation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
+ switch (orientation)
+ {
+ default:
+ case Surface.ROTATION_0:
+ x = -sensorEvent.values[0];
+ y = -sensorEvent.values[1];
+ break;
+ case Surface.ROTATION_90:
+ x = sensorEvent.values[1];
+ y = -sensorEvent.values[0];
+ break;
+ case Surface.ROTATION_180:
+ x = sensorEvent.values[0];
+ y = sensorEvent.values[1];
+ break;
+ case Surface.ROTATION_270:
+ x = -sensorEvent.values[1];
+ y = sensorEvent.values[0];
+ break;
+ }
+
if (sensorEvent.sensor == mAccelSensor)
{
- float x = -sensorEvent.values[0];
- float y = -sensorEvent.values[1];
- float z = sensorEvent.values[2];
NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice,
ButtonType.WIIMOTE_ACCEL_LEFT, x);
NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice,
@@ -49,9 +74,6 @@ public class MotionListener implements SensorEventListener
if (sensorEvent.sensor == mGyroSensor)
{
- float x = -sensorEvent.values[0];
- float y = -sensorEvent.values[1];
- float z = sensorEvent.values[2];
NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice,
ButtonType.WIIMOTE_GYRO_PITCH_UP, x);
NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice,