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 deleted file mode 100644 index b4670341a9..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.dolphinemu.dolphinemu.utils; - -import android.app.Activity; -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Rect; -import android.view.View; -import android.view.ViewGroup; - -import androidx.core.graphics.Insets; - -import com.google.android.material.appbar.AppBarLayout; - -public class InsetsHelper -{ - 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 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 - public static void applyNavbarWorkaround(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; - } - - public static int getNavigationBarHeight(Context context) - { - Resources resources = context.getResources(); - int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); - if (resourceId > 0) - { - return resources.getDimensionPixelSize(resourceId); - } - return 0; - } - - // This is primarily intended to account for any navigation bar at the bottom of the screen - public static int getBottomPaddingRequired(Activity activity) - { - Rect visibleFrame = new Rect(); - activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleFrame); - return visibleFrame.bottom - visibleFrame.top - - activity.getResources().getDisplayMetrics().heightPixels; - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.kt new file mode 100644 index 0000000000..ea1f40ea2d --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/InsetsHelper.kt @@ -0,0 +1,67 @@ +package org.dolphinemu.dolphinemu.utils + +import android.app.Activity +import android.content.Context +import android.content.res.Resources +import android.graphics.Rect +import android.view.View +import android.view.ViewGroup +import androidx.core.graphics.Insets +import com.google.android.material.appbar.AppBarLayout + +object InsetsHelper { + const val THREE_BUTTON_NAVIGATION = 0 + const val TWO_BUTTON_NAVIGATION = 1 + const val GESTURE_NAVIGATION = 2 + + @JvmStatic + fun insetAppBar(insets: Insets, appBarLayout: AppBarLayout) { + val mlpAppBar = appBarLayout.layoutParams as ViewGroup.MarginLayoutParams + mlpAppBar.leftMargin = insets.left + mlpAppBar.topMargin = insets.top + mlpAppBar.rightMargin = insets.right + appBarLayout.layoutParams = 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 + @JvmStatic + fun applyNavbarWorkaround(bottomInset: Int, workaroundView: View) { + if (bottomInset > 0) { + val lpWorkaround = workaroundView.layoutParams + lpWorkaround.height = bottomInset + workaroundView.layoutParams = lpWorkaround + } + } + + @JvmStatic + fun getSystemGestureType(context: Context): Int { + val resources: Resources = context.resources + val resourceId = + resources.getIdentifier("config_navBarInteractionMode", "integer", "android") + return if (resourceId != 0) { + resources.getInteger(resourceId) + } else { + 0 + } + } + + @JvmStatic + fun getNavigationBarHeight(context: Context): Int { + val resources: Resources = context.resources + val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android") + return if (resourceId > 0) { + resources.getDimensionPixelSize(resourceId) + } else { + 0 + } + } + + // This is primarily intended to account for any navigation bar at the bottom of the screen + @JvmStatic + fun getBottomPaddingRequired(activity: Activity): Int { + val visibleFrame = Rect() + activity.window.decorView.getWindowVisibleDisplayFrame(visibleFrame) + return visibleFrame.bottom - visibleFrame.top - activity.resources.displayMetrics.heightPixels + } +}