Android: Port over settings from the old menu

This commit is contained in:
JosJuice 2020-08-04 15:22:59 +02:00
parent 364b9702f4
commit 36a3b54c1f
7 changed files with 139 additions and 368 deletions

View File

@ -26,6 +26,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
@ -103,7 +104,7 @@ public final class EmulationActivity extends AppCompatActivity
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_MOTION_CONTROLS, MENU_ACTION_PAUSE_EMULATION,
MENU_ACTION_UNPAUSE_EMULATION})
MENU_ACTION_UNPAUSE_EMULATION, MENU_ACTION_OVERLAY_CONTROLS})
public @interface MenuAction
{
}
@ -141,7 +142,7 @@ public final class EmulationActivity extends AppCompatActivity
public static final int MENU_ACTION_MOTION_CONTROLS = 30;
public static final int MENU_ACTION_PAUSE_EMULATION = 31;
public static final int MENU_ACTION_UNPAUSE_EMULATION = 32;
public static final int MENU_ACTION_OVERLAY_CONTROLS = 33;
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
@ -155,33 +156,6 @@ public final class EmulationActivity extends AppCompatActivity
.append(R.id.menu_emulation_adjust_scale, EmulationActivity.MENU_ACTION_ADJUST_SCALE);
buttonsActionsMap.append(R.id.menu_emulation_choose_controller,
EmulationActivity.MENU_ACTION_CHOOSE_CONTROLLER);
buttonsActionsMap
.append(R.id.menu_refresh_wiimotes, EmulationActivity.MENU_ACTION_REFRESH_WIIMOTES);
buttonsActionsMap
.append(R.id.menu_emulation_pause, EmulationActivity.MENU_ACTION_PAUSE_EMULATION);
buttonsActionsMap
.append(R.id.menu_emulation_unpause, EmulationActivity.MENU_ACTION_UNPAUSE_EMULATION);
buttonsActionsMap
.append(R.id.menu_emulation_screenshot, EmulationActivity.MENU_ACTION_TAKE_SCREENSHOT);
buttonsActionsMap.append(R.id.menu_quicksave, EmulationActivity.MENU_ACTION_QUICK_SAVE);
buttonsActionsMap.append(R.id.menu_quickload, EmulationActivity.MENU_ACTION_QUICK_LOAD);
buttonsActionsMap
.append(R.id.menu_emulation_save_root, EmulationActivity.MENU_ACTION_SAVE_ROOT);
buttonsActionsMap
.append(R.id.menu_emulation_load_root, EmulationActivity.MENU_ACTION_LOAD_ROOT);
buttonsActionsMap.append(R.id.menu_emulation_save_1, EmulationActivity.MENU_ACTION_SAVE_SLOT1);
buttonsActionsMap.append(R.id.menu_emulation_save_2, EmulationActivity.MENU_ACTION_SAVE_SLOT2);
buttonsActionsMap.append(R.id.menu_emulation_save_3, EmulationActivity.MENU_ACTION_SAVE_SLOT3);
buttonsActionsMap.append(R.id.menu_emulation_save_4, EmulationActivity.MENU_ACTION_SAVE_SLOT4);
buttonsActionsMap.append(R.id.menu_emulation_save_5, EmulationActivity.MENU_ACTION_SAVE_SLOT5);
buttonsActionsMap.append(R.id.menu_emulation_load_1, EmulationActivity.MENU_ACTION_LOAD_SLOT1);
buttonsActionsMap.append(R.id.menu_emulation_load_2, EmulationActivity.MENU_ACTION_LOAD_SLOT2);
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_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,
EmulationActivity.MENU_ACTION_JOYSTICK_REL_CENTER);
buttonsActionsMap.append(R.id.menu_emulation_rumble, EmulationActivity.MENU_ACTION_RUMBLE);
@ -191,8 +165,6 @@ 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);
buttonsActionsMap.append(R.id.menu_emulation_motion_controls,
EmulationActivity.MENU_ACTION_MOTION_CONTROLS);
}
@ -470,35 +442,13 @@ public final class EmulationActivity extends AppCompatActivity
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
public void showOverlayControlsMenu(@NonNull View anchor)
{
// Inflate the menu; this adds items to the action bar if it is present.
if (sIsGameCubeGame)
{
getMenuInflater().inflate(R.menu.menu_emulation, menu);
}
else
{
getMenuInflater().inflate(R.menu.menu_emulation_wii, menu);
}
PopupMenu popup = new PopupMenu(this, anchor);
Menu menu = popup.getMenu();
mPauseEmulationButton = menu.findItem(R.id.menu_emulation_pause);
mUnpauseEmulationButton = menu.findItem(R.id.menu_emulation_unpause);
if (sUserPausedEmulation)
{
showUnpauseEmulationButton();
}
if (mSettings.getSection(SettingsFile.FILE_NAME_DOLPHIN, Settings.SECTION_INI_CORE)
.getBoolean(SettingsFile.KEY_ENABLE_SAVE_STATES, false))
{
menu.findItem(R.id.menu_quicksave).setVisible(true);
menu.findItem(R.id.menu_quickload).setVisible(true);
menu.findItem(R.id.menu_emulation_save_root).setVisible(true);
menu.findItem(R.id.menu_emulation_load_root).setVisible(true);
}
int id = sIsGameCubeGame ? R.menu.menu_overlay_controls_gc : R.menu.menu_overlay_controls_wii;
popup.getMenuInflater().inflate(id, menu);
// Populate the checkbox value for joystick center on touch
menu.findItem(R.id.menu_emulation_joystick_rel_center)
@ -506,7 +456,9 @@ public final class EmulationActivity extends AppCompatActivity
menu.findItem(R.id.menu_emulation_rumble)
.setChecked(mPreferences.getBoolean("phoneRumble", true));
return true;
popup.setOnMenuItemClickListener(this::onOptionsItemSelected);
popup.show();
}
@SuppressWarnings("WrongConstant")
@ -735,6 +687,8 @@ public final class EmulationActivity extends AppCompatActivity
}
else
{
closeSubmenu();
closeMenu();
mEmulationFragment.startConfiguringControls();
}
}

