From be357ef06a3494980c8bf7c78e1cedaddfbd1655 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 15 Jun 2017 18:48:16 +0300 Subject: [PATCH 1/6] Show the distance between the fingers in each ruler mode; Draw the first or second mode of the ruler only if the widget is visible (check in Analyze on map) --- .../osmand/plus/views/RulerControlLayer.java | 79 ++++++++++--------- .../mapwidgets/MapInfoWidgetsFactory.java | 38 ++++----- 2 files changed, 60 insertions(+), 57 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index 7e92c2da14..3474459826 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -7,6 +7,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.Rect; +import android.view.View; import net.osmand.Location; import net.osmand.data.QuadPoint; @@ -25,6 +26,7 @@ public class RulerControlLayer extends OsmandMapLayer { private final MapActivity mapActivity; private OsmandApplication app; private OsmandMapTileView view; + private View rightWidgetsPanel; private TextSide textSide; private int maxRadiusInDp; @@ -55,6 +57,7 @@ public class RulerControlLayer extends OsmandMapLayer { cacheDistances = new ArrayList<>(); cacheCenter = new QuadPoint(); maxRadiusInDp = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_radius); + rightWidgetsPanel = mapActivity.findViewById(R.id.map_right_widgets_panel); centerIconDay = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_day); centerIconNight = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_night); @@ -78,28 +81,28 @@ public class RulerControlLayer extends OsmandMapLayer { @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { - if (mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler")) { + if (mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler") && + rightWidgetsPanel.getVisibility() == View.VISIBLE) { lineAttrs.updatePaints(view, settings, tb); circleAttrs.updatePaints(view, settings, tb); circleAttrs.paint2.setStyle(Style.FILL); final QuadPoint center = tb.getCenterPixelPoint(); final RulerMode mode = app.getSettings().RULER_MODE.get(); - if (mode == RulerMode.FIRST) { - if (view.isMultiTouch()) { - float x1 = view.getFirstTouchPointX(); - float y1 = view.getFirstTouchPointY(); - float x2 = view.getSecondTouchPointX(); - float y2 = view.getSecondTouchPointY(); - drawFingerDistance(canvas, tb, center, x1, y1, x2, y2); - } else { - drawCenterIcon(canvas, tb, center, settings.isNightMode()); - Location currentLoc = app.getLocationProvider().getLastKnownLocation(); - if (currentLoc != null) { - drawDistance(canvas, tb, center, currentLoc); - } + if (view.isMultiTouch()) { + float x1 = view.getFirstTouchPointX(); + float y1 = view.getFirstTouchPointY(); + float x2 = view.getSecondTouchPointX(); + float y2 = view.getSecondTouchPointY(); + drawFingerDistance(canvas, tb, center, x1, y1, x2, y2); + } else if (mode == RulerMode.FIRST) { + drawCenterIcon(canvas, tb, center, settings.isNightMode()); + Location currentLoc = app.getLocationProvider().getLastKnownLocation(); + if (currentLoc != null) { + drawDistance(canvas, tb, center, currentLoc); } - } else if (mode == RulerMode.SECOND) { + } + if (mode == RulerMode.SECOND) { drawCenterIcon(canvas, tb, center, settings.isNightMode()); updateData(tb, center); for (int i = 1; i <= cacheDistances.size(); i++) { @@ -191,30 +194,30 @@ public class RulerControlLayer extends OsmandMapLayer { } private void drawCircle(Canvas canvas, RotatedTileBox tb, int circleNumber, QuadPoint center) { - Rect bounds = new Rect(); - String text = cacheDistances.get(circleNumber - 1); - circleAttrs.paint2.getTextBounds(text, 0, text.length(), bounds); - - // coords of left or top text - float x1 = 0; - float y1 = 0; - // coords of right or bottom text - float x2 = 0; - float y2 = 0; - - if (textSide == TextSide.VERTICAL) { - x1 = center.x - bounds.width() / 2; - y1 = center.y - radius * circleNumber + bounds.height() / 2; - x2 = center.x - bounds.width() / 2; - y2 = center.y + radius * circleNumber + bounds.height() / 2; - } else if (textSide == TextSide.HORIZONTAL) { - x1 = center.x - radius * circleNumber - bounds.width() / 2; - y1 = center.y + bounds.height() / 2; - x2 = center.x + radius * circleNumber - bounds.width() / 2; - y2 = center.y + bounds.height() / 2; - } - if (!mapActivity.getMapView().isZooming()) { + Rect bounds = new Rect(); + String text = cacheDistances.get(circleNumber - 1); + circleAttrs.paint2.getTextBounds(text, 0, text.length(), bounds); + + // coords of left or top text + float x1 = 0; + float y1 = 0; + // coords of right or bottom text + float x2 = 0; + float y2 = 0; + + if (textSide == TextSide.VERTICAL) { + x1 = center.x - bounds.width() / 2; + y1 = center.y - radius * circleNumber + bounds.height() / 2; + x2 = center.x - bounds.width() / 2; + y2 = center.y + radius * circleNumber + bounds.height() / 2; + } else if (textSide == TextSide.HORIZONTAL) { + x1 = center.x - radius * circleNumber - bounds.width() / 2; + y1 = center.y + bounds.height() / 2; + x2 = center.x + radius * circleNumber - bounds.width() / 2; + y2 = center.y + bounds.height() / 2; + } + canvas.rotate(-tb.getRotate(), center.x, center.y); canvas.drawCircle(center.x, center.y, radius * circleNumber, circleAttrs.shadowPaint); canvas.drawCircle(center.x, center.y, radius * circleNumber, circleAttrs.paint); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index 86d6ca014b..aa7e228de6 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -190,32 +190,32 @@ public class MapInfoWidgetsFactory { @Override public boolean updateInfo(DrawSettings drawSettings) { RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get(); - if (mode == RulerMode.FIRST) { + OsmandMapTileView view = map.getMapView(); + + if (view.isMultiTouch()) { + if (needNewLatLon) { + float x1 = view.getFirstTouchPointX(); + float y1 = view.getFirstTouchPointY(); + float x2 = view.getSecondTouchPointX(); + float y2 = view.getSecondTouchPointY(); + LatLon firstFinger = view.getCurrentRotatedTileBox().getLatLonFromPixel(x1, y1); + LatLon secondFinger = view.getCurrentRotatedTileBox().getLatLonFromPixel(x2, y2); + setDistanceText(firstFinger.getLatitude(), firstFinger.getLongitude(), + secondFinger.getLatitude(), secondFinger.getLongitude()); + needNewLatLon = false; + } + } else if (mode == RulerMode.FIRST) { Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation(); LatLon centerLoc = map.getMapLocation(); - OsmandMapTileView view = map.getMapView(); - - if (view.isMultiTouch()) { - if (needNewLatLon) { - float x1 = view.getFirstTouchPointX(); - float y1 = view.getFirstTouchPointY(); - float x2 = view.getSecondTouchPointX(); - float y2 = view.getSecondTouchPointY(); - LatLon firstFinger = view.getCurrentRotatedTileBox().getLatLonFromPixel(x1, y1); - LatLon secondFinger = view.getCurrentRotatedTileBox().getLatLonFromPixel(x2, y2); - setDistanceText(firstFinger.getLatitude(), firstFinger.getLongitude(), - secondFinger.getLatitude(), secondFinger.getLongitude()); - needNewLatLon = false; - } - } else if (currentLoc != null && centerLoc != null) { + if (currentLoc != null && centerLoc != null) { setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(), centerLoc.getLatitude(), centerLoc.getLongitude()); needNewLatLon = true; - } else { - setText(title, null); - needNewLatLon = true; } + } else { + setText(title, null); + needNewLatLon = true; } if (mode != cacheMode) { cacheMode = mode; From 8f8a7a9169dc73d4f026eaec230f929815015b8a Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 16 Jun 2017 13:10:56 +0300 Subject: [PATCH 2/6] Show the distance from the center to the current location in the radius mode; draw a line between the fingers without moving the map --- .../net/osmand/plus/views/OsmandMapTileView.java | 1 + .../views/mapwidgets/MapInfoWidgetsFactory.java | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 80c0b84067..4c24aceaf2 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -1033,6 +1033,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { this.y1 = y1; this.x2 = x2; this.y2 = y2; + multiTouch = true; } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index aa7e228de6..39db38f904 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -185,7 +185,6 @@ public class MapInfoWidgetsFactory { final String title = map.getResources().getString(R.string.map_widget_show_ruler); final TextInfoWidget rulerControl = new TextInfoWidget(map) { boolean needNewLatLon; - RulerMode cacheMode = map.getMyApplication().getSettings().RULER_MODE.get(); @Override public boolean updateInfo(DrawSettings drawSettings) { @@ -204,26 +203,19 @@ public class MapInfoWidgetsFactory { secondFinger.getLatitude(), secondFinger.getLongitude()); needNewLatLon = false; } - } else if (mode == RulerMode.FIRST) { + } else if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) { Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation(); LatLon centerLoc = map.getMapLocation(); if (currentLoc != null && centerLoc != null) { setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(), centerLoc.getLatitude(), centerLoc.getLongitude()); - needNewLatLon = true; } + needNewLatLon = true; } else { setText(title, null); needNewLatLon = true; } - if (mode != cacheMode) { - cacheMode = mode; - setRulerControlIcon(this, mode); - if (mode != RulerMode.FIRST) { - setText(title, null); - } - } return true; } @@ -240,7 +232,6 @@ public class MapInfoWidgetsFactory { rulerControl.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - rulerControl.setText(title, null); final RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get(); RulerMode newMode = RulerMode.FIRST; if (mode == RulerMode.FIRST) { From 11e1fab9fef39fd90f45f62ea66b743e7af67c32 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 16 Jun 2017 16:40:25 +0300 Subject: [PATCH 3/6] Don't draw a line far beyond the screen; fix drawing line after double tap --- .../osmand/plus/views/OsmandMapTileView.java | 4 +++- .../osmand/plus/views/RulerControlLayer.java | 24 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 4c24aceaf2..cf87c09767 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -1033,7 +1033,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback { this.y1 = y1; this.x2 = x2; this.y2 = y2; - multiTouch = true; + if (x1 != x2 && y1 != y2) { + multiTouch = true; + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index 3474459826..ba23596476 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -131,9 +131,27 @@ public class RulerControlLayer extends OsmandMapLayer { } private void drawDistance(Canvas canvas, RotatedTileBox tb, QuadPoint center, Location currentLoc) { - int currentLocX = tb.getPixXFromLonNoRot(currentLoc.getLongitude()); - int currentLocY = tb.getPixYFromLatNoRot(currentLoc.getLatitude()); - canvas.drawLine(currentLocX, currentLocY, center.x, center.y, lineAttrs.paint); + int currX = tb.getPixXFromLonNoRot(currentLoc.getLongitude()); + int currY = tb.getPixYFromLatNoRot(currentLoc.getLatitude()); + int width = tb.getPixWidth(); + int height = tb.getPixHeight(); + + if (currX < 0 || currY < 0 || currX > width || currY > height) { + float x = (currX + center.x) / 2; + float y = (currY + center.y) / 2; + + while (true) { + if (x < 0 || y < 0 || x > width || y > height) { + currX = (int) x; + currY = (int) y; + } else { + break; + } + x = (x + center.x) / 2; + y = (y + center.y) / 2; + } + } + canvas.drawLine(currX, currY, center.x, center.y, lineAttrs.paint); } private void updateData(RotatedTileBox tb, QuadPoint center) { From bfbb048b8eb4a879d062ae3896c67b845701631e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 16 Jun 2017 18:05:20 +0300 Subject: [PATCH 4/6] Add small improvements to "draw a line between the fingers without moving the map" --- OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index cf87c09767..01d9a2b918 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -1034,6 +1034,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { this.x2 = x2; this.y2 = y2; if (x1 != x2 && y1 != y2) { + firstTouchPointX = x1; + firstTouchPointY = y1; + secondTouchPointX = x2; + secondTouchPointY = y2; multiTouch = true; } } From 8ae7c068775fef5a0eff46e1008dec5b93f39176 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 16 Jun 2017 18:36:53 +0300 Subject: [PATCH 5/6] Fix the line hang after the navigation drawer appears --- .../osmand/plus/activities/MapActivity.java | 21 +++++++++++++++++++ .../osmand/plus/views/OsmandMapTileView.java | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 689bfa3640..23a586da57 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -287,6 +287,27 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven mapActions.updateDrawerMenu(); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() { + @Override + public void onDrawerSlide(View drawerView, float slideOffset) { + mapView.setMultiTouch(false); + } + + @Override + public void onDrawerOpened(View drawerView) { + + } + + @Override + public void onDrawerClosed(View drawerView) { + + } + + @Override + public void onDrawerStateChanged(int newState) { + + } + }); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); screenOffReceiver = new ScreenOffReceiver(); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 01d9a2b918..2f82836d56 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -331,6 +331,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { return multiTouch; } + public void setMultiTouch(boolean multiTouch) { + this.multiTouch = multiTouch; + } + public void setIntZoom(int zoom) { zoom = zoom > getMaxZoom() ? getMaxZoom() : zoom; zoom = zoom < getMinZoom() ? getMinZoom() : zoom; From ad2a450d091bf0dac9d350ed3149d48351fbc502 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 18 Jun 2017 00:02:19 +0300 Subject: [PATCH 6/6] Add small fixes --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 10 ++++++++-- .../src/net/osmand/plus/views/OsmandMapTileView.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 23a586da57..ad848835d1 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -186,6 +186,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven private boolean mIsDestroyed = false; private InAppHelper inAppHelper; + private DrawerLayout.DrawerListener drawerListener; + @Override public void onCreate(Bundle savedInstanceState) { long tm = System.currentTimeMillis(); @@ -287,7 +289,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven mapActions.updateDrawerMenu(); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() { + drawerListener = new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { mapView.setMultiTouch(false); @@ -307,7 +309,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven public void onDrawerStateChanged(int newState) { } - }); + }; + drawerLayout.addDrawerListener(drawerListener); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); screenOffReceiver = new ScreenOffReceiver(); @@ -999,6 +1002,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven if (inAppHelper != null) { inAppHelper.stop(); } + if (drawerLayout != null) { + drawerLayout.removeDrawerListener(drawerListener); + } mIsDestroyed = true; } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 2f82836d56..6e7e8efeb1 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -1037,7 +1037,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { this.y1 = y1; this.x2 = x2; this.y2 = y2; - if (x1 != x2 && y1 != y2) { + if (x1 != x2 || y1 != y2) { firstTouchPointX = x1; firstTouchPointY = y1; secondTouchPointX = x2;