android: frontend: Add persistent changeable layout option for landscape mode.
This commit is contained in:
parent
b29f352ac6
commit
4914250177
@ -275,15 +275,10 @@ public final class NativeLibrary {
|
||||
*/
|
||||
private static native void CacheClassesAndMethods();
|
||||
|
||||
/**
|
||||
* Switches the screen layout.
|
||||
*/
|
||||
public static native void SwitchScreenLayout(boolean is_portrait_mode);
|
||||
|
||||
/**
|
||||
* Notifies the core emulation that the orientation has changed.
|
||||
*/
|
||||
public static native void NotifyOrientationChange(boolean is_portrait_mode);
|
||||
public static native void NotifyOrientationChange(int layout_option, boolean is_portrait_mode);
|
||||
|
||||
/**
|
||||
* Swaps the top and bottom screens.
|
||||
|
@ -57,9 +57,12 @@ public final class EmulationActivity extends AppCompatActivity {
|
||||
public static final int MENU_ACTION_ADJUST_SCALE = 2;
|
||||
public static final int MENU_ACTION_EXIT = 3;
|
||||
public static final int MENU_ACTION_TOGGLE_PREF_STATS = 4;
|
||||
public static final int MENU_ACTION_SWITCH_SCREEN_LAYOUT = 5;
|
||||
public static final int MENU_ACTION_SWAP_SCREENS = 6;
|
||||
public static final int MENU_ACTION_RESET_OVERLAY = 7;
|
||||
public static final int MENU_ACTION_SCREEN_LAYOUT_LANDSCAPE = 5;
|
||||
public static final int MENU_ACTION_SCREEN_LAYOUT_PORTRAIT = 6;
|
||||
public static final int MENU_ACTION_SCREEN_LAYOUT_SINGLE = 7;
|
||||
public static final int MENU_ACTION_SCREEN_LAYOUT_SIDEBYSIDE = 8;
|
||||
public static final int MENU_ACTION_SWAP_SCREENS = 9;
|
||||
public static final int MENU_ACTION_RESET_OVERLAY = 10;
|
||||
private static final String BACKSTACK_NAME_MENU = "menu";
|
||||
private static final String BACKSTACK_NAME_SUBMENU = "submenu";
|
||||
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
|
||||
@ -74,8 +77,14 @@ public final class EmulationActivity extends AppCompatActivity {
|
||||
buttonsActionsMap.append(R.id.menu_emulation_toggle_perf_stats,
|
||||
EmulationActivity.MENU_ACTION_TOGGLE_PREF_STATS);
|
||||
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
|
||||
buttonsActionsMap.append(R.id.menu_emulation_switch_screen_layout,
|
||||
EmulationActivity.MENU_ACTION_SWITCH_SCREEN_LAYOUT);
|
||||
buttonsActionsMap.append(R.id.menu_screen_layout_landscape,
|
||||
EmulationActivity.MENU_ACTION_SCREEN_LAYOUT_LANDSCAPE);
|
||||
buttonsActionsMap.append(R.id.menu_screen_layout_portrait,
|
||||
EmulationActivity.MENU_ACTION_SCREEN_LAYOUT_PORTRAIT);
|
||||
buttonsActionsMap.append(R.id.menu_screen_layout_single,
|
||||
EmulationActivity.MENU_ACTION_SCREEN_LAYOUT_SINGLE);
|
||||
buttonsActionsMap.append(R.id.menu_screen_layout_sidebyside,
|
||||
EmulationActivity.MENU_ACTION_SCREEN_LAYOUT_SIDEBYSIDE);
|
||||
buttonsActionsMap.append(R.id.menu_emulation_swap_screens,
|
||||
EmulationActivity.MENU_ACTION_SWAP_SCREENS);
|
||||
buttonsActionsMap
|
||||
@ -214,7 +223,6 @@ public final class EmulationActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -326,10 +334,38 @@ public final class EmulationActivity extends AppCompatActivity {
|
||||
.withEndAction(afterShowingScreenshot);
|
||||
}
|
||||
|
||||
// These must match what is defined in src/core/settings.h
|
||||
private static final int LayoutOption_Default = 0;
|
||||
private static final int LayoutOption_SingleScreen = 1;
|
||||
private static final int LayoutOption_LargeScreen = 2;
|
||||
private static final int LayoutOption_SideScreen = 3;
|
||||
private static final int LayoutOption_MobilePortrait = 4;
|
||||
private static final int LayoutOption_MobileLandscape = 5;
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_emulation, menu);
|
||||
|
||||
|
||||
// mPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
int layoutOption = mPreferences.getInt("LandscapeScreenLayout", LayoutOption_MobileLandscape);
|
||||
|
||||
int menuItemId = R.id.menu_screen_layout_landscape;
|
||||
switch (layoutOption) {
|
||||
case LayoutOption_SingleScreen:
|
||||
menuItemId = R.id.menu_screen_layout_single;
|
||||
break;
|
||||
case LayoutOption_SideScreen:
|
||||
menuItemId = R.id.menu_screen_layout_sidebyside;
|
||||
break;
|
||||
case LayoutOption_MobilePortrait:
|
||||
menuItemId = R.id.menu_screen_layout_portrait;
|
||||
break;
|
||||
}
|
||||
|
||||
menu.findItem(menuItemId).setChecked(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -337,14 +373,8 @@ public final class EmulationActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int action = buttonsActionsMap.get(item.getItemId(), -1);
|
||||
if (action >= 0) {
|
||||
handleMenuAction(action);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void handleMenuAction(@MenuAction int menuAction) {
|
||||
switch (menuAction) {
|
||||
switch (action) {
|
||||
// Edit the placement of the controls
|
||||
case MENU_ACTION_EDIT_CONTROLS_PLACEMENT:
|
||||
editControlsPlacement();
|
||||
@ -353,27 +383,42 @@ public final class EmulationActivity extends AppCompatActivity {
|
||||
// Enable/Disable specific buttons or the entire input overlay.
|
||||
case MENU_ACTION_TOGGLE_CONTROLS:
|
||||
toggleControls();
|
||||
return;
|
||||
break;
|
||||
|
||||
// Adjust the scale of the overlay controls.
|
||||
case MENU_ACTION_ADJUST_SCALE:
|
||||
adjustScale();
|
||||
return;
|
||||
break;
|
||||
|
||||
// Toggle the visibility of the Performance stats TextView
|
||||
case MENU_ACTION_TOGGLE_PREF_STATS:
|
||||
mEmulationFragment.togglePerfStatsVisibility();
|
||||
return;
|
||||
break;
|
||||
|
||||
// Switch the layout of the screens
|
||||
case MENU_ACTION_SWITCH_SCREEN_LAYOUT:
|
||||
NativeLibrary.SwitchScreenLayout(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
|
||||
return;
|
||||
// Sets the screen layout to Landscape
|
||||
case MENU_ACTION_SCREEN_LAYOUT_LANDSCAPE:
|
||||
changeScreenOrientation(LayoutOption_MobileLandscape, item);
|
||||
break;
|
||||
|
||||
// Sets the screen layout to Portrait
|
||||
case MENU_ACTION_SCREEN_LAYOUT_PORTRAIT:
|
||||
changeScreenOrientation(LayoutOption_MobilePortrait, item);
|
||||
break;
|
||||
|
||||
// Sets the screen layout to Single
|
||||
case MENU_ACTION_SCREEN_LAYOUT_SINGLE:
|
||||
changeScreenOrientation(LayoutOption_SingleScreen, item);
|
||||
break;
|
||||
|
||||
// Sets the screen layout to Side by Side
|
||||
case MENU_ACTION_SCREEN_LAYOUT_SIDEBYSIDE:
|
||||
changeScreenOrientation(LayoutOption_SideScreen, item);
|
||||
break;
|
||||
|
||||
// Swap the top and bottom screen locations
|
||||
case MENU_ACTION_SWAP_SCREENS:
|
||||
NativeLibrary.SwapScreens(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
|
||||
return;
|
||||
break;
|
||||
|
||||
// Reset overlay placement
|
||||
case MENU_ACTION_RESET_OVERLAY:
|
||||
@ -384,8 +429,21 @@ public final class EmulationActivity extends AppCompatActivity {
|
||||
toggleMenu(); // Hide the menu (it will be showing since we just clicked it)
|
||||
mEmulationFragment.stopEmulation();
|
||||
exitWithAnimation();
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void changeScreenOrientation(int layoutOption, MenuItem item) {
|
||||
item.setChecked(true);
|
||||
|
||||
NativeLibrary.NotifyOrientationChange(layoutOption,
|
||||
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
|
||||
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt("LandscapeScreenLayout", layoutOption);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private void editControlsPlacement() {
|
||||
@ -560,7 +618,8 @@ public final class EmulationActivity extends AppCompatActivity {
|
||||
|
||||
@Retention(SOURCE)
|
||||
@IntDef({MENU_ACTION_EDIT_CONTROLS_PLACEMENT, MENU_ACTION_TOGGLE_CONTROLS, MENU_ACTION_ADJUST_SCALE,
|
||||
MENU_ACTION_EXIT, MENU_ACTION_TOGGLE_PREF_STATS, MENU_ACTION_SWITCH_SCREEN_LAYOUT,
|
||||
MENU_ACTION_EXIT, MENU_ACTION_TOGGLE_PREF_STATS, MENU_ACTION_SCREEN_LAYOUT_LANDSCAPE,
|
||||
MENU_ACTION_SCREEN_LAYOUT_PORTRAIT, MENU_ACTION_SCREEN_LAYOUT_SINGLE, MENU_ACTION_SCREEN_LAYOUT_SIDEBYSIDE,
|
||||
MENU_ACTION_SWAP_SCREENS, MENU_ACTION_RESET_OVERLAY})
|
||||
public @interface MenuAction {
|
||||
}
|
||||
|
@ -22,8 +22,14 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
||||
buttonsActionsMap.append(R.id.menu_emulation_toggle_perf_stats,
|
||||
EmulationActivity.MENU_ACTION_TOGGLE_PREF_STATS);
|
||||
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
|
||||
buttonsActionsMap.append(R.id.menu_emulation_switch_screen_layout,
|
||||
EmulationActivity.MENU_ACTION_SWITCH_SCREEN_LAYOUT);
|
||||
buttonsActionsMap.append(R.id.menu_screen_layout_landscape,
|
||||
EmulationActivity.MENU_ACTION_SCREEN_LAYOUT_LANDSCAPE);
|
||||
buttonsActionsMap.append(R.id.menu_screen_layout_portrait,
|
||||
EmulationActivity.MENU_ACTION_SCREEN_LAYOUT_PORTRAIT);
|
||||
buttonsActionsMap.append(R.id.menu_screen_layout_single,
|
||||
EmulationActivity.MENU_ACTION_SCREEN_LAYOUT_SINGLE);
|
||||
buttonsActionsMap.append(R.id.menu_screen_layout_sidebyside,
|
||||
EmulationActivity.MENU_ACTION_SCREEN_LAYOUT_SIDEBYSIDE);
|
||||
buttonsActionsMap.append(R.id.menu_emulation_swap_screens,
|
||||
EmulationActivity.MENU_ACTION_SWAP_SCREENS);
|
||||
}
|
||||
@ -62,9 +68,5 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
||||
@SuppressWarnings("WrongConstant")
|
||||
@Override
|
||||
public void onClick(View button) {
|
||||
int action = buttonsActionsMap.get(button.getId());
|
||||
if (action >= 0) {
|
||||
((EmulationActivity) getActivity()).handleMenuAction(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -344,7 +344,14 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
|
||||
joystick.draw(canvas);
|
||||
}
|
||||
|
||||
NativeLibrary.NotifyOrientationChange(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
|
||||
// This is a convenient place to handle changes to orientation
|
||||
HandleOrientationChange();
|
||||
}
|
||||
|
||||
private void HandleOrientationChange() {
|
||||
final int layoutOption = mPreferences.getInt("LandscapeScreenLayout",5 /*LayoutOption_MobileLandscape*/);
|
||||
final boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
|
||||
NativeLibrary.NotifyOrientationChange(layoutOption, isPortrait);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -192,24 +192,9 @@ void Java_org_citra_citra_1android_NativeLibrary_CacheClassesAndMethods(JNIEnv*
|
||||
"(Ljava/lang/String;Ljava/lang/String;Z)Z");
|
||||
}
|
||||
|
||||
void Java_org_citra_citra_1android_NativeLibrary_SwitchScreenLayout(JNIEnv* env, jobject obj,
|
||||
jboolean is_portrait_mode) {
|
||||
if (Settings::values.layout_option == Settings::LayoutOption::MobilePortrait) {
|
||||
Settings::values.layout_option = Settings::LayoutOption::MobileLandscape;
|
||||
} else if (Settings::values.layout_option == Settings::LayoutOption::MobileLandscape) {
|
||||
Settings::values.layout_option = Settings::LayoutOption::SingleScreen;
|
||||
} else if (Settings::values.layout_option == Settings::LayoutOption::SingleScreen) {
|
||||
Settings::values.layout_option = Settings::LayoutOption::LargeScreen;
|
||||
} else if (Settings::values.layout_option == Settings::LayoutOption::LargeScreen) {
|
||||
Settings::values.layout_option = Settings::LayoutOption::SideScreen;
|
||||
} else {
|
||||
Settings::values.layout_option = Settings::LayoutOption::MobilePortrait;
|
||||
}
|
||||
VideoCore::g_renderer->UpdateCurrentFramebufferLayout(is_portrait_mode);
|
||||
}
|
||||
|
||||
void Java_org_citra_citra_1android_NativeLibrary_NotifyOrientationChange(
|
||||
JNIEnv* env, jobject obj, jboolean is_portrait_mode) {
|
||||
JNIEnv* env, jobject obj, jint layout_option, jboolean is_portrait_mode) {
|
||||
Settings::values.layout_option = static_cast<Settings::LayoutOption>(layout_option);
|
||||
VideoCore::g_renderer->UpdateCurrentFramebufferLayout(is_portrait_mode);
|
||||
}
|
||||
|
||||
|
@ -139,11 +139,8 @@ JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_WriteProfileR
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_citra_citra_1android_NativeLibrary_CacheClassesAndMethods(JNIEnv* env, jobject obj);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_SwitchScreenLayout(
|
||||
JNIEnv* env, jobject obj, jboolean is_portrait_mode);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_NotifyOrientationChange(
|
||||
JNIEnv* env, jobject obj, jboolean is_portrait_mode);
|
||||
JNIEnv* env, jobject obj, jint layout_option, jboolean is_portrait_mode);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_SwapScreens(
|
||||
JNIEnv* env, jobject obj, jboolean is_portrait_mode);
|
||||
|
@ -33,7 +33,27 @@
|
||||
<item
|
||||
android:id="@+id/menu_emulation_switch_screen_layout"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/emulation_switch_screen_layout"/>
|
||||
android:title="@string/emulation_switch_screen_layout">
|
||||
<menu>
|
||||
<group android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/menu_screen_layout_landscape"
|
||||
android:title="@string/emulation_screen_layout_landscape"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_screen_layout_portrait"
|
||||
android:title="@string/emulation_screen_layout_portrait"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_screen_layout_single"
|
||||
android:title="@string/emulation_screen_layout_single"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_screen_layout_sidebyside"
|
||||
android:title="@string/emulation_screen_layout_sidebyside"/>
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_emulation_swap_screens"
|
||||
|
@ -153,7 +153,11 @@
|
||||
<string name="emulation_control_scale">Adjust Scale</string>
|
||||
<string name="emulation_choose_controller">Choose Controller</string>
|
||||
<string name="emulation_controller_changed">You may have to reload the game after changing extensions.</string>
|
||||
<string name="emulation_switch_screen_layout">Switch Screen Layout</string>
|
||||
<string name="emulation_switch_screen_layout">Landscape Screen Layout</string>
|
||||
<string name="emulation_screen_layout_landscape">Default</string>
|
||||
<string name="emulation_screen_layout_portrait">Portrait</string>
|
||||
<string name="emulation_screen_layout_single">Single Screen</string>
|
||||
<string name="emulation_screen_layout_sidebyside">Side by Side Screens</string>
|
||||
<string name="emulation_swap_screens">Swap Screens</string>
|
||||
<string name="emulation_touch_overlay_reset">Reset Overlay</string>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user