View File

@ -1,5 +1,6 @@
package org.dolphinemu.dolphinemu.fragments;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
@ -19,8 +20,10 @@ import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
public final class MenuFragment extends Fragment implements View.OnClickListener
{
private TextView mTitleText;
private View mPauseEmulation;
private View mUnpauseEmulation;
private static final String KEY_TITLE = "title";
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
@ -38,8 +41,12 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
.append(R.id.menu_emulation_save_root, EmulationActivity.MENU_ACTION_SAVE_ROOT);
buttonsActionsMap
.append(R.id.menu_emulation_load_root, EmulationActivity.MENU_ACTION_LOAD_ROOT);
buttonsActionsMap
.append(R.id.menu_overlay_controls, EmulationActivity.MENU_ACTION_OVERLAY_CONTROLS);
buttonsActionsMap
.append(R.id.menu_refresh_wiimotes, EmulationActivity.MENU_ACTION_REFRESH_WIIMOTES);
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);
}
@ -82,6 +89,21 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
options.findViewById(R.id.menu_emulation_load_root).setVisibility(View.VISIBLE);
}
PackageManager packageManager = requireActivity().getPackageManager();
if (!packageManager.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN))
{
options.findViewById(R.id.menu_overlay_controls).setVisibility(View.GONE);
}
// Old devices which support both portrait and landscape may report support for neither,
// so we only hide the orientation button if the device only supports one orientation
if (packageManager.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT) !=
packageManager.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE))
{
options.findViewById(R.id.menu_screen_orientation).setVisibility(View.GONE);
}
for (int childIndex = 0; childIndex < options.getChildCount(); childIndex++)
{
Button button = (Button) options.getChildAt(childIndex);
@ -89,11 +111,11 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
button.setOnClickListener(this);
}
TextView titleText = rootView.findViewById(R.id.text_game_title);
mTitleText = rootView.findViewById(R.id.text_game_title);
String title = getArguments().getString(KEY_TITLE);
if (title != null)
{
titleText.setText(title);
mTitleText.setText(title);
}
return rootView;
@ -116,6 +138,8 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
public void onClick(View button)
{
int action = buttonsActionsMap.get(button.getId());
EmulationActivity activity = (EmulationActivity) requireActivity();
if (action == EmulationActivity.MENU_ACTION_PAUSE_EMULATION)
{
EmulationActivity.setHasUserPausedEmulation(true);
@ -128,9 +152,15 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
NativeLibrary.UnPauseEmulation();
showPauseEmulationButton();
}
else if (action == EmulationActivity.MENU_ACTION_OVERLAY_CONTROLS)
{
// We could use the button parameter as the anchor here, but this often results in a tiny menu
// (because the button often is in the middle of the screen), so let's use mTitleText instead
activity.showOverlayControlsMenu(mTitleText);
}
else if (action >= 0)
{
((EmulationActivity) getActivity()).handleMenuAction(action);
activity.handleMenuAction(action);
}
}
}

