From 7b868e8c558c7cb8b3a70e2d57f0f8151e84fb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dinis=20Caro=C3=A7o?= Date: Wed, 3 Apr 2024 23:07:29 +0100 Subject: [PATCH 1/2] Fix #6024: Disable zoom buttons when min or max zoom is reached MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dinis Caroço --- .../maplayer/MapButtonsController.java | 38 +++++++++++++++++-- 1 file changed, 34 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 94cbbc6f9c..35275ef80e 100644 --- a/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java +++ b/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java @@ -33,6 +33,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; public class MapButtonsController extends Fragment { @@ -94,11 +95,40 @@ public class MapButtonsController extends Fragment helpButton.getDrawable().setTintList(null); } + final int MIN_ZOOM_LEVEL = 0; + final int MAX_ZOOM_LEVEL = 20; final View zoomFrame = mFrame.findViewById(R.id.zoom_buttons_container); - mFrame.findViewById(R.id.nav_zoom_in) - .setOnClickListener((v) -> mMapButtonClickListener.onMapButtonClick(MapButtons.zoomIn)); - mFrame.findViewById(R.id.nav_zoom_out) - .setOnClickListener((v) -> mMapButtonClickListener.onMapButtonClick(MapButtons.zoomOut)); + final View zoomInButton = mFrame.findViewById(R.id.nav_zoom_in); + final View zoomOutButton = mFrame.findViewById(R.id.nav_zoom_out); + AtomicInteger currentZoomLevel = new AtomicInteger(0); + zoomInButton.setOnClickListener((v) -> { + if (currentZoomLevel.get() < MAX_ZOOM_LEVEL) { + mMapButtonClickListener.onMapButtonClick(MapButtons.zoomIn); + currentZoomLevel.getAndIncrement(); + } + if (!zoomOutButton.isEnabled()) { + zoomOutButton.setEnabled(true); + zoomOutButton.setAlpha(1f); + } + if (currentZoomLevel.get() >= MAX_ZOOM_LEVEL) { + zoomInButton.setEnabled(false); + zoomInButton.setAlpha(0.5f); + } + }); + zoomOutButton.setOnClickListener((v) -> { + if (currentZoomLevel.get() > MIN_ZOOM_LEVEL) { + mMapButtonClickListener.onMapButtonClick(MapButtons.zoomOut); + currentZoomLevel.getAndDecrement(); + } + if (!zoomInButton.isEnabled()) { + zoomInButton.setEnabled(true); + zoomInButton.setAlpha(1f); + } + if (currentZoomLevel.get() <= MIN_ZOOM_LEVEL) { + zoomOutButton.setEnabled(false); + zoomOutButton.setAlpha(0.5f); + } + }); final View bookmarksButton = mFrame.findViewById(R.id.btn_bookmarks); bookmarksButton.setOnClickListener((v) -> mMapButtonClickListener.onMapButtonClick(MapButtons.bookmarks)); final View myPosition = mFrame.findViewById(R.id.my_position); -- 2.45.3 From b6b985e0d6a207ee9d2b5e24d8f53317c965a1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dinis=20Caro=C3=A7o?= Date: Thu, 4 Apr 2024 21:35:09 +0100 Subject: [PATCH 2/2] Fix #6024: [android] Disable zoom buttons when min or max zoom is reached MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dinis Caroço --- .../maplayer/MapButtonsController.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 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 35275ef80e..706ec6b6c6 100644 --- a/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java +++ b/android/app/src/main/java/app/organicmaps/maplayer/MapButtonsController.java @@ -17,6 +17,8 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; + +import app.organicmaps.Framework; import app.organicmaps.MwmActivity; import app.organicmaps.R; import app.organicmaps.downloader.MapManager; @@ -33,7 +35,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; public class MapButtonsController extends Fragment { @@ -95,36 +96,29 @@ public class MapButtonsController extends Fragment helpButton.getDrawable().setTintList(null); } - final int MIN_ZOOM_LEVEL = 0; + final int MIN_ZOOM_LEVEL = 2; final int MAX_ZOOM_LEVEL = 20; final View zoomFrame = mFrame.findViewById(R.id.zoom_buttons_container); final View zoomInButton = mFrame.findViewById(R.id.nav_zoom_in); final View zoomOutButton = mFrame.findViewById(R.id.nav_zoom_out); - AtomicInteger currentZoomLevel = new AtomicInteger(0); zoomInButton.setOnClickListener((v) -> { - if (currentZoomLevel.get() < MAX_ZOOM_LEVEL) { - mMapButtonClickListener.onMapButtonClick(MapButtons.zoomIn); - currentZoomLevel.getAndIncrement(); - } + if (Framework.nativeGetDrawScale() < MAX_ZOOM_LEVEL) mMapButtonClickListener.onMapButtonClick(MapButtons.zoomIn); if (!zoomOutButton.isEnabled()) { zoomOutButton.setEnabled(true); zoomOutButton.setAlpha(1f); } - if (currentZoomLevel.get() >= MAX_ZOOM_LEVEL) { + if (Framework.nativeGetDrawScale() >= MAX_ZOOM_LEVEL) { zoomInButton.setEnabled(false); zoomInButton.setAlpha(0.5f); } }); zoomOutButton.setOnClickListener((v) -> { - if (currentZoomLevel.get() > MIN_ZOOM_LEVEL) { - mMapButtonClickListener.onMapButtonClick(MapButtons.zoomOut); - currentZoomLevel.getAndDecrement(); - } + if (Framework.nativeGetDrawScale() > MIN_ZOOM_LEVEL) mMapButtonClickListener.onMapButtonClick(MapButtons.zoomOut); if (!zoomInButton.isEnabled()) { zoomInButton.setEnabled(true); zoomInButton.setAlpha(1f); } - if (currentZoomLevel.get() <= MIN_ZOOM_LEVEL) { + if (Framework.nativeGetDrawScale() <= MIN_ZOOM_LEVEL) { zoomOutButton.setEnabled(false); zoomOutButton.setAlpha(0.5f); } -- 2.45.3