From 90d27be1d6246ecde3412464c2af2988b2b11bb6 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Thu, 22 Sep 2022 19:03:45 -0400 Subject: [PATCH] Android: Do not fit system windows --- .../activities/ConvertActivity.java | 11 +- .../activities/UserDataActivity.java | 11 +- .../dolphinemu/adapters/GameAdapter.java | 23 --- .../features/cheats/ui/CheatListFragment.java | 3 + .../features/cheats/ui/CheatsActivity.java | 20 +- .../ui/RiivolutionBootActivity.java | 11 +- .../settings/ui/SettingsActivity.java | 21 +- .../settings/ui/SettingsFragment.java | 4 + .../dolphinemu/ui/main/MainActivity.java | 11 ++ .../ui/platform/PlatformGamesFragment.java | 3 +- .../dolphinemu/utils/InsetsHelper.java | 181 ++++++++++++++++++ .../dolphinemu/utils/ThemeHelper.java | 120 ++++++++---- .../res/layout-land/activity_user_data.xml | 14 +- .../layout-w680dp-land/activity_convert.xml | 14 +- .../src/main/res/layout/activity_cheats.xml | 16 +- .../src/main/res/layout/activity_convert.xml | 14 +- .../app/src/main/res/layout/activity_main.xml | 13 +- .../res/layout/activity_riivolution_boot.xml | 14 +- .../src/main/res/layout/activity_settings.xml | 14 +- .../main/res/layout/activity_user_data.xml | 14 +- .../app/src/main/res/layout/card_game.xml | 40 ++-- .../res/layout/fragment_cheat_details.xml | 105 +++++----- .../main/res/layout/fragment_cheat_list.xml | 3 + .../app/src/main/res/layout/fragment_grid.xml | 8 +- .../src/main/res/layout/fragment_settings.xml | 12 +- .../app/src/main/res/values-v27/themes.xml | 1 - .../app/src/main/res/values-v29/themes.xml | 9 + 27 files changed, 551 insertions(+), 159 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java create mode 100644 Source/Android/app/src/main/res/values-v29/themes.xml diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java index bd05f751ed07..2ba35c4d2603 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/ConvertActivity.java @@ -5,8 +5,11 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.view.View; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.WindowCompat; +import androidx.core.widget.NestedScrollView; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; @@ -14,6 +17,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.fragments.ConvertFragment; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; import org.dolphinemu.dolphinemu.utils.ThemeHelper; public class ConvertActivity extends AppCompatActivity @@ -36,6 +40,8 @@ protected void onCreate(Bundle savedInstanceState) setContentView(R.layout.activity_convert); + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); + String path = getIntent().getStringExtra(ARG_GAME_PATH); ConvertFragment fragment = (ConvertFragment) getSupportFragmentManager() @@ -53,7 +59,10 @@ protected void onCreate(Bundle savedInstanceState) getSupportActionBar().setDisplayHomeAsUpEnabled(true); AppBarLayout appBarLayout = findViewById(R.id.appbar_convert); - ThemeHelper.enableScrollTint(tb, appBarLayout, this); + NestedScrollView scrollView = findViewById(R.id.scroll_view_convert); + View workaroundView = findViewById(R.id.workaround_view); + InsetsHelper.setUpAppBarWithScrollView(this, appBarLayout, scrollView, workaroundView); + ThemeHelper.enableScrollTint(this, tb, appBarLayout); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java index 02ee1bcc8274..9f6a211cd99c 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java @@ -15,7 +15,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; +import androidx.core.view.WindowCompat; +import androidx.core.widget.NestedScrollView; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.MaterialToolbar; @@ -23,6 +24,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; import org.dolphinemu.dolphinemu.utils.Log; import org.dolphinemu.dolphinemu.utils.ThemeHelper; import org.dolphinemu.dolphinemu.utils.ThreadUtil; @@ -61,6 +63,8 @@ protected void onCreate(Bundle savedInstanceState) setContentView(R.layout.activity_user_data); + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); + TextView textType = findViewById(R.id.text_type); TextView textPath = findViewById(R.id.text_path); TextView textAndroid11 = findViewById(R.id.text_android_11); @@ -92,7 +96,10 @@ protected void onCreate(Bundle savedInstanceState) getSupportActionBar().setDisplayHomeAsUpEnabled(true); AppBarLayout appBarLayout = findViewById(R.id.appbar_user_data); - ThemeHelper.enableScrollTint(tb, appBarLayout, this); + NestedScrollView scrollView = findViewById(R.id.scroll_view_user_data); + View workaroundView = findViewById(R.id.workaround_view); + InsetsHelper.setUpAppBarWithScrollView(this, appBarLayout, scrollView, workaroundView); + ThemeHelper.enableScrollTint(this, tb, appBarLayout); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java index 9d45036e1122..25d683cbac8b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java @@ -150,9 +150,7 @@ public void onClick(View view) @Override public boolean onLongClick(View view) { - FragmentActivity activity = (FragmentActivity) view.getContext(); GameViewHolder holder = (GameViewHolder) view.getTag(); - String gameId = holder.gameFile.getGameId(); GamePropertiesDialog fragment = GamePropertiesDialog.newInstance(holder.gameFile); ((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction() @@ -160,25 +158,4 @@ public boolean onLongClick(View view) return true; } - - public static class SpacesItemDecoration extends RecyclerView.ItemDecoration - { - private int space; - - public SpacesItemDecoration(int space) - { - this.space = space; - } - - @Override - public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, - @NonNull RecyclerView parent, - @NonNull RecyclerView.State state) - { - outRect.left = space; - outRect.right = space; - outRect.bottom = space; - outRect.top = space; - } - } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatListFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatListFragment.java index a2cf37dba8e4..60c20590d9e7 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatListFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatListFragment.java @@ -18,6 +18,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; public class CheatListFragment extends Fragment { @@ -44,5 +45,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat new MaterialDividerItemDecoration(requireActivity(), LinearLayoutManager.VERTICAL); divider.setLastItemDecorated(false); recyclerView.addItemDecoration(divider); + + InsetsHelper.setUpList(getContext(), recyclerView); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsActivity.java index c89aea45dcff..189db827be02 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatsActivity.java @@ -10,14 +10,18 @@ import android.view.View; import android.view.ViewGroup; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; import androidx.core.view.ViewCompat; +import androidx.core.view.WindowCompat; import androidx.lifecycle.ViewModelProvider; import androidx.slidingpanelayout.widget.SlidingPaneLayout; +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.MaterialToolbar; +import com.google.android.material.color.MaterialColors; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.dolphinemu.dolphinemu.R; @@ -27,6 +31,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.Settings; import org.dolphinemu.dolphinemu.ui.TwoPaneOnBackPressedCallback; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; import org.dolphinemu.dolphinemu.utils.ThemeHelper; public class CheatsActivity extends AppCompatActivity @@ -83,6 +88,8 @@ protected void onCreate(Bundle savedInstanceState) setContentView(R.layout.activity_cheats); + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); + mSlidingPaneLayout = findViewById(R.id.sliding_pane_layout); mCheatList = findViewById(R.id.cheat_list); mCheatDetails = findViewById(R.id.cheat_details); @@ -100,9 +107,18 @@ protected void onCreate(Bundle savedInstanceState) mViewModel.getOpenDetailsViewEvent().observe(this, this::openDetailsView); - Toolbar tb = findViewById(R.id.toolbar_cheats); + MaterialToolbar tb = findViewById(R.id.toolbar_cheats); setSupportActionBar(tb); getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + View workaroundView = findViewById(R.id.workaround_view); + AppBarLayout appBarLayout = findViewById(R.id.appbar_cheats); + InsetsHelper.setUpCheatsLayout(this, appBarLayout, mSlidingPaneLayout, mCheatDetails, + workaroundView); + + @ColorInt int color = MaterialColors.getColor(tb, R.attr.colorSurfaceVariant); + tb.setBackgroundColor(color); + ThemeHelper.setStatusBarColor(this, color); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/riivolution/ui/RiivolutionBootActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/riivolution/ui/RiivolutionBootActivity.java index 721d8e42e3bd..4186de21b824 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/riivolution/ui/RiivolutionBootActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/riivolution/ui/RiivolutionBootActivity.java @@ -5,10 +5,13 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.view.View; import android.widget.Button; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.WindowCompat; +import androidx.core.widget.NestedScrollView; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -21,6 +24,7 @@ import org.dolphinemu.dolphinemu.features.riivolution.model.RiivolutionPatches; import org.dolphinemu.dolphinemu.features.settings.model.StringSetting; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; import org.dolphinemu.dolphinemu.utils.ThemeHelper; public class RiivolutionBootActivity extends AppCompatActivity @@ -52,6 +56,8 @@ protected void onCreate(Bundle savedInstanceState) setContentView(R.layout.activity_riivolution_boot); + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); + Intent intent = getIntent(); String path = getIntent().getStringExtra(ARG_GAME_PATH); @@ -89,7 +95,10 @@ protected void onCreate(Bundle savedInstanceState) getSupportActionBar().setDisplayHomeAsUpEnabled(true); AppBarLayout appBarLayout = findViewById(R.id.appbar_riivolution); - ThemeHelper.enableScrollTint(tb, appBarLayout, this); + NestedScrollView scrollView = findViewById(R.id.scroll_view_riivolution); + View workaroundView = findViewById(R.id.workaround_view); + InsetsHelper.setUpAppBarWithScrollView(this, appBarLayout, scrollView, workaroundView); + ThemeHelper.enableScrollTint(this, tb, appBarLayout); } @Override diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java index f21764689cb0..45a48a1cfa34 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java @@ -9,11 +9,15 @@ import android.provider.Settings; import android.view.Menu; import android.view.MenuInflater; +import android.view.View; +import android.widget.FrameLayout; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowCompat; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProvider; @@ -26,6 +30,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.ui.main.MainPresenter; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; import org.dolphinemu.dolphinemu.utils.ThemeHelper; import java.util.Set; @@ -78,6 +83,8 @@ protected void onCreate(Bundle savedInstanceState) setContentView(R.layout.activity_settings); + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); + Intent launcher = getIntent(); String gameID = launcher.getStringExtra(ARG_GAME_ID); if (gameID == null) @@ -95,7 +102,15 @@ protected void onCreate(Bundle savedInstanceState) getSupportActionBar().setDisplayHomeAsUpEnabled(true); AppBarLayout appBarLayout = findViewById(R.id.appbar_settings); - ThemeHelper.enableScrollTint(tb, appBarLayout, this); + FrameLayout frameLayout = findViewById(R.id.frame_content_settings); + + // TODO: Remove this when CollapsingToolbarLayouts are fixed by Google + // https://github.com/material-components/material-components-android/issues/1310 + ViewCompat.setOnApplyWindowInsetsListener(mToolbarLayout, null); + + View workaroundView = findViewById(R.id.workaround_view); + InsetsHelper.setUpSettingsLayout(this, appBarLayout, frameLayout, workaroundView); + ThemeHelper.enableScrollTint(this, tb, appBarLayout); } @Override @@ -162,8 +177,8 @@ public void showSettingsFragment(MenuTag menuTag, Bundle extras, boolean addToSt transaction.addToBackStack(null); } - transaction.replace(R.id.frame_content, SettingsFragment.newInstance(menuTag, gameID, extras), - FRAGMENT_TAG); + transaction.replace(R.id.frame_content_settings, + SettingsFragment.newInstance(menuTag, gameID, extras), FRAGMENT_TAG); transaction.commit(); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java index 89587ea53562..025c98e56c48 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java @@ -19,6 +19,8 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.settings.model.Settings; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; +import org.dolphinemu.dolphinemu.utils.Log; import java.util.ArrayList; import java.util.HashMap; @@ -143,6 +145,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat divider.setLastItemDecorated(false); recyclerView.addItemDecoration(divider); + InsetsHelper.setUpList(getContext(), recyclerView); + SettingsActivityView activity = (SettingsActivityView) getActivity(); mPresenter.onViewCreated(menuTag, activity.getSettings()); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index 480e7472e3ca..d751e39ae532 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -9,15 +9,18 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.core.splashscreen.SplashScreen; +import androidx.core.view.WindowCompat; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.viewpager.widget.ViewPager; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; @@ -35,6 +38,7 @@ import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; import org.dolphinemu.dolphinemu.utils.PermissionsHandler; import org.dolphinemu.dolphinemu.utils.StartupHandler; import org.dolphinemu.dolphinemu.utils.ThemeHelper; @@ -50,6 +54,7 @@ public final class MainActivity extends AppCompatActivity private ViewPager mViewPager; private Toolbar mToolbar; private TabLayout mTabLayout; + private AppBarLayout mAppBarLayout; private FloatingActionButton mFab; private int mThemeId; @@ -70,6 +75,11 @@ protected void onCreate(Bundle savedInstanceState) findViews(); + View workaroundView = findViewById(R.id.workaround_view); + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); + InsetsHelper.setUpMainLayout(this, mAppBarLayout, mFab, mViewPager, workaroundView); + ThemeHelper.enableStatusBarScrollTint(this, mAppBarLayout); + setSupportActionBar(mToolbar); // Set up the FAB. @@ -147,6 +157,7 @@ else if (DirectoryInitialization.areDolphinDirectoriesReady()) // TODO: Replace with a ButterKnife injection. private void findViews() { + mAppBarLayout = findViewById(R.id.appbar_main); mToolbar = findViewById(R.id.toolbar_main); mViewPager = findViewById(R.id.pager_platforms); mTabLayout = findViewById(R.id.tabs_platforms); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java index 84b921aa8f56..62063caaeb7c 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java @@ -19,6 +19,7 @@ import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.adapters.GameAdapter; import org.dolphinemu.dolphinemu.services.GameFileCacheManager; +import org.dolphinemu.dolphinemu.utils.InsetsHelper; public final class PlatformGamesFragment extends Fragment implements PlatformGamesView { @@ -74,7 +75,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(mAdapter); - mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(8)); + InsetsHelper.setUpList(getContext(), mRecyclerView); setRefreshing(GameFileCacheManager.isLoadingOrRescanning()); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java new file mode 100644 index 000000000000..575756b99c81 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java @@ -0,0 +1,181 @@ +package org.dolphinemu.dolphinemu.utils; + +import android.content.Context; +import android.content.res.Resources; +import android.util.DisplayMetrics; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.core.widget.NestedScrollView; +import androidx.recyclerview.widget.RecyclerView; +import androidx.slidingpanelayout.widget.SlidingPaneLayout; +import androidx.viewpager.widget.ViewPager; + +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.color.MaterialColors; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import org.dolphinemu.dolphinemu.R; + +public class InsetsHelper +{ + public static final int FAB_INSET = 16; + public static final int EXTRA_NAV_INSET = 32; + + public static final int THREE_BUTTON_NAVIGATION = 0; + public static final int TWO_BUTTON_NAVIGATION = 1; + public static final int GESTURE_NAVIGATION = 2; + + public static int dpToPx(Context context, int dp) + { + return (int) (dp * ((float) context.getResources().getDisplayMetrics().densityDpi / + DisplayMetrics.DENSITY_DEFAULT) + 0.5f); + } + + public static void setUpAppBarWithScrollView(AppCompatActivity activity, + AppBarLayout appBarLayout, NestedScrollView nestedScrollView, View workaroundView) + { + ViewCompat.setOnApplyWindowInsetsListener(appBarLayout, (v, windowInsets) -> + { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + + insetAppBar(insets, appBarLayout); + + nestedScrollView.setPadding(insets.left, 0, insets.right, insets.bottom); + + applyWorkaround(insets.bottom, workaroundView); + + ThemeHelper.setNavigationBarColor(activity, + MaterialColors.getColor(appBarLayout, R.attr.colorSurface)); + + return windowInsets; + }); + } + + public static void setUpList(Context context, RecyclerView recyclerView) + { + ViewCompat.setOnApplyWindowInsetsListener(recyclerView, (v, windowInsets) -> + { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(0, 0, 0, insets.bottom + dpToPx(context, EXTRA_NAV_INSET)); + + return windowInsets; + }); + } + + public static void setUpMainLayout(AppCompatActivity activity, AppBarLayout appBarLayout, + FloatingActionButton fab, ViewPager viewPager, View workaroundView) + { + ViewCompat.setOnApplyWindowInsetsListener(appBarLayout, (v, windowInsets) -> + { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + + insetAppBar(insets, appBarLayout); + + ViewGroup.MarginLayoutParams mlpFab = (ViewGroup.MarginLayoutParams) fab.getLayoutParams(); + int fabPadding = + InsetsHelper.dpToPx(activity.getApplicationContext(), FAB_INSET); + mlpFab.leftMargin = insets.left + fabPadding; + mlpFab.bottomMargin = insets.bottom + fabPadding; + mlpFab.rightMargin = insets.right + fabPadding; + fab.setLayoutParams(mlpFab); + + viewPager.setPadding(insets.left, 0, insets.right, 0); + + applyWorkaround(insets.bottom, workaroundView); + + ThemeHelper.setNavigationBarColor(activity, + MaterialColors.getColor(appBarLayout, R.attr.colorSurface)); + + return windowInsets; + }); + } + + public static void setUpSettingsLayout(AppCompatActivity activity, + AppBarLayout appBarLayout, FrameLayout frameLayout, View workaroundView) + { + ViewCompat.setOnApplyWindowInsetsListener(appBarLayout, (v, windowInsets) -> + { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + + insetAppBar(insets, appBarLayout); + + frameLayout.setPadding(insets.left, 0, insets.right, 0); + + applyWorkaround(insets.bottom, workaroundView); + + ThemeHelper.setNavigationBarColor(activity, + MaterialColors.getColor(appBarLayout, R.attr.colorSurface)); + + return windowInsets; + }); + } + + public static void setUpCheatsLayout(AppCompatActivity activity, AppBarLayout appBarLayout, + SlidingPaneLayout slidingPaneLayout, View cheatDetails, View workaroundView) + { + ViewCompat.setOnApplyWindowInsetsListener(appBarLayout, (v, windowInsets) -> + { + Insets barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + Insets keyboardInsets = windowInsets.getInsets(WindowInsetsCompat.Type.ime()); + + insetAppBar(barInsets, appBarLayout); + + slidingPaneLayout.setPadding(barInsets.left, barInsets.top, barInsets.right, 0); + + if (keyboardInsets.bottom > 0) + { + cheatDetails.setPadding(0, 0, 0, keyboardInsets.bottom); + } + else + { + cheatDetails.setPadding(0, 0, 0, barInsets.bottom); + } + + applyWorkaround(barInsets.bottom, workaroundView); + + ThemeHelper.setNavigationBarColor(activity, + MaterialColors.getColor(appBarLayout, R.attr.colorSurface)); + + return windowInsets; + }); + } + + private static void insetAppBar(Insets insets, AppBarLayout appBarLayout) + { + ViewGroup.MarginLayoutParams mlpAppBar = + (ViewGroup.MarginLayoutParams) appBarLayout.getLayoutParams(); + mlpAppBar.leftMargin = insets.left; + mlpAppBar.topMargin = insets.top; + mlpAppBar.rightMargin = insets.right; + appBarLayout.setLayoutParams(mlpAppBar); + } + + // Workaround for a bug on Android 13 that allows users to interact with UI behind the + // navigation bar https://issuetracker.google.com/issues/248761842 + private static void applyWorkaround(int bottomInset, View workaroundView) + { + if (bottomInset > 0) + { + ViewGroup.LayoutParams lpWorkaround = workaroundView.getLayoutParams(); + lpWorkaround.height = bottomInset; + workaroundView.setLayoutParams(lpWorkaround); + } + } + + public static int getSystemGestureType(Context context) + { + Resources resources = context.getResources(); + int resourceId = resources.getIdentifier("config_navBarInteractionMode", "integer", "android"); + if (resourceId != 0) + { + return resources.getInteger(resourceId); + } + return 0; + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThemeHelper.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThemeHelper.java index ab66878383a2..5d9a1a9c5b88 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThemeHelper.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ThemeHelper.java @@ -3,10 +3,15 @@ import android.app.Activity; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.Color; import android.os.Build; import android.preference.PreferenceManager; import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.MaterialToolbar; @@ -25,7 +30,9 @@ public class ThemeHelper public static final int GREEN = 3; public static final int PINK = 4; - public static void setTheme(Activity activity) + public static final float NAV_BAR_ALPHA = 0.9f; + + public static void setTheme(@NonNull AppCompatActivity activity) { // We have to use shared preferences in addition to Dolphin's settings to guarantee that the // requested theme id is ready before the onCreate method of any given Activity. @@ -35,43 +42,22 @@ public static void setTheme(Activity activity) { case DEFAULT: activity.setTheme(R.style.Theme_Dolphin_Main); - activity.getWindow() - .setStatusBarColor(activity.getResources().getColor(R.color.dolphin_surface)); break; case MONET: activity.setTheme(R.style.Theme_Dolphin_Main_MaterialYou); - int currentNightMode = activity.getResources().getConfiguration().uiMode & - Configuration.UI_MODE_NIGHT_MASK; - switch (currentNightMode) - { - case Configuration.UI_MODE_NIGHT_NO: - activity.getWindow().setStatusBarColor( - activity.getResources().getColor(R.color.m3_sys_color_dynamic_light_surface)); - break; - case Configuration.UI_MODE_NIGHT_YES: - activity.getWindow().setStatusBarColor( - activity.getResources().getColor(R.color.m3_sys_color_dynamic_dark_surface)); - break; - } break; case MATERIAL_DEFAULT: activity.setTheme(R.style.Theme_Dolphin_Main_Material); - activity.getWindow() - .setStatusBarColor(activity.getResources().getColor(R.color.dolphin_surface)); break; case GREEN: activity.setTheme(R.style.Theme_Dolphin_Main_Green); - activity.getWindow() - .setStatusBarColor(activity.getResources().getColor(R.color.green_surface)); break; case PINK: activity.setTheme(R.style.Theme_Dolphin_Main_Pink); - activity.getWindow() - .setStatusBarColor(activity.getResources().getColor(R.color.pink_surface)); break; } @@ -79,19 +65,19 @@ public static void setTheme(Activity activity) // black status bar since their icons do not adapt based on background color if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - activity.getWindow() - .setStatusBarColor(activity.getResources().getColor(android.R.color.black)); + activity.getWindow().setStatusBarColor( + ContextCompat.getColor(activity.getApplicationContext(), android.R.color.black)); } } - public static void saveTheme(Activity activity, int themeValue) + public static void saveTheme(@NonNull Activity activity, int themeValue) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext()); preferences.edit().putInt(CURRENT_THEME, themeValue).apply(); } - public static void deleteThemeKey(Activity activity) + public static void deleteThemeKey(@NonNull Activity activity) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext()); @@ -100,7 +86,7 @@ public static void deleteThemeKey(Activity activity) activity.recreate(); } - public static void setCorrectTheme(Activity activity) + public static void setCorrectTheme(AppCompatActivity activity) { int currentTheme = ((ThemeProvider) activity).getThemeId(); setTheme(activity); @@ -111,12 +97,12 @@ public static void setCorrectTheme(Activity activity) } } - private static void setStatusBarColor(@ColorInt int color, Activity activity) + public static void setStatusBarColor(AppCompatActivity activity, @ColorInt int color) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - activity.getWindow() - .setStatusBarColor(activity.getResources().getColor(android.R.color.black)); + activity.getWindow().setStatusBarColor( + ContextCompat.getColor(activity.getApplicationContext(), android.R.color.black)); } else { @@ -124,8 +110,42 @@ private static void setStatusBarColor(@ColorInt int color, Activity activity) } } - public static void enableScrollTint(MaterialToolbar toolbar, AppBarLayout appBarLayout, - Activity activity) + public static void setNavigationBarColor(Activity activity, @ColorInt int color) + { + int gestureType = InsetsHelper.getSystemGestureType(activity.getApplicationContext()); + int orientation = activity.getResources().getConfiguration().orientation; + + // Use black if the Android version is too low to support changing button colors + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) + { + activity.getWindow().setNavigationBarColor( + ContextCompat.getColor(activity.getApplicationContext(), android.R.color.black)); + } + // Use a solid color when the navigation bar is on the left/right edge of the screen + else if ((gestureType == InsetsHelper.THREE_BUTTON_NAVIGATION || + gestureType == InsetsHelper.TWO_BUTTON_NAVIGATION) && + orientation == Configuration.ORIENTATION_LANDSCAPE) + { + activity.getWindow().setNavigationBarColor(color); + } + // Use semi-transparent color when in portrait mode with three/two button navigation to + // partially see list items behind the navigation bar + else if (gestureType == InsetsHelper.THREE_BUTTON_NAVIGATION || + gestureType == InsetsHelper.TWO_BUTTON_NAVIGATION) + { + activity.getWindow().setNavigationBarColor(getColorWithOpacity(color, NAV_BAR_ALPHA)); + } + // Use transparent color when using gesture navigation + else + { + activity.getWindow().setNavigationBarColor( + ContextCompat.getColor(activity.getApplicationContext(), + android.R.color.transparent)); + } + } + + public static void enableScrollTint(AppCompatActivity activity, MaterialToolbar toolbar, + @NonNull AppBarLayout appBarLayout) { appBarLayout.addOnOffsetChangedListener((layout, verticalOffset) -> { @@ -133,14 +153,42 @@ public static void enableScrollTint(MaterialToolbar toolbar, AppBarLayout appBar { @ColorInt int color = MaterialColors.getColor(toolbar, R.attr.colorSurfaceVariant); toolbar.setBackgroundColor(color); - setStatusBarColor(color, activity); + setStatusBarColor(activity, color); } else { - @ColorInt int color = MaterialColors.getColor(toolbar, R.attr.colorSurface); - toolbar.setBackgroundColor(color); - setStatusBarColor(color, activity); + @ColorInt int statusBarColor = ContextCompat.getColor(activity.getApplicationContext(), + android.R.color.transparent); + @ColorInt int appBarColor = MaterialColors.getColor(toolbar, R.attr.colorSurface); + toolbar.setBackgroundColor(appBarColor); + setStatusBarColor(activity, statusBarColor); } }); } + + public static void enableStatusBarScrollTint(AppCompatActivity activity, + @NonNull AppBarLayout appBarLayout) + { + appBarLayout.addOnOffsetChangedListener((layout, verticalOffset) -> + { + if (-verticalOffset > 0) + { + @ColorInt int color = MaterialColors.getColor(appBarLayout, R.attr.colorSurface); + setStatusBarColor(activity, color); + } + else + { + @ColorInt int statusBarColor = ContextCompat.getColor(activity.getApplicationContext(), + android.R.color.transparent); + setStatusBarColor(activity, statusBarColor); + } + }); + } + + @RequiresApi(api = Build.VERSION_CODES.O_MR1) @ColorInt + private static int getColorWithOpacity(@ColorInt int color, float alphaFactor) + { + return Color.argb(Math.round(alphaFactor * Color.alpha(color)), Color.red(color), + Color.green(color), Color.blue(color)); + } } diff --git a/Source/Android/app/src/main/res/layout-land/activity_user_data.xml b/Source/Android/app/src/main/res/layout-land/activity_user_data.xml index 24863dcd5fa8..52f6b173fd92 100644 --- a/Source/Android/app/src/main/res/layout-land/activity_user_data.xml +++ b/Source/Android/app/src/main/res/layout-land/activity_user_data.xml @@ -4,7 +4,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + + diff --git a/Source/Android/app/src/main/res/layout-w680dp-land/activity_convert.xml b/Source/Android/app/src/main/res/layout-w680dp-land/activity_convert.xml index 1c00d679a6f2..78dfcbd0cf92 100644 --- a/Source/Android/app/src/main/res/layout-w680dp-land/activity_convert.xml +++ b/Source/Android/app/src/main/res/layout-w680dp-land/activity_convert.xml @@ -3,7 +3,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + + diff --git a/Source/Android/app/src/main/res/layout/activity_cheats.xml b/Source/Android/app/src/main/res/layout/activity_cheats.xml index 581f8bddbe7b..151c8edf67cb 100644 --- a/Source/Android/app/src/main/res/layout/activity_cheats.xml +++ b/Source/Android/app/src/main/res/layout/activity_cheats.xml @@ -3,20 +3,22 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/coordinator_main" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + android:background="?attr/colorSurface" /> @@ -24,7 +26,7 @@ android:id="@+id/sliding_pane_layout" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginTop="56dp"> + android:layout_marginTop="64dp"> + + diff --git a/Source/Android/app/src/main/res/layout/activity_convert.xml b/Source/Android/app/src/main/res/layout/activity_convert.xml index f2e07bf56f4a..f2072d00375a 100644 --- a/Source/Android/app/src/main/res/layout/activity_convert.xml +++ b/Source/Android/app/src/main/res/layout/activity_convert.xml @@ -3,7 +3,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + + diff --git a/Source/Android/app/src/main/res/layout/activity_main.xml b/Source/Android/app/src/main/res/layout/activity_main.xml index c183cd171750..645825062a99 100644 --- a/Source/Android/app/src/main/res/layout/activity_main.xml +++ b/Source/Android/app/src/main/res/layout/activity_main.xml @@ -4,12 +4,14 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/coordinator_main" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + + diff --git a/Source/Android/app/src/main/res/layout/activity_riivolution_boot.xml b/Source/Android/app/src/main/res/layout/activity_riivolution_boot.xml index 1ab3315646de..7203dd15ed43 100644 --- a/Source/Android/app/src/main/res/layout/activity_riivolution_boot.xml +++ b/Source/Android/app/src/main/res/layout/activity_riivolution_boot.xml @@ -4,7 +4,8 @@ xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + + diff --git a/Source/Android/app/src/main/res/layout/activity_settings.xml b/Source/Android/app/src/main/res/layout/activity_settings.xml index d38c9618d1d5..561755a5f661 100644 --- a/Source/Android/app/src/main/res/layout/activity_settings.xml +++ b/Source/Android/app/src/main/res/layout/activity_settings.xml @@ -4,7 +4,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/coordinator_main" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + + diff --git a/Source/Android/app/src/main/res/layout/activity_user_data.xml b/Source/Android/app/src/main/res/layout/activity_user_data.xml index a9df023fce64..849e4668cb75 100644 --- a/Source/Android/app/src/main/res/layout/activity_user_data.xml +++ b/Source/Android/app/src/main/res/layout/activity_user_data.xml @@ -4,7 +4,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/colorSurface"> + + diff --git a/Source/Android/app/src/main/res/layout/card_game.xml b/Source/Android/app/src/main/res/layout/card_game.xml index 2e7eb280d3bc..47e2c7a5593d 100644 --- a/Source/Android/app/src/main/res/layout/card_game.xml +++ b/Source/Android/app/src/main/res/layout/card_game.xml @@ -1,5 +1,6 @@ - + app:cardCornerRadius="4dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + android:layout_weight="1" /> @@ -47,26 +49,28 @@ - + diff --git a/Source/Android/app/src/main/res/layout/fragment_cheat_details.xml b/Source/Android/app/src/main/res/layout/fragment_cheat_details.xml index 208bd9b45053..5b85c3b5abec 100644 --- a/Source/Android/app/src/main/res/layout/fragment_cheat_details.xml +++ b/Source/Android/app/src/main/res/layout/fragment_cheat_details.xml @@ -14,7 +14,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toTopOf="@id/barrier"> + app:layout_constraintBottom_toTopOf="@id/button_layout"> - + android:background="@android:color/transparent" + app:layout_constraintBottom_toBottomOf="parent"> -