View File

@ -67,11 +67,21 @@
style="@style/InGameMenuOption"
android:visibility="gone"/>
<Button
android:id="@+id/menu_overlay_controls"
android:text="@string/emulation_overlay_controls"
style="@style/InGameMenuOption"/>
<Button
android:id="@+id/menu_refresh_wiimotes"
android:text="@string/emulation_refresh_wiimotes"
style="@style/InGameMenuOption"/>
<Button
android:id="@+id/menu_screen_orientation"
android:text="@string/emulation_screen_orientation"
style="@style/InGameMenuOption"/>
<Button
android:id="@+id/menu_change_disc"
android:text="@string/emulation_change_disc"

View File

@ -1,143 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity">
<item
android:id="@+id/menu_emulation_pause"
app:showAsAction="ifRoom"
android:icon="@drawable/lb_ic_pause"
android:title="@string/pause_emulation"/>
<item
android:id="@+id/menu_emulation_unpause"
app:showAsAction="ifRoom"
android:icon="@drawable/lb_ic_play"
android:title="@string/unpause_emulation"
android:visible="false"/>
<item
android:id="@+id/menu_emulation_screenshot"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_screenshot"
android:title="@string/emulation_screenshot"/>
<item
android:id="@+id/menu_quicksave"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_quicksave"
android:title="@string/emulation_quicksave"
android:visible="false"/>
<item
android:id="@+id/menu_quickload"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_quickload"
android:title="@string/emulation_quickload"
android:visible="false"/>
<!-- Save State Slots -->
<item
android:id="@+id/menu_emulation_save_root"
app:showAsAction="never"
android:title="@string/emulation_savestate"
android:visible="false">
<menu>
<item
android:id="@+id/menu_emulation_save_1"
android:title="@string/emulation_slot1"/>
<item
android:id="@+id/menu_emulation_save_2"
android:title="@string/emulation_slot2"/>
<item
android:id="@+id/menu_emulation_save_3"
android:title="@string/emulation_slot3"/>
<item
android:id="@+id/menu_emulation_save_4"
android:title="@string/emulation_slot4"/>
<item
android:id="@+id/menu_emulation_save_5"
android:title="@string/emulation_slot5"/>
</menu>
</item>
<!-- Load State Slots -->
<item
android:id="@+id/menu_emulation_load_root"
app:showAsAction="never"
android:title="@string/emulation_loadstate"
android:visible="false">
<menu>
<item
android:id="@+id/menu_emulation_load_1"
android:title="@string/emulation_slot1"/>
<item
android:id="@+id/menu_emulation_load_2"
android:title="@string/emulation_slot2"/>
<item
android:id="@+id/menu_emulation_load_3"
android:title="@string/emulation_slot3"/>
<item
android:id="@+id/menu_emulation_load_4"
android:title="@string/emulation_slot4"/>
<item
android:id="@+id/menu_emulation_load_5"
android:title="@string/emulation_slot5"/>
</menu>
</item>
<item
android:id="@+id/menu_emulation_overlay_controls"
app:showAsAction="never"
android:title="@string/emulation_overlay_controls">
<menu>
<item
android:id="@+id/menu_emulation_edit_layout"
android:title="@string/emulation_edit_layout"/>
<item
android:id="@+id/menu_emulation_toggle_controls"
android:title="@string/emulation_toggle_controls"/>
<item
android:id="@+id/menu_emulation_adjust_scale"
android:title="@string/emulation_control_scale"/>
<item
android:id="@+id/menu_emulation_joystick_rel_center"
android:checkable="true"
android:title="@string/emulation_control_joystick_rel_center"/>
<item
android:id="@+id/menu_emulation_rumble"
android:checkable="true"
android:title="@string/emulation_control_rumble"/>
<item
android:id="@+id/menu_emulation_reset_overlay"
android:title="@string/emulation_touch_overlay_reset"/>
</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"
android:title="@string/emulation_change_disc"/>
<item
android:id="@+id/menu_exit"
app:showAsAction="never"
android:title="@string/emulation_exit"/>
</menu>

