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)
This commit is contained in:
parent
7db024957e
commit
be357ef06a
2 changed files with 60 additions and 57 deletions
|
@ -7,6 +7,7 @@ import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Paint.Style;
|
import android.graphics.Paint.Style;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.data.QuadPoint;
|
import net.osmand.data.QuadPoint;
|
||||||
|
@ -25,6 +26,7 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
private final MapActivity mapActivity;
|
private final MapActivity mapActivity;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private OsmandMapTileView view;
|
private OsmandMapTileView view;
|
||||||
|
private View rightWidgetsPanel;
|
||||||
|
|
||||||
private TextSide textSide;
|
private TextSide textSide;
|
||||||
private int maxRadiusInDp;
|
private int maxRadiusInDp;
|
||||||
|
@ -55,6 +57,7 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
cacheDistances = new ArrayList<>();
|
cacheDistances = new ArrayList<>();
|
||||||
cacheCenter = new QuadPoint();
|
cacheCenter = new QuadPoint();
|
||||||
maxRadiusInDp = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_radius);
|
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);
|
centerIconDay = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_day);
|
||||||
centerIconNight = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_night);
|
centerIconNight = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center_night);
|
||||||
|
@ -78,28 +81,28 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
|
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);
|
lineAttrs.updatePaints(view, settings, tb);
|
||||||
circleAttrs.updatePaints(view, settings, tb);
|
circleAttrs.updatePaints(view, settings, tb);
|
||||||
circleAttrs.paint2.setStyle(Style.FILL);
|
circleAttrs.paint2.setStyle(Style.FILL);
|
||||||
final QuadPoint center = tb.getCenterPixelPoint();
|
final QuadPoint center = tb.getCenterPixelPoint();
|
||||||
final RulerMode mode = app.getSettings().RULER_MODE.get();
|
final RulerMode mode = app.getSettings().RULER_MODE.get();
|
||||||
|
|
||||||
if (mode == RulerMode.FIRST) {
|
if (view.isMultiTouch()) {
|
||||||
if (view.isMultiTouch()) {
|
float x1 = view.getFirstTouchPointX();
|
||||||
float x1 = view.getFirstTouchPointX();
|
float y1 = view.getFirstTouchPointY();
|
||||||
float y1 = view.getFirstTouchPointY();
|
float x2 = view.getSecondTouchPointX();
|
||||||
float x2 = view.getSecondTouchPointX();
|
float y2 = view.getSecondTouchPointY();
|
||||||
float y2 = view.getSecondTouchPointY();
|
drawFingerDistance(canvas, tb, center, x1, y1, x2, y2);
|
||||||
drawFingerDistance(canvas, tb, center, x1, y1, x2, y2);
|
} else if (mode == RulerMode.FIRST) {
|
||||||
} else {
|
drawCenterIcon(canvas, tb, center, settings.isNightMode());
|
||||||
drawCenterIcon(canvas, tb, center, settings.isNightMode());
|
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
|
||||||
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
|
if (currentLoc != null) {
|
||||||
if (currentLoc != null) {
|
drawDistance(canvas, tb, center, currentLoc);
|
||||||
drawDistance(canvas, tb, center, currentLoc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (mode == RulerMode.SECOND) {
|
}
|
||||||
|
if (mode == RulerMode.SECOND) {
|
||||||
drawCenterIcon(canvas, tb, center, settings.isNightMode());
|
drawCenterIcon(canvas, tb, center, settings.isNightMode());
|
||||||
updateData(tb, center);
|
updateData(tb, center);
|
||||||
for (int i = 1; i <= cacheDistances.size(); i++) {
|
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) {
|
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()) {
|
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.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.shadowPaint);
|
||||||
canvas.drawCircle(center.x, center.y, radius * circleNumber, circleAttrs.paint);
|
canvas.drawCircle(center.x, center.y, radius * circleNumber, circleAttrs.paint);
|
||||||
|
|
|
@ -190,32 +190,32 @@ public class MapInfoWidgetsFactory {
|
||||||
@Override
|
@Override
|
||||||
public boolean updateInfo(DrawSettings drawSettings) {
|
public boolean updateInfo(DrawSettings drawSettings) {
|
||||||
RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get();
|
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();
|
Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||||
LatLon centerLoc = map.getMapLocation();
|
LatLon centerLoc = map.getMapLocation();
|
||||||
OsmandMapTileView view = map.getMapView();
|
|
||||||
|
|
||||||
|
if (currentLoc != null && centerLoc != null) {
|
||||||
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) {
|
|
||||||
setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(),
|
setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(),
|
||||||
centerLoc.getLatitude(), centerLoc.getLongitude());
|
centerLoc.getLatitude(), centerLoc.getLongitude());
|
||||||
needNewLatLon = true;
|
needNewLatLon = true;
|
||||||
} else {
|
|
||||||
setText(title, null);
|
|
||||||
needNewLatLon = true;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setText(title, null);
|
||||||
|
needNewLatLon = true;
|
||||||
}
|
}
|
||||||
if (mode != cacheMode) {
|
if (mode != cacheMode) {
|
||||||
cacheMode = mode;
|
cacheMode = mode;
|
||||||
|
|
Loading…
Reference in a new issue