From cf51642c17878ddeebee4397b03b46f10871bf47 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 7 Apr 2020 18:02:35 +0200 Subject: [PATCH] Android: Use Back to open the emulation menu on all devices https://bugs.dolphin-emu.org/issues/12029 We currently have one way of opening the menu on touch screen devices (swiping down from the top of the screen to bring up the action bar and selecting the menu in the action bar), and another way of opening the menu on Android TV (pressing Back). However, some devices that claim to support touch (or don't support leanback? Dolphin currently conflates the two) don't actually let you swipe down from the top of the screen in the way that Dolphin expects, notably Chromebooks. There are also some phones where you can swipe down from the top of the screen but this for some reason doesn't lead to the action bar becoming visible, though we are getting less reports about this nowadays than in the past. This change makes us use the Back method on all devices, since it should work on all devices with no significant drawbacks. Unfortunately, we not only have two different ways of triggering the menu but actually two entirely different menus, with the non-touch menu not implementing options that only are revelant when using a touch screen. A later commit will add the missing features to the menu that we now use on all devices. --- .../activities/EmulationActivity.java | 94 +++++-------------- .../layout-television/activity_emulation.xml | 38 -------- .../main/res/layout/activity_emulation.xml | 27 ++++++ .../app/src/main/res/values/strings.xml | 2 +- .../app/src/main/res/values/styles.xml | 16 +--- 5 files changed, 54 insertions(+), 123 deletions(-) delete mode 100644 Source/Android/app/src/main/res/layout-television/activity_emulation.xml diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 090e22a1bb..3ec233a117 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -6,7 +6,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.os.Bundle; -import android.os.Handler; import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.SparseIntArray; @@ -62,7 +61,6 @@ public final class EmulationActivity extends AppCompatActivity private static final String BACKSTACK_NAME_SUBMENU = "submenu"; public static final int REQUEST_CHANGE_DISC = 1; - private View mDecorView; private EmulationFragment mEmulationFragment; private SharedPreferences mPreferences; @@ -85,7 +83,6 @@ public final class EmulationActivity extends AppCompatActivity private int mPlatform; private String[] mPaths; private static boolean sUserPausedEmulation; - private boolean backPressedOnce = false; public static final String EXTRA_SELECTED_GAMES = "SelectedGames"; public static final String EXTRA_SELECTED_TITLE = "SelectedTitle"; @@ -317,33 +314,10 @@ public final class EmulationActivity extends AppCompatActivity mDeviceHasTouchScreen = getPackageManager().hasSystemFeature("android.hardware.touchscreen"); mMotionListener = new MotionListener(this); - int themeId; - if (mDeviceHasTouchScreen) - { - themeId = R.style.DolphinEmulationBase; + // Set these options now so that the SurfaceView the game renders into is the right size. + enableFullscreenImmersive(); - // Get a handle to the Window containing the UI. - mDecorView = getWindow().getDecorView(); - mDecorView.setOnSystemUiVisibilityChangeListener(visibility -> - { - if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) - { - // Go back to immersive fullscreen mode in 3s - Handler handler = new Handler(getMainLooper()); - handler.postDelayed(this::enableFullscreenImmersive, 3000 /* 3s */); - } - }); - // Set these options now so that the SurfaceView the game renders into is the right size. - enableFullscreenImmersive(); - Toast.makeText(this, getString(R.string.emulation_touch_button_help), Toast.LENGTH_LONG) - .show(); - } - else - { - themeId = R.style.DolphinEmulationTvBase; - } - - setTheme(themeId); + Toast.makeText(this, getString(R.string.emulation_menu_help), Toast.LENGTH_LONG).show(); Rumble.initRumble(this); @@ -360,10 +334,7 @@ public final class EmulationActivity extends AppCompatActivity .commit(); } - if (mDeviceHasTouchScreen) - { - setTitle(mSelectedTitle); - } + setTitle(mSelectedTitle); } @Override @@ -390,10 +361,20 @@ public final class EmulationActivity extends AppCompatActivity sUserPausedEmulation = savedInstanceState.getBoolean(EXTRA_USER_PAUSED_EMULATION); } + @Override + public void onWindowFocusChanged(boolean hasFocus) + { + if (hasFocus) + { + enableFullscreenImmersive(); + } + } + @Override protected void onResume() { super.onResume(); + if (!sIsGameCubeGame && mPreferences.getInt("motionControlsEnabled", 0) != 2) mMotionListener.enable(); } @@ -414,28 +395,11 @@ public final class EmulationActivity extends AppCompatActivity @Override public void onBackPressed() { - if (!mDeviceHasTouchScreen) + boolean popResult = getSupportFragmentManager().popBackStackImmediate( + BACKSTACK_NAME_SUBMENU, FragmentManager.POP_BACK_STACK_INCLUSIVE); + if (!popResult) { - boolean popResult = getSupportFragmentManager().popBackStackImmediate( - BACKSTACK_NAME_SUBMENU, FragmentManager.POP_BACK_STACK_INCLUSIVE); - if (!popResult) - { - toggleMenu(); - } - } - else - { - if (backPressedOnce) - { - mEmulationFragment.stopEmulation(); - finish(); - } - else - { - backPressedOnce = true; - Toast.makeText(this, "Press back again to exit", Toast.LENGTH_LONG).show(); - new Handler().postDelayed(() -> backPressedOnce = false, 3000); - } + toggleMenu(); } } @@ -459,14 +423,13 @@ public final class EmulationActivity extends AppCompatActivity private void enableFullscreenImmersive() { - // It would be nice to use IMMERSIVE_STICKY, but that doesn't show the toolbar. - mDecorView.setSystemUiVisibility( + getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | - View.SYSTEM_UI_FLAG_IMMERSIVE); + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } private void updateOrientation() @@ -631,19 +594,12 @@ public final class EmulationActivity extends AppCompatActivity NativeLibrary.LoadState(9); return; - // TV Menu only case MENU_ACTION_SAVE_ROOT: - if (!mDeviceHasTouchScreen) - { - showSubMenu(SaveLoadStateFragment.SaveOrLoad.SAVE); - } + showSubMenu(SaveLoadStateFragment.SaveOrLoad.SAVE); return; case MENU_ACTION_LOAD_ROOT: - if (!mDeviceHasTouchScreen) - { - showSubMenu(SaveLoadStateFragment.SaveOrLoad.LOAD); - } + showSubMenu(SaveLoadStateFragment.SaveOrLoad.LOAD); return; // Save state slots @@ -718,9 +674,9 @@ public final class EmulationActivity extends AppCompatActivity return; case MENU_ACTION_EXIT: - // ATV menu is built using a fragment, this will pop that fragment before emulation ends. - if (TvUtil.isLeanback(getApplicationContext())) - toggleMenu(); // Hide the menu (it will be showing since we just clicked it) + // Hide the menu (it will be showing since we just clicked it) + toggleMenu(); + mEmulationFragment.stopEmulation(); finish(); return; diff --git a/Source/Android/app/src/main/res/layout-television/activity_emulation.xml b/Source/Android/app/src/main/res/layout-television/activity_emulation.xml deleted file mode 100644 index 5e516d04ad..0000000000 --- a/Source/Android/app/src/main/res/layout-television/activity_emulation.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/Source/Android/app/src/main/res/layout/activity_emulation.xml b/Source/Android/app/src/main/res/layout/activity_emulation.xml index 2ebea4fc34..5e516d04ad 100644 --- a/Source/Android/app/src/main/res/layout/activity_emulation.xml +++ b/Source/Android/app/src/main/res/layout/activity_emulation.xml @@ -1,6 +1,8 @@ + + + + + + + + + + diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 1ced8c6969..033f279b4b 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -355,7 +355,7 @@ Relative Stick Center Rumble Choose Controller - Swipe down from the top of the screen to access the menu. + Press Back to access the menu. Reset Overlay Touch IR Pointer IR Sensitivity diff --git a/Source/Android/app/src/main/res/values/styles.xml b/Source/Android/app/src/main/res/values/styles.xml index 8a292d4113..5bb491c418 100644 --- a/Source/Android/app/src/main/res/values/styles.xml +++ b/Source/Android/app/src/main/res/values/styles.xml @@ -29,21 +29,7 @@ - -