From a592b397fc7641590753b03fc1250e6e5fd5fbfc Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Fri, 12 Mar 2021 16:21:12 +0200 Subject: [PATCH 1/3] wrong direction contextmenu item https://github.com/osmandapp/OsmAnd/issues/10961 --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 21 ++++++++++--------- .../MapContextMenuFragment.java | 1 + 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index e6ce06ca35..918faf8fbd 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -18,6 +18,7 @@ import android.text.Spanned; import android.text.style.StyleSpan; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.Surface; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; @@ -66,12 +67,8 @@ public class UiUtilities { private static final Log LOG = PlatformUtil.getLog(UiUtilities.class); - private TLongObjectHashMap drawableCache = new TLongObjectHashMap<>(); - private OsmandApplication app; - private static final int ORIENTATION_0 = 0; - private static final int ORIENTATION_90 = 3; - private static final int ORIENTATION_270 = 1; - private static final int ORIENTATION_180 = 2; + private final TLongObjectHashMap drawableCache = new TLongObjectHashMap<>(); + private final OsmandApplication app; private static final int INVALID_ID = -1; public enum DialogButtonType { @@ -259,6 +256,10 @@ public class UiUtilities { } public static class UpdateLocationViewCache { + public void setScreenOrientation(int screenOrientation) { + this.screenOrientation = screenOrientation; + } + int screenOrientation; public boolean paintTxt = true; public int arrowResId; @@ -356,16 +357,16 @@ public class UiUtilities { public int getScreenOrientation() { int screenOrientation = ((WindowManager) app.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); switch (screenOrientation) { - case ORIENTATION_0: // Device default (normally portrait) + case Surface.ROTATION_0: // Device default (normally portrait) screenOrientation = 0; break; - case ORIENTATION_90: // Landscape right + case Surface.ROTATION_90: // Landscape right screenOrientation = 90; break; - case ORIENTATION_270: // Landscape left + case Surface.ROTATION_270: // Landscape left screenOrientation = 270; break; - case ORIENTATION_180: // Upside down + case Surface.ROTATION_180: // Upside down screenOrientation = 180; break; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index a3026eda83..937328e721 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -1386,6 +1386,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo mapActivity.getChooseRouteFragment().dismiss(); } updateLocationViewCache = mapActivity.getMyApplication().getUIUtilities().getUpdateLocationViewCache(); + updateLocationViewCache.setScreenOrientation(0); mapActivity.getMapViewTrackingUtilities().setContextMenu(menu); mapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false); wasDrawerDisabled = mapActivity.isDrawerDisabled(); From ded818b0920c141d473a5d118b2f9fb65bf74763 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 15 Mar 2021 10:15:48 +0200 Subject: [PATCH 2/3] Review --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 27 ++++++++++++------- .../MapContextMenuFragment.java | 3 +-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 918faf8fbd..548b17e16d 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -10,15 +10,12 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.RippleDrawable; -import android.hardware.Sensor; -import android.hardware.SensorManager; import android.os.Build; import android.text.SpannableString; import android.text.Spanned; import android.text.style.StyleSpan; import android.view.Gravity; import android.view.LayoutInflater; -import android.view.Surface; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; @@ -67,6 +64,10 @@ public class UiUtilities { private static final Log LOG = PlatformUtil.getLog(UiUtilities.class); + private static final int ORIENTATION_0 = 0; + private static final int ORIENTATION_90 = 3; + private static final int ORIENTATION_270 = 1; + private static final int ORIENTATION_180 = 2; private final TLongObjectHashMap drawableCache = new TLongObjectHashMap<>(); private final OsmandApplication app; private static final int INVALID_ID = -1; @@ -249,9 +250,15 @@ public class UiUtilities { return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL; } - public UpdateLocationViewCache getUpdateLocationViewCache(){ + public UpdateLocationViewCache getUpdateLocationViewCache() { + return getUpdateLocationViewCache(true); + } + + public UpdateLocationViewCache getUpdateLocationViewCache(boolean useScreenOrientation) { UpdateLocationViewCache uvc = new UpdateLocationViewCache(); - uvc.screenOrientation = getScreenOrientation(); + if (useScreenOrientation) { + uvc.screenOrientation = getScreenOrientation(); + } return uvc; } @@ -357,16 +364,16 @@ public class UiUtilities { public int getScreenOrientation() { int screenOrientation = ((WindowManager) app.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); switch (screenOrientation) { - case Surface.ROTATION_0: // Device default (normally portrait) + case ORIENTATION_0: // Device default (normally portrait) screenOrientation = 0; break; - case Surface.ROTATION_90: // Landscape right + case ORIENTATION_90: // Landscape right screenOrientation = 90; break; - case Surface.ROTATION_270: // Landscape left + case ORIENTATION_270: // Landscape left screenOrientation = 270; break; - case Surface.ROTATION_180: // Upside down + case ORIENTATION_180: // Upside down screenOrientation = 180; break; } @@ -378,7 +385,7 @@ public class UiUtilities { } return screenOrientation; } - + public static void setupSnackbar(Snackbar snackbar, boolean nightMode) { setupSnackbar(snackbar, nightMode, null, null, null, null); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 937328e721..4182748127 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -1385,8 +1385,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo if (MapRouteInfoMenu.chooseRoutesVisible) { mapActivity.getChooseRouteFragment().dismiss(); } - updateLocationViewCache = mapActivity.getMyApplication().getUIUtilities().getUpdateLocationViewCache(); - updateLocationViewCache.setScreenOrientation(0); + updateLocationViewCache = mapActivity.getMyApplication().getUIUtilities().getUpdateLocationViewCache(false); mapActivity.getMapViewTrackingUtilities().setContextMenu(menu); mapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false); wasDrawerDisabled = mapActivity.isDrawerDisabled(); From b2b25c31ba646c9805b97ee368da22d8ee3fd07d Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 15 Mar 2021 10:20:55 +0200 Subject: [PATCH 3/3] Minor fix --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 548b17e16d..a7c0223c22 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -263,10 +263,6 @@ public class UiUtilities { } public static class UpdateLocationViewCache { - public void setScreenOrientation(int screenOrientation) { - this.screenOrientation = screenOrientation; - } - int screenOrientation; public boolean paintTxt = true; public int arrowResId;