From 17a9283d1812cc534978eaf0eaee215d03f10431 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sat, 21 Dec 2024 13:43:42 +0530 Subject: [PATCH] DrawerFragment: set insets for edge to edge screen --- .../pandroid/app/game/DrawerFragment.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/game/DrawerFragment.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/game/DrawerFragment.java index 736a2cdcb..d74c42772 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/game/DrawerFragment.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/game/DrawerFragment.java @@ -8,13 +8,16 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.content.pm.ActivityInfo; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatTextView; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; -import android.content.pm.ActivityInfo; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.core.graphics.Insets; import com.google.android.material.navigation.NavigationView; import com.panda3ds.pandroid.AlberDriver; @@ -49,6 +52,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat drawerLayout = view.findViewById(R.id.drawer_layout); ((NavigationView)view.findViewById(R.id.menu)).setNavigationItemSelectedListener(this); + setInsets(((NavigationView)view.findViewById(R.id.menu))); refresh(); } @@ -63,6 +67,29 @@ private void refresh() { ((AppCompatTextView)drawerLayout.findViewById(R.id.game_publisher)).setText(game.getPublisher()); } + private void setInsets(NavigationView navigationView) { + ViewCompat.setOnApplyWindowInsetsListener( + navigationView, + new androidx.core.view.OnApplyWindowInsetsListener() { + @Override + public WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsets) { + Insets cutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout()); + int left = 0; + int right = 0; + if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) { + left = cutInsets.left; + } else { + right = cutInsets.right; + } + + view.setPadding(left, cutInsets.top, right, 0); + return windowInsets; + } + } + ); + } + + @Override public void onDetach() { if (drawerContainer != null) {