package it.danieleverducci.nextcloudmaps.utils; import android.view.View; import android.view.ViewGroup; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class EdgeToEdgeUtils { /** * Clears the system bars in edge to edge mode (https://developer.android.com/develop/ui/views/layout/edge-to-edge) * @param viewToClear the view to clear from system bars */ public static void clearBottomBarWithMargin(View viewToClear) { ViewCompat.setOnApplyWindowInsetsListener(viewToClear, (v, windowInsets) -> { Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); mlp.bottomMargin = insets.bottom; mlp.leftMargin = insets.left; mlp.rightMargin = insets.right; v.setLayoutParams(mlp); //return WindowInsetsCompat.CONSUMED; return windowInsets; }); } /** * Clears the system bars in edge to edge mode (https://developer.android.com/develop/ui/views/layout/edge-to-edge) * @param viewToClear the view to clear from system bars */ public static void clearTopBarWithMargin(View viewToClear) { ViewCompat.setOnApplyWindowInsetsListener(viewToClear, (v, windowInsets) -> { Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); mlp.topMargin = insets.top; mlp.leftMargin = insets.left; mlp.rightMargin = insets.right; v.setLayoutParams(mlp); //return WindowInsetsCompat.CONSUMED; return windowInsets; }); } /** * Clears the system bars in edge to edge mode (https://developer.android.com/develop/ui/views/layout/edge-to-edge) * @param viewToClear the view to clear from system bars */ public static void clearTopBarWithPadding(View viewToClear) { ViewCompat.setOnApplyWindowInsetsListener(viewToClear, (v, windowInsets) -> { Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(insets.left, insets.top, insets.right, v.getPaddingBottom()); //return WindowInsetsCompat.CONSUMED; return windowInsets; }); } }