View File

@ -1,163 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity">
<item
android:id="@+id/menu_emulation_pause"
app:showAsAction="ifRoom"
android:icon="@drawable/lb_ic_pause"
android:title="@string/pause_emulation"/>
<item
android:id="@+id/menu_emulation_unpause"
app:showAsAction="ifRoom"
android:icon="@drawable/lb_ic_play"
android:title="@string/unpause_emulation"
android:visible="false"/>
<item
android:id="@+id/menu_emulation_screenshot"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_screenshot"
android:title="@string/emulation_screenshot"/>
<item
android:id="@+id/menu_quicksave"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_quicksave"
android:title="@string/emulation_quicksave"
android:visible="false"/>
<item
android:id="@+id/menu_quickload"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_quickload"
android:title="@string/emulation_quickload"
android:visible="false"/>
<!-- Save State Slots -->
<item
android:id="@+id/menu_emulation_save_root"
app:showAsAction="never"
android:title="@string/emulation_savestate"
android:visible="false">
<menu>
<item
android:id="@+id/menu_emulation_save_1"
android:title="@string/emulation_slot1"/>
<item
android:id="@+id/menu_emulation_save_2"
android:title="@string/emulation_slot2"/>
<item
android:id="@+id/menu_emulation_save_3"
android:title="@string/emulation_slot3"/>
<item
android:id="@+id/menu_emulation_save_4"
android:title="@string/emulation_slot4"/>
<item
android:id="@+id/menu_emulation_save_5"
android:title="@string/emulation_slot5"/>
</menu>
</item>
<!-- Load State Slots -->
<item
android:id="@+id/menu_emulation_load_root"
app:showAsAction="never"
android:title="@string/emulation_loadstate"
android:visible="false">
<menu>
<item
android:id="@+id/menu_emulation_load_1"
android:title="@string/emulation_slot1"/>
<item
android:id="@+id/menu_emulation_load_2"
android:title="@string/emulation_slot2"/>
<item
android:id="@+id/menu_emulation_load_3"
android:title="@string/emulation_slot3"/>
<item
android:id="@+id/menu_emulation_load_4"
android:title="@string/emulation_slot4"/>
<item
android:id="@+id/menu_emulation_load_5"
android:title="@string/emulation_slot5"/>
</menu>
</item>
<item
android:id="@+id/menu_emulation_overlay_controls"
app:showAsAction="never"
android:title="@string/emulation_overlay_controls">
<menu>
<item
android:id="@+id/menu_emulation_edit_layout"
android:title="@string/emulation_edit_layout"/>
<item
android:id="@+id/menu_emulation_toggle_controls"
android:title="@string/emulation_toggle_controls"/>
<item
android:id="@+id/menu_emulation_adjust_scale"
android:title="@string/emulation_control_scale"/>
<group android:checkableBehavior="all">
<item
android:id="@+id/menu_emulation_joystick_rel_center"
android:checkable="true"
android:title="@string/emulation_control_joystick_rel_center"/>
<item
android:id="@+id/menu_emulation_rumble"
android:checkable="true"
android:title="@string/emulation_control_rumble"/>
</group>
<item
android:id="@+id/menu_emulation_choose_controller"
android:title="@string/emulation_choose_controller"/>
<item
android:id="@+id/menu_emulation_motion_controls"
android:title="@string/emulation_motion_controls"/>
<item
android:id="@+id/menu_emulation_ir_group"
android:title="@string/emulation_ir_group"
app:showAsAction="never">
<menu>
<item
android:id="@+id/menu_emulation_set_ir_sensitivity"
android:title="@string/emulation_ir_sensitivity"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_emulation_choose_doubletap"
android:title="@string/emulation_choose_doubletap"
app:showAsAction="ifRoom"/>
</menu>
</item>
<item
android:id="@+id/menu_emulation_reset_overlay"
android:title="@string/emulation_touch_overlay_reset"/>
</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"
android:title="@string/emulation_change_disc"/>
</menu>

