Android: Remove redundant pause/unpause code

This commit is contained in:
JosJuice 2020-08-08 12:25:18 +02:00
parent 1fdabc7481
commit 6b68b76aed
2 changed files with 12 additions and 48 deletions

View File

@ -71,9 +71,6 @@ public final class EmulationActivity extends AppCompatActivity
private Settings mSettings; private Settings mSettings;
private MenuItem mPauseEmulationButton;
private MenuItem mUnpauseEmulationButton;
private boolean mDeviceHasTouchScreen; private boolean mDeviceHasTouchScreen;
private boolean mMenuVisible; private boolean mMenuVisible;
@ -544,13 +541,11 @@ public final class EmulationActivity extends AppCompatActivity
case MENU_ACTION_PAUSE_EMULATION: case MENU_ACTION_PAUSE_EMULATION:
sUserPausedEmulation = true; sUserPausedEmulation = true;
NativeLibrary.PauseEmulation(); NativeLibrary.PauseEmulation();
showUnpauseEmulationButton();
return; return;
case MENU_ACTION_UNPAUSE_EMULATION: case MENU_ACTION_UNPAUSE_EMULATION:
sUserPausedEmulation = false; sUserPausedEmulation = false;
NativeLibrary.UnPauseEmulation(); NativeLibrary.UnPauseEmulation();
showPauseEmulationButton();
return; return;
// Screenshot capturing // Screenshot capturing
@ -653,28 +648,11 @@ public final class EmulationActivity extends AppCompatActivity
} }
} }
private void showPauseEmulationButton()
{
mUnpauseEmulationButton.setVisible(false);
mPauseEmulationButton.setVisible(true);
}
private void showUnpauseEmulationButton()
{
mPauseEmulationButton.setVisible(false);
mUnpauseEmulationButton.setVisible(true);
}
public static boolean getHasUserPausedEmulation() public static boolean getHasUserPausedEmulation()
{ {
return sUserPausedEmulation; return sUserPausedEmulation;
} }
public static void setHasUserPausedEmulation(boolean value)
{
sUserPausedEmulation = value;
}
private void toggleJoystickRelCenter(boolean state) private void toggleJoystickRelCenter(boolean state)
{ {
final SharedPreferences.Editor editor = mPreferences.edit(); final SharedPreferences.Editor editor = mPreferences.edit();
@ -690,7 +668,6 @@ public final class EmulationActivity extends AppCompatActivity
Rumble.setPhoneVibrator(state, this); Rumble.setPhoneVibrator(state, this);
} }
private void editControlsPlacement() private void editControlsPlacement()
{ {
if (mEmulationFragment.isConfiguringControls()) if (mEmulationFragment.isConfiguringControls())

View File

@ -72,10 +72,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
mPauseEmulation = options.findViewById(R.id.menu_pause_emulation); mPauseEmulation = options.findViewById(R.id.menu_pause_emulation);
mUnpauseEmulation = options.findViewById(R.id.menu_unpause_emulation); mUnpauseEmulation = options.findViewById(R.id.menu_unpause_emulation);
if (EmulationActivity.getHasUserPausedEmulation()) updatePauseUnpauseVisibility();
{
showUnpauseEmulationButton();
}
boolean enableSaveStates = ((EmulationActivity) getActivity()).getSettings() boolean enableSaveStates = ((EmulationActivity) getActivity()).getSettings()
.getSection(SettingsFile.FILE_NAME_DOLPHIN, Settings.SECTION_INI_CORE) .getSection(SettingsFile.FILE_NAME_DOLPHIN, Settings.SECTION_INI_CORE)
@ -126,16 +123,12 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
return rootView; return rootView;
} }
private void showPauseEmulationButton() private void updatePauseUnpauseVisibility()
{ {
mUnpauseEmulation.setVisibility(View.GONE); boolean paused = EmulationActivity.getHasUserPausedEmulation();
mPauseEmulation.setVisibility(View.VISIBLE);
}
private void showUnpauseEmulationButton() mUnpauseEmulation.setVisibility(paused ? View.VISIBLE : View.GONE);
{ mPauseEmulation.setVisibility(paused ? View.GONE : View.VISIBLE);
mPauseEmulation.setVisibility(View.GONE);
mUnpauseEmulation.setVisibility(View.VISIBLE);
} }
@SuppressWarnings("WrongConstant") @SuppressWarnings("WrongConstant")
@ -145,19 +138,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
int action = buttonsActionsMap.get(button.getId()); int action = buttonsActionsMap.get(button.getId());
EmulationActivity activity = (EmulationActivity) requireActivity(); EmulationActivity activity = (EmulationActivity) requireActivity();
if (action == EmulationActivity.MENU_ACTION_PAUSE_EMULATION) if (action == EmulationActivity.MENU_ACTION_OVERLAY_CONTROLS)
{
EmulationActivity.setHasUserPausedEmulation(true);
NativeLibrary.PauseEmulation();
showUnpauseEmulationButton();
}
else if (action == EmulationActivity.MENU_ACTION_UNPAUSE_EMULATION)
{
EmulationActivity.setHasUserPausedEmulation(false);
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 // 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 // (because the button often is in the middle of the screen), so let's use mTitleText instead
@ -167,5 +148,11 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
{ {
activity.handleMenuAction(action); activity.handleMenuAction(action);
} }
if (action == EmulationActivity.MENU_ACTION_PAUSE_EMULATION ||
action == EmulationActivity.MENU_ACTION_UNPAUSE_EMULATION)
{
updatePauseUnpauseVisibility();
}
} }
} }