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.
This commit is contained in:
parent
a548489aaf
commit
4d838212e2
|
@ -24,6 +24,7 @@ import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
import android.view.Surface;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
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_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_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5,
|
||||||
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
|
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
|
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_ACTION_RESET_OVERLAY = 26;
|
||||||
public static final int MENU_SET_IR_SENSITIVITY = 27;
|
public static final int MENU_SET_IR_SENSITIVITY = 27;
|
||||||
public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
|
public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
|
||||||
|
public static final int MENU_ACTION_SCREEN_ORIENTATION = 29;
|
||||||
|
|
||||||
|
|
||||||
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
|
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
|
||||||
|
@ -178,6 +181,8 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
EmulationActivity.MENU_SET_IR_SENSITIVITY);
|
EmulationActivity.MENU_SET_IR_SENSITIVITY);
|
||||||
buttonsActionsMap.append(R.id.menu_emulation_choose_doubletap,
|
buttonsActionsMap.append(R.id.menu_emulation_choose_doubletap,
|
||||||
EmulationActivity.MENU_ACTION_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)
|
private static String[] scanForSecondDisc(GameFile gameFile)
|
||||||
|
@ -253,9 +258,13 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
restoreState(savedInstanceState);
|
restoreState(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
mSettings = new Settings();
|
mSettings = new Settings();
|
||||||
mSettings.loadSettings(null);
|
mSettings.loadSettings(null);
|
||||||
|
|
||||||
|
updateOrientation();
|
||||||
|
|
||||||
// TODO: The accurate way to find out which console we're emulating is to
|
// 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
|
// first launch emulation and then ask the core which console we're emulating
|
||||||
sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE;
|
sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE;
|
||||||
|
@ -297,17 +306,6 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
|
|
||||||
setContentView(R.layout.activity_emulation);
|
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
|
// Find or create the EmulationFragment
|
||||||
mEmulationFragment = (EmulationFragment) getSupportFragmentManager()
|
mEmulationFragment = (EmulationFragment) getSupportFragmentManager()
|
||||||
.findFragmentById(R.id.frame_emulation_fragment);
|
.findFragmentById(R.id.frame_emulation_fragment);
|
||||||
|
@ -323,9 +321,6 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
{
|
{
|
||||||
setTitle(mSelectedTitle);
|
setTitle(mSelectedTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -431,6 +426,12 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
View.SYSTEM_UI_FLAG_IMMERSIVE);
|
View.SYSTEM_UI_FLAG_IMMERSIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateOrientation()
|
||||||
|
{
|
||||||
|
setRequestedOrientation(mPreferences.getInt("emulationActivityOrientation",
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE));
|
||||||
|
}
|
||||||
|
|
||||||
private void toggleMenu()
|
private void toggleMenu()
|
||||||
{
|
{
|
||||||
boolean result = getSupportFragmentManager().popBackStackImmediate(
|
boolean result = getSupportFragmentManager().popBackStackImmediate(
|
||||||
|
@ -646,6 +647,10 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
chooseDoubleTapButton();
|
chooseDoubleTapButton();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case MENU_ACTION_SCREEN_ORIENTATION:
|
||||||
|
chooseOrientation();
|
||||||
|
return;
|
||||||
|
|
||||||
case MENU_ACTION_EXIT:
|
case MENU_ACTION_EXIT:
|
||||||
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
|
// ATV menu is built using a fragment, this will pop that fragment before emulation ends.
|
||||||
if (TvUtil.isLeanback(getApplicationContext()))
|
if (TvUtil.isLeanback(getApplicationContext()))
|
||||||
|
@ -883,6 +888,37 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
alertDialog.show();
|
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()
|
private void setIRSensitivity()
|
||||||
{
|
{
|
||||||
int ir_pitch = Integer.valueOf(
|
int ir_pitch = Integer.valueOf(
|
||||||
|
|
|
@ -224,7 +224,6 @@ public final class SettingsFragmentPresenter
|
||||||
Setting autoDiscChange = null;
|
Setting autoDiscChange = null;
|
||||||
Setting analytics = null;
|
Setting analytics = null;
|
||||||
Setting enableSaveState;
|
Setting enableSaveState;
|
||||||
Setting lockToLandscape;
|
|
||||||
|
|
||||||
SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE);
|
SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE);
|
||||||
SettingSection analyticsSection = mSettings.getSection(Settings.SECTION_ANALYTICS);
|
SettingSection analyticsSection = mSettings.getSection(Settings.SECTION_ANALYTICS);
|
||||||
|
@ -238,7 +237,6 @@ public final class SettingsFragmentPresenter
|
||||||
autoDiscChange = coreSection.getSetting(SettingsFile.KEY_AUTO_DISC_CHANGE);
|
autoDiscChange = coreSection.getSetting(SettingsFile.KEY_AUTO_DISC_CHANGE);
|
||||||
analytics = analyticsSection.getSetting(SettingsFile.KEY_ANALYTICS_ENABLED);
|
analytics = analyticsSection.getSetting(SettingsFile.KEY_ANALYTICS_ENABLED);
|
||||||
enableSaveState = coreSection.getSetting(SettingsFile.KEY_ENABLE_SAVE_STATES);
|
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.
|
// TODO: Having different emuCoresEntries/emuCoresValues for each architecture is annoying.
|
||||||
// The proper solution would be to have one emuCoresEntries and one emuCoresValues
|
// 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,
|
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,
|
R.string.enable_save_states, R.string.enable_save_states_description, false,
|
||||||
enableSaveState));
|
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,
|
sl.add(new CheckBoxSetting(SettingsFile.KEY_ANALYTICS_ENABLED, Settings.SECTION_ANALYTICS,
|
||||||
R.string.analytics, 0, false, analytics));
|
R.string.analytics, 0, false, analytics));
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ public final class SettingsFile
|
||||||
public static final String KEY_SLOT_A_DEVICE = "SlotA";
|
public static final String KEY_SLOT_A_DEVICE = "SlotA";
|
||||||
public static final String KEY_SLOT_B_DEVICE = "SlotB";
|
public static final String KEY_SLOT_B_DEVICE = "SlotB";
|
||||||
public static final String KEY_ENABLE_SAVE_STATES = "EnableSaveStates";
|
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_ENABLED = "Enabled";
|
||||||
public static final String KEY_ANALYTICS_PERMISSION_ASKED = "PermissionAsked";
|
public static final String KEY_ANALYTICS_PERMISSION_ASKED = "PermissionAsked";
|
||||||
|
|
|
@ -113,6 +113,11 @@
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_screen_orientation"
|
||||||
|
app:showAsAction="never"
|
||||||
|
android:title="@string/emulation_screen_orientation"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_change_disc"
|
android:id="@+id/menu_change_disc"
|
||||||
app:showAsAction="never"
|
app:showAsAction="never"
|
||||||
|
|
|
@ -133,6 +133,11 @@
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_screen_orientation"
|
||||||
|
app:showAsAction="never"
|
||||||
|
android:title="@string/emulation_screen_orientation"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_change_disc"
|
android:id="@+id/menu_change_disc"
|
||||||
app:showAsAction="never"
|
app:showAsAction="never"
|
||||||
|
|
|
@ -348,4 +348,15 @@
|
||||||
<item>Wii Controller Settings</item>
|
<item>Wii Controller Settings</item>
|
||||||
<item>Clear Game Settings</item>
|
<item>Clear Game Settings</item>
|
||||||
</string-array>
|
</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>
|
</resources>
|
||||||
|
|
|
@ -313,6 +313,7 @@
|
||||||
<string name="emulation_ir_group">Touch IR Pointer</string>
|
<string name="emulation_ir_group">Touch IR Pointer</string>
|
||||||
<string name="emulation_ir_sensitivity">IR Sensitivity</string>
|
<string name="emulation_ir_sensitivity">IR Sensitivity</string>
|
||||||
<string name="emulation_choose_doubletap">Double tap button</string>
|
<string name="emulation_choose_doubletap">Double tap button</string>
|
||||||
|
<string name="emulation_screen_orientation">Screen Orientation</string>
|
||||||
|
|
||||||
<!-- GC Adapter Menu-->
|
<!-- GC Adapter Menu-->
|
||||||
<string name="gc_adapter_rumble">Enable Vibration</string>
|
<string name="gc_adapter_rumble">Enable Vibration</string>
|
||||||
|
|
Loading…
Reference in New Issue