View File

@ -0,0 +1,30 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity">
<item
android:id="@+id/menu_emulation_edit_layout"
android:title="@string/emulation_edit_layout"/>
<item
android:id="@+id/menu_emulation_toggle_controls"
android:title="@string/emulation_toggle_controls"/>
<item
android:id="@+id/menu_emulation_adjust_scale"
android:title="@string/emulation_control_scale"/>
<item
android:id="@+id/menu_emulation_joystick_rel_center"
android:checkable="true"
android:title="@string/emulation_control_joystick_rel_center"/>
<item
android:id="@+id/menu_emulation_rumble"
android:checkable="true"
android:title="@string/emulation_control_rumble"/>
<item
android:id="@+id/menu_emulation_reset_overlay"
android:title="@string/emulation_touch_overlay_reset"/>
</menu>

View File

@ -0,0 +1,53 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity">
<item
android:id="@+id/menu_emulation_edit_layout"
android:title="@string/emulation_edit_layout"/>
<item
android:id="@+id/menu_emulation_toggle_controls"
android:title="@string/emulation_toggle_controls"/>
<item
android:id="@+id/menu_emulation_adjust_scale"
android:title="@string/emulation_control_scale"/>
<group android:checkableBehavior="all">
<item
android:id="@+id/menu_emulation_joystick_rel_center"
android:checkable="true"
android:title="@string/emulation_control_joystick_rel_center"/>
<item
android:id="@+id/menu_emulation_rumble"
android:checkable="true"
android:title="@string/emulation_control_rumble"/>
</group>
<item
android:id="@+id/menu_emulation_choose_controller"
android:title="@string/emulation_choose_controller"/>
<item
android:id="@+id/menu_emulation_motion_controls"
android:title="@string/emulation_motion_controls"/>
<item
android:id="@+id/menu_emulation_ir_group"
android:title="@string/emulation_ir_group">
<menu>
<item
android:id="@+id/menu_emulation_set_ir_sensitivity"
android:title="@string/emulation_ir_sensitivity"/>
<item
android:id="@+id/menu_emulation_choose_doubletap"
android:title="@string/emulation_choose_doubletap"/>
</menu>
</item>
<item
android:id="@+id/menu_emulation_reset_overlay"
android:title="@string/emulation_touch_overlay_reset"/>
</menu>