From b143df91be5c7f18a61666baa4a5b673d2cfd2cd Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 28 Oct 2019 16:40:14 +0100 Subject: Android: Native motion controls --- .../org/dolphinemu/dolphinemu/NativeLibrary.java | 12 +++ .../dolphinemu/activities/EmulationActivity.java | 19 +++++ .../dolphinemu/utils/DirectoryInitialization.java | 2 +- .../dolphinemu/utils/MotionListener.java | 88 ++++++++++++++++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java (limited to 'Source/Android/app/src/main/java') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 0595100e09..5bb6a92b23 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -195,6 +195,18 @@ public final class NativeLibrary public static final int TURNTABLE_CROSSFADE = 622; public static final int TURNTABLE_CROSSFADE_LEFT = 623; public static final int TURNTABLE_CROSSFADE_RIGHT = 624; + public static final int WIIMOTE_ACCEL_LEFT = 625; + public static final int WIIMOTE_ACCEL_RIGHT = 626; + public static final int WIIMOTE_ACCEL_FORWARD = 627; + public static final int WIIMOTE_ACCEL_BACKWARD = 628; + public static final int WIIMOTE_ACCEL_UP = 629; + public static final int WIIMOTE_ACCEL_DOWN = 630; + public static final int WIIMOTE_GYRO_PITCH_UP = 631; + public static final int WIIMOTE_GYRO_PITCH_DOWN = 632; + public static final int WIIMOTE_GYRO_ROLL_LEFT = 633; + public static final int WIIMOTE_GYRO_ROLL_RIGHT = 634; + public static final int WIIMOTE_GYRO_YAW_LEFT = 635; + public static final int WIIMOTE_GYRO_YAW_RIGHT = 636; } /** diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index ad97625af0..ac31446250 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -48,6 +48,7 @@ import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; import org.dolphinemu.dolphinemu.utils.Java_GCAdapter; import org.dolphinemu.dolphinemu.utils.Java_WiimoteAdapter; +import org.dolphinemu.dolphinemu.utils.MotionListener; import org.dolphinemu.dolphinemu.utils.Rumble; import org.dolphinemu.dolphinemu.utils.TvUtil; @@ -66,6 +67,7 @@ public final class EmulationActivity extends AppCompatActivity private EmulationFragment mEmulationFragment; private SharedPreferences mPreferences; + private MotionListener mMotionListener; private ControllerMappingHelper mControllerMappingHelper; private Settings mSettings; @@ -258,6 +260,7 @@ public final class EmulationActivity extends AppCompatActivity // first launch emulation and then ask the core which console we're emulating sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE; mDeviceHasTouchScreen = getPackageManager().hasSystemFeature("android.hardware.touchscreen"); + mMotionListener = new MotionListener(this); mControllerMappingHelper = new ControllerMappingHelper(); int themeId; @@ -347,6 +350,22 @@ public final class EmulationActivity extends AppCompatActivity mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM); } + @Override + protected void onResume() + { + super.onResume(); + if (!sIsGameCubeGame) + mMotionListener.enable(); + } + + @Override + protected void onPause() + { + super.onPause(); + if (!sIsGameCubeGame) + mMotionListener.disable(); + } + @Override protected void onStop() { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java index 727240b478..2b54e2ac1a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java @@ -34,7 +34,7 @@ public final class DirectoryInitialization "org.dolphinemu.dolphinemu.DIRECTORY_INITIALIZATION"; public static final String EXTRA_STATE = "directoryState"; - private static final Integer WiimoteNewVersion = 2; + private static final int WiimoteNewVersion = 3; // Last changed in PR 8439 private static volatile DirectoryInitializationState directoryState = null; private static String userPath; private static String internalPath; 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 new file mode 100644 index 0000000000..98ee46a40e --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java @@ -0,0 +1,88 @@ +package org.dolphinemu.dolphinemu.utils; + +import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; + +import org.dolphinemu.dolphinemu.NativeLibrary; +import org.dolphinemu.dolphinemu.NativeLibrary.ButtonType; + +public class MotionListener implements SensorEventListener +{ + private final SensorManager mSensorManager; + private final Sensor mAccelSensor; + private final Sensor mGyroSensor; + + // The same sampling period as for Wii Remotes + private static final int SAMPLING_PERIOD_US = 1000000 / 200; + + public MotionListener(Context context) + { + mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); + mAccelSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); + mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); + } + + @Override + public void onSensorChanged(SensorEvent sensorEvent) + { + 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, + ButtonType.WIIMOTE_ACCEL_RIGHT, x); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_FORWARD, y); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_BACKWARD, y); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_UP, z); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_ACCEL_DOWN, z); + } + + 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, + ButtonType.WIIMOTE_GYRO_PITCH_DOWN, x); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_ROLL_LEFT, y); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_ROLL_RIGHT, y); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_YAW_LEFT, z); + NativeLibrary.onGamePadMoveEvent(NativeLibrary.TouchScreenDevice, + ButtonType.WIIMOTE_GYRO_YAW_RIGHT, z); + } + } + + @Override + public void onAccuracyChanged(Sensor sensor, int i) + { + // We don't care about this + } + + public void enable() + { + if (mAccelSensor != null) + mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US); + if (mGyroSensor != null) + mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US); + } + + public void disable() + { + mSensorManager.unregisterListener(this); + } +} -- cgit v1.2.3 From 455790138243a0bb53b298cba7626bd1e1d529df Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 5 Nov 2019 18:18:54 +0100 Subject: Android: Make "Horizontal Wii Remote" flip the motion controls Before, it only flipped the d-pad (and arranged the overlay buttons differently). --- .../dolphinemu/activities/EmulationActivity.java | 2 ++ .../dolphinemu/dolphinemu/overlay/InputOverlay.java | 21 +++++---------------- 2 files changed, 7 insertions(+), 16 deletions(-) (limited to 'Source/Android/app/src/main/java') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index ac31446250..58af2a2b80 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -869,6 +869,8 @@ public final class EmulationActivity extends AppCompatActivity editor.putInt("wiiController", indexSelected); NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "Extension", getResources().getStringArray(R.array.controllersValues)[indexSelected]); + NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", + "Options/Sideways Wiimote", indexSelected == 2 ? "True" : "False"); NativeLibrary.ReloadWiimoteConfig(); }); builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java index 40e4a3d6ed..e2c6c1978c 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java @@ -571,22 +571,11 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener } if (mPreferences.getBoolean("buttonToggleWii7", true)) { - if (mPreferences.getInt("wiiController", 3) == 2) - { - overlayDpads.add(initializeOverlayDpad(getContext(), R.drawable.gcwii_dpad, - R.drawable.gcwii_dpad_pressed_one_direction, - R.drawable.gcwii_dpad_pressed_two_directions, - ButtonType.WIIMOTE_RIGHT, ButtonType.WIIMOTE_LEFT, - ButtonType.WIIMOTE_UP, ButtonType.WIIMOTE_DOWN, orientation)); - } - else - { - overlayDpads.add(initializeOverlayDpad(getContext(), R.drawable.gcwii_dpad, - R.drawable.gcwii_dpad_pressed_one_direction, - R.drawable.gcwii_dpad_pressed_two_directions, - ButtonType.WIIMOTE_UP, ButtonType.WIIMOTE_DOWN, - ButtonType.WIIMOTE_LEFT, ButtonType.WIIMOTE_RIGHT, orientation)); - } + overlayDpads.add(initializeOverlayDpad(getContext(), R.drawable.gcwii_dpad, + R.drawable.gcwii_dpad_pressed_one_direction, + R.drawable.gcwii_dpad_pressed_two_directions, + ButtonType.WIIMOTE_UP, ButtonType.WIIMOTE_DOWN, + ButtonType.WIIMOTE_LEFT, ButtonType.WIIMOTE_RIGHT, orientation)); } } -- cgit v1.2.3 From a548489aaf6a0e30a478b473334b7cfa2e22b2f4 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 1 Nov 2019 17:03:05 +0100 Subject: Android: Adjust accel/gyro data for screen orientation --- .../dolphinemu/utils/MotionListener.java | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'Source/Android/app/src/main/java') 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, -- cgit v1.2.3 From 4d838212e2622f623a7f864163396a6a9634e47f Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 4 Nov 2019 00:15:35 +0100 Subject: Android: Overhaul the orientation lock setting When using motion controls, it's useful to be able to lock the screen to a certain orientation so that Android won't interpret game motions as an intent to change the screen orientation. To this end, I've changed the existing orientation lock setting in the following ways: - A portrait lock mode has been added in addition to the existing landscape lock mode and unlocked mode. - The landscape lock mode now locks to regular landscape rather than letting you change between the two possible landscape orientations. - The setting is now accessed during emulation rather than outside. --- .../dolphinemu/activities/EmulationActivity.java | 66 +++++++++++++++++----- .../settings/ui/SettingsFragmentPresenter.java | 8 --- .../features/settings/utils/SettingsFile.java | 1 - 3 files changed, 51 insertions(+), 24 deletions(-) (limited to 'Source/Android/app/src/main/java') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 58af2a2b80..f6756d30b0 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -24,6 +24,7 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; +import android.view.Surface; import android.view.View; import android.widget.SeekBar; import android.widget.TextView; @@ -98,7 +99,8 @@ public final class EmulationActivity extends AppCompatActivity MENU_ACTION_SAVE_SLOT6, MENU_ACTION_LOAD_SLOT1, MENU_ACTION_LOAD_SLOT2, MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5, MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC, - MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP}) + MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP, + MENU_ACTION_SCREEN_ORIENTATION}) public @interface MenuAction { } @@ -132,6 +134,7 @@ public final class EmulationActivity extends AppCompatActivity public static final int MENU_ACTION_RESET_OVERLAY = 26; public static final int MENU_SET_IR_SENSITIVITY = 27; public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28; + public static final int MENU_ACTION_SCREEN_ORIENTATION = 29; private static SparseIntArray buttonsActionsMap = new SparseIntArray(); @@ -178,6 +181,8 @@ public final class EmulationActivity extends AppCompatActivity EmulationActivity.MENU_SET_IR_SENSITIVITY); buttonsActionsMap.append(R.id.menu_emulation_choose_doubletap, EmulationActivity.MENU_ACTION_CHOOSE_DOUBLETAP); + buttonsActionsMap.append(R.id.menu_screen_orientation, + EmulationActivity.MENU_ACTION_SCREEN_ORIENTATION); } private static String[] scanForSecondDisc(GameFile gameFile) @@ -253,9 +258,13 @@ public final class EmulationActivity extends AppCompatActivity restoreState(savedInstanceState); } + mPreferences = PreferenceManager.getDefaultSharedPreferences(this); + mSettings = new Settings(); mSettings.loadSettings(null); + updateOrientation(); + // TODO: The accurate way to find out which console we're emulating is to // first launch emulation and then ask the core which console we're emulating sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE; @@ -297,17 +306,6 @@ public final class EmulationActivity extends AppCompatActivity setContentView(R.layout.activity_emulation); - - BooleanSetting lockLandscapeSetting = - (BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE) - .getSetting(SettingsFile.KEY_LOCK_LANDSCAPE); - boolean lockLandscape = lockLandscapeSetting == null || lockLandscapeSetting.getValue(); - // Force landscape if set - if (mDeviceHasTouchScreen && lockLandscape) - { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); - } - // Find or create the EmulationFragment mEmulationFragment = (EmulationFragment) getSupportFragmentManager() .findFragmentById(R.id.frame_emulation_fragment); @@ -323,9 +321,6 @@ public final class EmulationActivity extends AppCompatActivity { setTitle(mSelectedTitle); } - - mPreferences = PreferenceManager.getDefaultSharedPreferences(this); - } @Override @@ -431,6 +426,12 @@ public final class EmulationActivity extends AppCompatActivity View.SYSTEM_UI_FLAG_IMMERSIVE); } + private void updateOrientation() + { + setRequestedOrientation(mPreferences.getInt("emulationActivityOrientation", + ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)); + } + private void toggleMenu() { boolean result = getSupportFragmentManager().popBackStackImmediate( @@ -646,6 +647,10 @@ public final class EmulationActivity extends AppCompatActivity chooseDoubleTapButton(); return; + case MENU_ACTION_SCREEN_ORIENTATION: + chooseOrientation(); + return; + case MENU_ACTION_EXIT: // ATV menu is built using a fragment, this will pop that fragment before emulation ends. if (TvUtil.isLeanback(getApplicationContext())) @@ -883,6 +888,37 @@ public final class EmulationActivity extends AppCompatActivity alertDialog.show(); } + private void chooseOrientation() + { + final int[] orientationValues = getResources().getIntArray(R.array.orientationValues); + int initialChoice = mPreferences.getInt("emulationActivityOrientation", + ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + int initialIndex = -1; + for (int i = 0; i < orientationValues.length; i++) + { + if (orientationValues[i] == initialChoice) + initialIndex = i; + } + + final SharedPreferences.Editor editor = mPreferences.edit(); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.emulation_screen_orientation); + builder.setSingleChoiceItems(R.array.orientationEntries, initialIndex, + (dialog, indexSelected) -> + { + int orientation = orientationValues[indexSelected]; + editor.putInt("emulationActivityOrientation", orientation); + }); + builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> + { + editor.apply(); + updateOrientation(); + }); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + private void setIRSensitivity() { int ir_pitch = Integer.valueOf( diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index 83817cae95..8a47aae890 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -224,7 +224,6 @@ public final class SettingsFragmentPresenter Setting autoDiscChange = null; Setting analytics = null; Setting enableSaveState; - Setting lockToLandscape; SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE); SettingSection analyticsSection = mSettings.getSection(Settings.SECTION_ANALYTICS); @@ -238,7 +237,6 @@ public final class SettingsFragmentPresenter autoDiscChange = coreSection.getSetting(SettingsFile.KEY_AUTO_DISC_CHANGE); analytics = analyticsSection.getSetting(SettingsFile.KEY_ANALYTICS_ENABLED); enableSaveState = coreSection.getSetting(SettingsFile.KEY_ENABLE_SAVE_STATES); - lockToLandscape = coreSection.getSetting(SettingsFile.KEY_LOCK_LANDSCAPE); // TODO: Having different emuCoresEntries/emuCoresValues for each architecture is annoying. // The proper solution would be to have one emuCoresEntries and one emuCoresValues @@ -283,12 +281,6 @@ public final class SettingsFragmentPresenter sl.add(new CheckBoxSetting(SettingsFile.KEY_ENABLE_SAVE_STATES, Settings.SECTION_INI_CORE, R.string.enable_save_states, R.string.enable_save_states_description, false, enableSaveState)); - if (!TvUtil.isLeanback(DolphinApplication.getAppContext())) - { - sl.add(new CheckBoxSetting(SettingsFile.KEY_LOCK_LANDSCAPE, Settings.SECTION_INI_CORE, - R.string.lock_emulation_landscape, R.string.lock_emulation_landscape_desc, true, - lockToLandscape)); - } sl.add(new CheckBoxSetting(SettingsFile.KEY_ANALYTICS_ENABLED, Settings.SECTION_ANALYTICS, R.string.analytics, 0, false, analytics)); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java index aac139266f..d14992f5f9 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java @@ -52,7 +52,6 @@ public final class SettingsFile public static final String KEY_SLOT_A_DEVICE = "SlotA"; public static final String KEY_SLOT_B_DEVICE = "SlotB"; public static final String KEY_ENABLE_SAVE_STATES = "EnableSaveStates"; - public static final String KEY_LOCK_LANDSCAPE = "LockLandscape"; public static final String KEY_ANALYTICS_ENABLED = "Enabled"; public static final String KEY_ANALYTICS_PERMISSION_ASKED = "PermissionAsked"; -- cgit v1.2.3 From c8b8a60033bb35917c10eeb5c4043ee428ae61a6 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 20 Nov 2019 19:40:47 +0100 Subject: Android: Let WiimoteEmu know whether we have accelerometer/gyroscope --- .../app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java | 3 +++ .../src/main/java/org/dolphinemu/dolphinemu/utils/MotionListener.java | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'Source/Android/app/src/main/java') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 5bb6a92b23..60b07902c3 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -265,6 +265,9 @@ public final class NativeLibrary Rumble.checkRumble(padID, state); } + public static native void SetMotionSensorsEnabled(boolean accelerometerEnabled, + boolean gyroscopeEnabled); + public static native void NewGameIniFile(); public static native void LoadGameIniFile(String gameId); 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 e0d8d68b98..4230b0b7bc 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 @@ -101,10 +101,14 @@ public class MotionListener implements SensorEventListener mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US); if (mGyroSensor != null) mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US); + + NativeLibrary.SetMotionSensorsEnabled(mAccelSensor != null, mGyroSensor != null); } public void disable() { mSensorManager.unregisterListener(this); + + NativeLibrary.SetMotionSensorsEnabled(false, false); } } -- cgit v1.2.3 From 2d4a3f4597f14b2563fac7acf080b91fa4bac5e8 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 20 Nov 2019 20:09:16 +0100 Subject: Android: Add an option for disabling native motion controls --- .../dolphinemu/activities/EmulationActivity.java | 40 +++++++++++++++++++--- .../dolphinemu/utils/MotionListener.java | 12 +++++++ 2 files changed, 48 insertions(+), 4 deletions(-) (limited to 'Source/Android/app/src/main/java') diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index f6756d30b0..4f4ddf2c71 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -100,7 +100,7 @@ public final class EmulationActivity extends AppCompatActivity MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5, MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC, MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP, - MENU_ACTION_SCREEN_ORIENTATION}) + MENU_ACTION_SCREEN_ORIENTATION, MENU_ACTION_MOTION_CONTROLS}) public @interface MenuAction { } @@ -135,6 +135,7 @@ public final class EmulationActivity extends AppCompatActivity public static final int MENU_SET_IR_SENSITIVITY = 27; public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28; public static final int MENU_ACTION_SCREEN_ORIENTATION = 29; + public static final int MENU_ACTION_MOTION_CONTROLS = 30; private static SparseIntArray buttonsActionsMap = new SparseIntArray(); @@ -183,6 +184,8 @@ public final class EmulationActivity extends AppCompatActivity EmulationActivity.MENU_ACTION_CHOOSE_DOUBLETAP); buttonsActionsMap.append(R.id.menu_screen_orientation, EmulationActivity.MENU_ACTION_SCREEN_ORIENTATION); + buttonsActionsMap.append(R.id.menu_emulation_motion_controls, + EmulationActivity.MENU_ACTION_MOTION_CONTROLS); } private static String[] scanForSecondDisc(GameFile gameFile) @@ -349,7 +352,7 @@ public final class EmulationActivity extends AppCompatActivity protected void onResume() { super.onResume(); - if (!sIsGameCubeGame) + if (!sIsGameCubeGame && mPreferences.getInt("motionControlsEnabled", 0) != 2) mMotionListener.enable(); } @@ -357,8 +360,7 @@ public final class EmulationActivity extends AppCompatActivity protected void onPause() { super.onPause(); - if (!sIsGameCubeGame) - mMotionListener.disable(); + mMotionListener.disable(); } @Override @@ -651,6 +653,10 @@ public final class EmulationActivity extends AppCompatActivity chooseOrientation(); return; + case MENU_ACTION_MOTION_CONTROLS: + showMotionControlsOptions(); + return; + case MENU_ACTION_EXIT: // ATV menu is built using a fragment, this will pop that fragment before emulation ends. if (TvUtil.isLeanback(getApplicationContext())) @@ -888,6 +894,32 @@ public final class EmulationActivity extends AppCompatActivity alertDialog.show(); } + private void showMotionControlsOptions() + { + final SharedPreferences.Editor editor = mPreferences.edit(); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.emulation_motion_controls); + builder.setSingleChoiceItems(R.array.motionControlsEntries, + mPreferences.getInt("motionControlsEnabled", 0), + (dialog, indexSelected) -> + { + editor.putInt("motionControlsEnabled", indexSelected); + + if (indexSelected != 2) + mMotionListener.enable(); + else + mMotionListener.disable(); + + NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "IMUIR/Enabled", + indexSelected != 1 ? "True" : "False"); + NativeLibrary.ReloadWiimoteConfig(); + }); + builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> editor.apply()); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + private void chooseOrientation() { final int[] orientationValues = getResources().getIntArray(R.array.orientationValues); 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 4230b0b7bc..31d1641aba 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 @@ -18,6 +18,8 @@ public class MotionListener implements SensorEventListener private final Sensor mAccelSensor; private final Sensor mGyroSensor; + private boolean mEnabled = false; + // The same sampling period as for Wii Remotes private static final int SAMPLING_PERIOD_US = 1000000 / 200; @@ -97,18 +99,28 @@ public class MotionListener implements SensorEventListener public void enable() { + if (mEnabled) + return; + if (mAccelSensor != null) mSensorManager.registerListener(this, mAccelSensor, SAMPLING_PERIOD_US); if (mGyroSensor != null) mSensorManager.registerListener(this, mGyroSensor, SAMPLING_PERIOD_US); NativeLibrary.SetMotionSensorsEnabled(mAccelSensor != null, mGyroSensor != null); + + mEnabled = true; } public void disable() { + if (!mEnabled) + return; + mSensorManager.unregisterListener(this); NativeLibrary.SetMotionSensorsEnabled(false, false); + + mEnabled = false; } } -- cgit v1.2.3