From f2c71a77fe74314e6ef7060a617acd1336274f66 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Tue, 6 Dec 2022 18:41:55 -0500 Subject: [PATCH] Android: Use ElevationOverlay for app bar elevation color --- .../features/cheats/ui/CheatListFragment.java | 10 ++++++++++ .../dolphinemu/features/cheats/ui/CheatsActivity.java | 5 ++++- .../org/dolphinemu/dolphinemu/utils/ThemeHelper.java | 6 +++++- .../app/src/main/res/layout/fragment_cheat_list.xml | 4 ++-- Source/Android/app/src/main/res/values/dimens.xml | 2 ++ 5 files changed, 23 insertions(+), 4 deletions(-) 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 62d3b19e79..b7dc0c8e4e 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 @@ -7,6 +7,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.graphics.Insets; @@ -16,7 +17,9 @@ import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; +import com.google.android.material.color.MaterialColors; import com.google.android.material.divider.MaterialDividerItemDecoration; +import com.google.android.material.elevation.ElevationOverlayProvider; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.databinding.FragmentCheatListBinding; @@ -49,6 +52,13 @@ public class CheatListFragment extends Fragment divider.setLastItemDecorated(false); mBinding.cheatList.addItemDecoration(divider); + @ColorInt int color = + new ElevationOverlayProvider(mBinding.cheatsWarning.getContext()).compositeOverlay( + MaterialColors.getColor(mBinding.cheatsWarning, R.attr.colorSurface), + getResources().getDimensionPixelSize(R.dimen.elevated_app_bar)); + mBinding.cheatsWarning.setBackgroundColor(color); + mBinding.gfxModsWarning.setBackgroundColor(color); + setInsets(); } 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 cde90eec69..8941626b92 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 @@ -24,6 +24,7 @@ import androidx.slidingpanelayout.widget.SlidingPaneLayout; import com.google.android.material.color.MaterialColors; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.elevation.ElevationOverlayProvider; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.databinding.ActivityCheatsBinding; @@ -112,7 +113,9 @@ public class CheatsActivity extends AppCompatActivity setInsets(); @ColorInt int color = - MaterialColors.getColor(mBinding.toolbarCheats, R.attr.colorSurfaceVariant); + new ElevationOverlayProvider(mBinding.toolbarCheats.getContext()).compositeOverlay( + MaterialColors.getColor(mBinding.toolbarCheats, R.attr.colorSurface), + getResources().getDimensionPixelSize(R.dimen.elevated_app_bar)); mBinding.toolbarCheats.setBackgroundColor(color); ThemeHelper.setStatusBarColor(this, color); } 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 040e20990a..968d0eef68 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 @@ -19,6 +19,7 @@ import androidx.preference.PreferenceManager; 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.elevation.ElevationOverlayProvider; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.ui.main.ThemeProvider; @@ -222,7 +223,10 @@ public class ThemeHelper { if (-verticalOffset >= (layout.getTotalScrollRange() / 2)) { - @ColorInt int color = MaterialColors.getColor(toolbar, R.attr.colorSurfaceVariant); + @ColorInt int color = + new ElevationOverlayProvider(appBarLayout.getContext()).compositeOverlay( + MaterialColors.getColor(appBarLayout, R.attr.colorSurface), + activity.getResources().getDimensionPixelSize(R.dimen.elevated_app_bar)); toolbar.setBackgroundColor(color); setStatusBarColor(activity, color); } diff --git a/Source/Android/app/src/main/res/layout/fragment_cheat_list.xml b/Source/Android/app/src/main/res/layout/fragment_cheat_list.xml index c82f4104ff..93649f4def 100644 --- a/Source/Android/app/src/main/res/layout/fragment_cheat_list.xml +++ b/Source/Android/app/src/main/res/layout/fragment_cheat_list.xml @@ -10,7 +10,7 @@ android:name="org.dolphinemu.dolphinemu.features.cheats.ui.CheatsDisabledWarningFragment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/colorSurfaceVariant" + android:background="?attr/colorSurface" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" @@ -21,7 +21,7 @@ android:name="org.dolphinemu.dolphinemu.features.cheats.ui.GraphicsModsDisabledWarningFragment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/colorSurfaceVariant" + android:background="?attr/colorSurface" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/cheats_warning" diff --git a/Source/Android/app/src/main/res/values/dimens.xml b/Source/Android/app/src/main/res/values/dimens.xml index 17230aaf6c..f10f34e81a 100644 --- a/Source/Android/app/src/main/res/values/dimens.xml +++ b/Source/Android/app/src/main/res/values/dimens.xml @@ -7,4 +7,6 @@ 72dp 256dp 135dp + + 3dp