Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch
This commit is contained in:
commit
96cdaad5bc
1 changed files with 65 additions and 45 deletions
|
@ -5,6 +5,8 @@ import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Paint.Style;
|
import android.graphics.Paint.Style;
|
||||||
|
import android.graphics.Path;
|
||||||
|
import android.graphics.PathMeasure;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
@ -22,15 +24,18 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.RulerMode;
|
import net.osmand.plus.OsmandSettings.RulerMode;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
|
|
||||||
public class RulerControlLayer extends OsmandMapLayer {
|
public class RulerControlLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
|
private static final int VERTICAL_OFFSET = 10;
|
||||||
private static final long DRAW_TIME = 2000;
|
private static final long DRAW_TIME = 2000;
|
||||||
private static final long DELAY_BEFORE_DRAW = 500;
|
private static final long DELAY_BEFORE_DRAW = 500;
|
||||||
private static final int TEXT_SIZE = 14;
|
private static final int TEXT_SIZE = 14;
|
||||||
private static final int MAX_ITERATIONS = 50;
|
|
||||||
|
|
||||||
private final MapActivity mapActivity;
|
private final MapActivity mapActivity;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
@ -62,6 +67,10 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
private boolean touched;
|
private boolean touched;
|
||||||
private boolean wasZoom;
|
private boolean wasZoom;
|
||||||
|
|
||||||
|
private TIntArrayList tx = new TIntArrayList();
|
||||||
|
private TIntArrayList ty = new TIntArrayList();
|
||||||
|
private Path linePath = new Path();
|
||||||
|
|
||||||
private Bitmap centerIconDay;
|
private Bitmap centerIconDay;
|
||||||
private Bitmap centerIconNight;
|
private Bitmap centerIconNight;
|
||||||
private Paint bitmapPaint;
|
private Paint bitmapPaint;
|
||||||
|
@ -202,17 +211,9 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
drawCenterIcon(canvas, tb, center, settings.isNightMode(), mode);
|
drawCenterIcon(canvas, tb, center, settings.isNightMode(), mode);
|
||||||
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
|
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
|
||||||
if (showDistBetweenFingerAndLocation && currentLoc != null) {
|
if (showDistBetweenFingerAndLocation && currentLoc != null) {
|
||||||
float x = tb.getPixXFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
|
drawDistBetweenFingerAndLocation(canvas, tb, currentLoc, settings.isNightMode());
|
||||||
float y = tb.getPixYFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude());
|
|
||||||
drawDistBetweenFingerAndLocation(canvas, tb, x, y, currentLoc, settings.isNightMode());
|
|
||||||
} else if (showTwoFingersDistance) {
|
} else if (showTwoFingersDistance) {
|
||||||
LatLon firstTouchPoint = view.getFirstTouchPointLatLon();
|
drawTwoFingersDistance(canvas, tb, view.getFirstTouchPointLatLon(), view.getSecondTouchPointLatLon(), settings.isNightMode());
|
||||||
LatLon secondTouchPoint = view.getSecondTouchPointLatLon();
|
|
||||||
float x1 = tb.getPixXFromLonNoRot(firstTouchPoint.getLongitude());
|
|
||||||
float y1 = tb.getPixYFromLatNoRot(firstTouchPoint.getLatitude());
|
|
||||||
float x2 = tb.getPixXFromLonNoRot(secondTouchPoint.getLongitude());
|
|
||||||
float y2 = tb.getPixYFromLatNoRot(secondTouchPoint.getLatitude());
|
|
||||||
drawTwoFingersDistance(canvas, x1, y1, x2, y2, settings.isNightMode());
|
|
||||||
}
|
}
|
||||||
if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
|
if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
|
||||||
updateData(tb, center);
|
updateData(tb, center);
|
||||||
|
@ -238,10 +239,41 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
handler.sendEmptyMessageDelayed(0, DRAW_TIME + 50);
|
handler.sendEmptyMessageDelayed(0, DRAW_TIME + 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawTwoFingersDistance(Canvas canvas, float x1, float y1, float x2, float y2, boolean nightMode) {
|
private void drawTwoFingersDistance(Canvas canvas, RotatedTileBox tb, LatLon firstTouch, LatLon secondTouch, boolean nightMode) {
|
||||||
canvas.drawLine(x1, y1, x2, y2, lineAttrs.paint);
|
float x1 = tb.getPixXFromLonNoRot(firstTouch.getLongitude());
|
||||||
|
float y1 = tb.getPixYFromLatNoRot(firstTouch.getLatitude());
|
||||||
|
float x2 = tb.getPixXFromLonNoRot(secondTouch.getLongitude());
|
||||||
|
float y2 = tb.getPixYFromLatNoRot(secondTouch.getLatitude());
|
||||||
|
|
||||||
|
Path path = new Path();
|
||||||
|
path.moveTo(x1, y1);
|
||||||
|
path.lineTo(x2, y2);
|
||||||
|
|
||||||
|
canvas.drawPath(path, lineAttrs.paint);
|
||||||
drawFingerTouchIcon(canvas, x1, y1, nightMode);
|
drawFingerTouchIcon(canvas, x1, y1, nightMode);
|
||||||
drawFingerTouchIcon(canvas, x2, y2, nightMode);
|
drawFingerTouchIcon(canvas, x2, y2, nightMode);
|
||||||
|
|
||||||
|
String text = OsmAndFormatter.getFormattedDistance((float) MapUtils.getDistance(firstTouch, secondTouch), app);
|
||||||
|
drawTextOnCenterOfPath(canvas, x1, x2, path, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawTextOnCenterOfPath(Canvas canvas, float x1, float x2, Path path, String text) {
|
||||||
|
PathMeasure pm = new PathMeasure(path, false);
|
||||||
|
Rect bounds = new Rect();
|
||||||
|
circleAttrs.paint2.getTextBounds(text, 0, text.length(), bounds);
|
||||||
|
float hOffset = pm.getLength() / 2 - bounds.width() / 2;
|
||||||
|
|
||||||
|
if (x1 >= x2) {
|
||||||
|
float[] pos = new float[2];
|
||||||
|
pm.getPosTan(pm.getLength() / 2, pos, null);
|
||||||
|
canvas.rotate(180, pos[0], pos[1]);
|
||||||
|
canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, circleAttrs.paint3);
|
||||||
|
canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, circleAttrs.paint2);
|
||||||
|
canvas.rotate(-180, pos[0], pos[1]);
|
||||||
|
} else {
|
||||||
|
canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, circleAttrs.paint3);
|
||||||
|
canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, circleAttrs.paint2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawFingerTouchIcon(Canvas canvas, float x, float y, boolean nightMode) {
|
private void drawFingerTouchIcon(Canvas canvas, float x, float y, boolean nightMode) {
|
||||||
|
@ -267,41 +299,29 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
canvas.rotate(tb.getRotate(), center.x, center.y);
|
canvas.rotate(tb.getRotate(), center.x, center.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawDistBetweenFingerAndLocation(Canvas canvas, RotatedTileBox tb, float x, float y,
|
private void drawDistBetweenFingerAndLocation(Canvas canvas, RotatedTileBox tb, Location currLoc, boolean night) {
|
||||||
Location currentLoc, boolean nightMode) {
|
float x = tb.getPixXFromLonNoRot(touchPointLatLon.getLongitude());
|
||||||
int currX = (int) tb.getPixXFromLatLon(currentLoc.getLatitude(), currentLoc.getLongitude());
|
float y = tb.getPixYFromLatNoRot(touchPointLatLon.getLatitude());
|
||||||
int currY = (int) tb.getPixYFromLatLon(currentLoc.getLatitude(), currentLoc.getLongitude());
|
int currX = tb.getPixXFromLonNoRot(currLoc.getLongitude());
|
||||||
int width = tb.getPixWidth();
|
int currY = tb.getPixYFromLatNoRot(currLoc.getLatitude());
|
||||||
int height = tb.getPixHeight();
|
|
||||||
boolean needDraw = true;
|
|
||||||
|
|
||||||
if ((currX < 0 && x == 0) || (currY < 0 && y == 0)
|
linePath.reset();
|
||||||
|| (currX > width && x == width) || (currY > height && y == height)) {
|
tx.reset();
|
||||||
needDraw = false;
|
ty.reset();
|
||||||
} else if (currX < 0 || currY < 0 || currX > width || currY > height) {
|
|
||||||
float xNew = (currX + x) / 2;
|
|
||||||
float yNew = (currY + y) / 2;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
while (count < MAX_ITERATIONS) {
|
tx.add((int) x);
|
||||||
count++;
|
ty.add((int) y);
|
||||||
if (xNew < 0 || yNew < 0 || xNew > width || yNew > height) {
|
tx.add(currX);
|
||||||
currX = (int) xNew;
|
ty.add(currY);
|
||||||
currY = (int) yNew;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
xNew = (xNew + x) / 2;
|
|
||||||
yNew = (yNew + y) / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needDraw) {
|
calculatePath(tb, tx, ty, linePath);
|
||||||
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
|
|
||||||
canvas.drawLine(currX, currY, x, y, lineAttrs.paint);
|
canvas.drawPath(linePath, lineAttrs.paint);
|
||||||
drawFingerTouchIcon(canvas, x, y, nightMode);
|
drawFingerTouchIcon(canvas, x, y, night);
|
||||||
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
|
|
||||||
}
|
float dist = (float) MapUtils.getDistance(touchPointLatLon, currLoc.getLatitude(), currLoc.getLongitude());
|
||||||
|
String text = OsmAndFormatter.getFormattedDistance(dist, app);
|
||||||
|
drawTextOnCenterOfPath(canvas, x, currX, linePath, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateData(RotatedTileBox tb, QuadPoint center) {
|
private void updateData(RotatedTileBox tb, QuadPoint center) {
|
||||||
|
|
Loading…
Reference in a new issue