Skip to content
Permalink
Browse files

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.
  • Loading branch information...
JosJuice committed Nov 3, 2019
1 parent d0f6c79 commit adfb8d13062f2bbfc5717986d5ba74b5a1e4d572
@@ -24,6 +24,7 @@
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;
@@ -132,6 +133,7 @@
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();
@@ -167,6 +169,8 @@
buttonsActionsMap.append(R.id.menu_emulation_load_3, EmulationActivity.MENU_ACTION_LOAD_SLOT3);
buttonsActionsMap.append(R.id.menu_emulation_load_4, EmulationActivity.MENU_ACTION_LOAD_SLOT4);
buttonsActionsMap.append(R.id.menu_emulation_load_5, EmulationActivity.MENU_ACTION_LOAD_SLOT5);
buttonsActionsMap.append(R.id.menu_screen_orientation,
EmulationActivity.MENU_ACTION_SCREEN_ORIENTATION);
buttonsActionsMap.append(R.id.menu_change_disc, EmulationActivity.MENU_ACTION_CHANGE_DISC);
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
buttonsActionsMap.append(R.id.menu_emulation_joystick_rel_center,
@@ -253,9 +257,13 @@ protected void onCreate(Bundle savedInstanceState)
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 +305,6 @@ protected void onCreate(Bundle savedInstanceState)

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 +320,6 @@ protected void onCreate(Bundle savedInstanceState)
{
setTitle(mSelectedTitle);
}

mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

}

@Override
@@ -431,6 +425,12 @@ private void enableFullscreenImmersive()
View.SYSTEM_UI_FLAG_IMMERSIVE);
}

private void updateOrientation()
{
setRequestedOrientation(mPreferences.getInt("emulationActivityOrientation",
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE));
}

private void toggleMenu()
{
boolean result = getSupportFragmentManager().popBackStackImmediate(
@@ -634,6 +634,10 @@ public void handleMenuAction(@MenuAction int menuAction)
NativeLibrary.LoadState(5);
return;

case MENU_ACTION_SCREEN_ORIENTATION:
chooseOrientation();
return;

case MENU_ACTION_CHANGE_DISC:
FileBrowserHelper.openFilePicker(this, REQUEST_CHANGE_DISC, false);
return;
@@ -883,6 +887,37 @@ private void chooseController()
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(
@@ -224,7 +224,6 @@ private void addGeneralSettings(ArrayList<SettingsItem> sl)
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 @@ private void addGeneralSettings(ArrayList<SettingsItem> sl)
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 @@ else if (defaultCpuCore == 4) // AArch64
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));
}
@@ -52,7 +52,6 @@
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";
@@ -113,6 +113,11 @@
</menu>
</item>

<item
android:id="@+id/menu_screen_orientation"
app:showAsAction="never"
android:title="@string/emulation_screen_orientation"/>

<item
android:id="@+id/menu_change_disc"
app:showAsAction="never"
@@ -133,6 +133,11 @@
</menu>
</item>

<item
android:id="@+id/menu_screen_orientation"
app:showAsAction="never"
android:title="@string/emulation_screen_orientation"/>

<item
android:id="@+id/menu_change_disc"
app:showAsAction="never"
@@ -348,4 +348,15 @@
<item>Wii Controller Settings</item>
<item>Clear Game Settings</item>
</string-array>

<string-array name="orientationEntries">
<item>Landscape</item>
<item>Portrait</item>
<item>Auto</item>
</string-array>
<integer-array name="orientationValues">
<item>0</item>
<item>1</item>
<item>-1</item>
</integer-array>
</resources>
@@ -313,6 +313,7 @@
<string name="emulation_ir_group">Touch IR Pointer</string>
<string name="emulation_ir_sensitivity">IR Sensitivity</string>
<string name="emulation_choose_doubletap">Double tap button</string>
<string name="emulation_screen_orientation">Screen Orientation</string>

<!-- GC Adapter Menu-->
<string name="gc_adapter_rumble">Enable Vibration</string>

0 comments on commit adfb8d1

Please sign in to comment.
You can’t perform that action at this time.