WIP Update to Android 15: edge to edge fixes

This commit is contained in:
Daniele Verducci
2024-10-01 08:58:47 +02:00
parent a0978d8a54
commit f70fa7163f
15 changed files with 243 additions and 93 deletions
@@ -0,0 +1,62 @@
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;
});
}
}