From 724a3b4766ecb4360cad4bb62b3f7c52f9c26d99 Mon Sep 17 00:00:00 2001 From: Dzmitry Strekha Date: Fri, 29 Nov 2024 20:03:51 +0300 Subject: [PATCH 1/4] [Android] Possible fix for wrong ime insets on some devices Signed-off-by: Dzmitry Strekha --- .../maplayer/MapButtonsController.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java b/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java index e3ae526f3b..82738292b0 100644 --- a/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java +++ b/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java @@ -12,7 +12,10 @@ import android.view.ViewTreeObserver; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.OptIn; +import androidx.core.graphics.Insets; +import androidx.core.view.OnApplyWindowInsetsListener; import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.Observer; @@ -30,8 +33,6 @@ import app.organicmaps.routing.RoutingController; import app.organicmaps.util.Config; import app.organicmaps.util.ThemeUtils; import app.organicmaps.util.UiUtils; -import app.organicmaps.util.WindowInsetUtils; -import app.organicmaps.util.WindowInsetUtils.PaddingInsetsListener; import app.organicmaps.widget.menu.MyPositionButton; import app.organicmaps.widget.placepage.PlacePageViewModel; import com.google.android.material.badge.BadgeDrawable; @@ -157,8 +158,6 @@ public class MapButtonsController extends Fragment mButtonsMap.put(MapButtons.menu, menuButton); if (helpButton != null) mButtonsMap.put(MapButtons.help, helpButton); - - ViewCompat.setOnApplyWindowInsetsListener(mFrame, PaddingInsetsListener.allSides()); return mFrame; } @@ -362,6 +361,26 @@ public class MapButtonsController extends Fragment mSearchWheel.onResume(); updateMenuBadge(); updateLayerButton(); + ViewCompat.setOnApplyWindowInsetsListener(mFrame, new OnApplyWindowInsetsListener() + { + @NonNull + @Override + public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat windowInsets) + { + // ignore ime insets here + final var insetsType = WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(); + final Insets insets = windowInsets.getInsets(insetsType); + v.setPadding(insets.left, insets.top, insets.right, insets.bottom); + return windowInsets; + } + }); + } + + @Override + public void onPause() + { + ViewCompat.setOnApplyWindowInsetsListener(mFrame, null); + super.onPause(); } @Override -- 2.45.3 From 2fab3140165964e511ffdb1d0a87fcf2293547c6 Mon Sep 17 00:00:00 2001 From: Dzmitry Strekha Date: Sun, 1 Dec 2024 14:27:15 +0300 Subject: [PATCH 2/4] [Android] Allow changing default insets type mask with a Builder Signed-off-by: Dzmitry Strekha --- .../organicmaps/util/WindowInsetUtils.java | 82 ++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/util/WindowInsetUtils.java b/android/app/src/main/java/app/organicmaps/util/WindowInsetUtils.java index 9bde7da119..f366562223 100644 --- a/android/app/src/main/java/app/organicmaps/util/WindowInsetUtils.java +++ b/android/app/src/main/java/app/organicmaps/util/WindowInsetUtils.java @@ -138,19 +138,29 @@ public final class WindowInsetUtils public static final class PaddingInsetsListener implements OnApplyWindowInsetsListener { + private final int insetsTypeMask; private final boolean top; private final boolean bottom; private final boolean left; private final boolean right; - public PaddingInsetsListener(boolean top, boolean bottom, boolean left, boolean right) + public PaddingInsetsListener(int insetsTypeMask, boolean top, boolean bottom, boolean left, boolean right) { + this.insetsTypeMask = insetsTypeMask; this.top = top; this.bottom = bottom; this.left = left; this.right = right; } + /** + * Creates PaddingInsetsListener with default insetsTypeMask equals TYPE_SAFE_DRAWING + */ + public PaddingInsetsListener(boolean top, boolean bottom, boolean left, boolean right) + { + this(TYPE_SAFE_DRAWING, top, bottom, left, right); + } + public static PaddingInsetsListener allSides() { return new PaddingInsetsListener(true, true, true, true); @@ -170,7 +180,7 @@ public final class WindowInsetUtils @Override public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat windowInsets) { - final Insets insets = windowInsets.getInsets(TYPE_SAFE_DRAWING); + final Insets insets = windowInsets.getInsets(insetsTypeMask); v.setPadding( left ? insets.left : v.getPaddingLeft(), top ? insets.top : v.getPaddingTop(), @@ -178,5 +188,73 @@ public final class WindowInsetUtils bottom ? insets.bottom : v.getPaddingBottom()); return windowInsets; } + + public static class Builder { + + private int mInsetsTypeMask = TYPE_SAFE_DRAWING; + private boolean mTop; + private boolean mBottom; + private boolean mLeft; + private boolean mRight; + + public Builder setInsetsTypeMask(int insetsTypeMask) + { + mInsetsTypeMask = insetsTypeMask; + return this; + } + + public Builder setAllSides() { + mTop = true; + mBottom = true; + mLeft = true; + mRight = true; + return this; + } + + public Builder setExcludeTop() { + mTop = false; + mBottom = true; + mLeft = true; + mRight = true; + return this; + } + + public Builder setExcludeBottom() { + mTop = true; + mBottom = false; + mLeft = true; + mRight = true; + return this; + } + + public Builder setTop(boolean top) + { + mTop = top; + return this; + } + + public Builder setBottom(boolean bottom) + { + mBottom = bottom; + return this; + } + + public Builder setLeft(boolean left) + { + mLeft = left; + return this; + } + + public Builder setRight(boolean right) + { + mRight = right; + return this; + } + + public PaddingInsetsListener build() + { + return new PaddingInsetsListener(mInsetsTypeMask, mTop, mBottom, mLeft, mRight); + } + } } } -- 2.45.3 From d76a734607cedcc14ea4b803f88fee0a5d3fd439 Mon Sep 17 00:00:00 2001 From: Dzmitry Strekha Date: Sun, 1 Dec 2024 14:28:43 +0300 Subject: [PATCH 3/4] [Android] Change insets type to exclude ime insets Signed-off-by: Dzmitry Strekha --- .../maplayer/MapButtonsController.java | 21 ++++++------------- .../widget/placepage/PlacePageButtons.java | 7 ++++++- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java b/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java index 82738292b0..8f53e4387d 100644 --- a/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java +++ b/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java @@ -12,8 +12,6 @@ import android.view.ViewTreeObserver; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.OptIn; -import androidx.core.graphics.Insets; -import androidx.core.view.OnApplyWindowInsetsListener; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; @@ -33,6 +31,7 @@ import app.organicmaps.routing.RoutingController; import app.organicmaps.util.Config; import app.organicmaps.util.ThemeUtils; import app.organicmaps.util.UiUtils; +import app.organicmaps.util.WindowInsetUtils; import app.organicmaps.widget.menu.MyPositionButton; import app.organicmaps.widget.placepage.PlacePageViewModel; import com.google.android.material.badge.BadgeDrawable; @@ -361,19 +360,11 @@ public class MapButtonsController extends Fragment mSearchWheel.onResume(); updateMenuBadge(); updateLayerButton(); - ViewCompat.setOnApplyWindowInsetsListener(mFrame, new OnApplyWindowInsetsListener() - { - @NonNull - @Override - public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat windowInsets) - { - // ignore ime insets here - final var insetsType = WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(); - final Insets insets = windowInsets.getInsets(insetsType); - v.setPadding(insets.left, insets.top, insets.right, insets.bottom); - return windowInsets; - } - }); + final WindowInsetUtils.PaddingInsetsListener insetsListener = new WindowInsetUtils.PaddingInsetsListener.Builder() + .setInsetsTypeMask(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout()) + .setAllSides() + .build(); + ViewCompat.setOnApplyWindowInsetsListener(mFrame, insetsListener); } @Override diff --git a/android/app/src/main/java/app/organicmaps/widget/placepage/PlacePageButtons.java b/android/app/src/main/java/app/organicmaps/widget/placepage/PlacePageButtons.java index d4fd663135..5fd7ec6b26 100644 --- a/android/app/src/main/java/app/organicmaps/widget/placepage/PlacePageButtons.java +++ b/android/app/src/main/java/app/organicmaps/widget/placepage/PlacePageButtons.java @@ -11,6 +11,7 @@ import androidx.annotation.AttrRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; @@ -44,7 +45,11 @@ public final class PlacePageButtons extends Fragment implements Observer Date: Sun, 1 Dec 2024 14:50:48 +0300 Subject: [PATCH 4/4] [Android] Change insets type to exclude ime insets Signed-off-by: Dzmitry Strekha --- .../app/organicmaps/routing/RoutingPlanController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/app/organicmaps/routing/RoutingPlanController.java b/android/app/src/main/java/app/organicmaps/routing/RoutingPlanController.java index deadbcab41..691681690e 100644 --- a/android/app/src/main/java/app/organicmaps/routing/RoutingPlanController.java +++ b/android/app/src/main/java/app/organicmaps/routing/RoutingPlanController.java @@ -12,6 +12,7 @@ import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; import app.organicmaps.Framework; import app.organicmaps.MwmApplication; import app.organicmaps.R; @@ -108,7 +109,11 @@ public class RoutingPlanController extends ToolbarController .getResources().getInteger(R.integer.anim_default); final View menuFrame = activity.findViewById(R.id.menu_frame); - ViewCompat.setOnApplyWindowInsetsListener(menuFrame, PaddingInsetsListener.excludeTop()); + final PaddingInsetsListener insetsListener = new PaddingInsetsListener.Builder() + .setInsetsTypeMask(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout()) + .setExcludeTop() + .build(); + ViewCompat.setOnApplyWindowInsetsListener(menuFrame, insetsListener); } @NonNull -- 2.45.3