Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-07-11 17:50:23 +02:00
commit c6d645b710
3 changed files with 85 additions and 42 deletions

View file

@ -334,10 +334,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
return wasZoomInMultiTouch; return wasZoomInMultiTouch;
} }
public void setWasZoomInMultiTouch(boolean wasZoomInMultiTouch) {
this.wasZoomInMultiTouch = wasZoomInMultiTouch;
}
public boolean mapGestureAllowed(OsmandMapLayer.MapGestureType type) { public boolean mapGestureAllowed(OsmandMapLayer.MapGestureType type) {
for (OsmandMapLayer layer : layers) { for (OsmandMapLayer layer : layers) {
if (!layer.isMapGestureAllowed(type)) { if (!layer.isMapGestureAllowed(type)) {
@ -1128,6 +1124,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
float calcRotate = calc.getRotate() + angle; float calcRotate = calc.getRotate() + angle;
calc.setRotate(calcRotate); calc.setRotate(calcRotate);
calc.setZoomAndAnimation(initialViewport.getZoom(), dz, initialViewport.getZoomFloatPart()); calc.setZoomAndAnimation(initialViewport.getZoom(), dz, initialViewport.getZoomFloatPart());
if (multiTouch) {
wasZoomInMultiTouch = true;
}
final QuadPoint cp = initialViewport.getCenterPixelPoint(); final QuadPoint cp = initialViewport.getCenterPixelPoint();
// Keep zoom center fixed or flexible // Keep zoom center fixed or flexible

View file

@ -3,13 +3,13 @@ package net.osmand.plus.views;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
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.Path; import android.graphics.Path;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import net.osmand.Location; import net.osmand.Location;
@ -42,6 +42,7 @@ public class RulerControlLayer extends OsmandMapLayer {
private int radius; private int radius;
private double roundedDist; private double roundedDist;
private boolean showTwoFingersDistance; private boolean showTwoFingersDistance;
private boolean showDistBetweenFingerAndLocation;
private QuadPoint cacheCenter; private QuadPoint cacheCenter;
private int cacheIntZoom; private int cacheIntZoom;
@ -52,12 +53,14 @@ public class RulerControlLayer extends OsmandMapLayer {
private Path distancePath; private Path distancePath;
private TIntArrayList tx; private TIntArrayList tx;
private TIntArrayList ty; private TIntArrayList ty;
private LatLon singleTouchPointLatLon;
private Bitmap centerIconDay; private Bitmap centerIconDay;
private Bitmap centerIconNight; private Bitmap centerIconNight;
private Paint bitmapPaint; private Paint bitmapPaint;
private RenderingLineAttributes lineAttrs; private RenderingLineAttributes lineAttrs;
private RenderingLineAttributes circleAttrs; private RenderingLineAttributes circleAttrs;
private RenderingLineAttributes circleAttrsAlt;
private Handler handler; private Handler handler;
@ -69,6 +72,14 @@ public class RulerControlLayer extends OsmandMapLayer {
return showTwoFingersDistance; return showTwoFingersDistance;
} }
public boolean isShowDistBetweenFingerAndLocation() {
return showDistBetweenFingerAndLocation;
}
public LatLon getSingleTouchPointLatLon() {
return singleTouchPointLatLon;
}
@Override @Override
public void initLayer(final OsmandMapTileView view) { public void initLayer(final OsmandMapTileView view) {
app = mapActivity.getMyApplication(); app = mapActivity.getMyApplication();
@ -91,14 +102,15 @@ public class RulerControlLayer extends OsmandMapLayer {
lineAttrs = new RenderingLineAttributes("rulerLine"); lineAttrs = new RenderingLineAttributes("rulerLine");
float textSize = TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density;
circleAttrs = new RenderingLineAttributes("rulerCircle"); circleAttrs = new RenderingLineAttributes("rulerCircle");
circleAttrs.paint.setStrokeWidth(2); circleAttrs.paint2.setTextSize(textSize);
circleAttrs.paint2.setTextSize(TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density); circleAttrs.paint3.setTextSize(textSize);
circleAttrs.paint3.setColor(Color.WHITE);
circleAttrs.paint3.setStrokeWidth(6); circleAttrsAlt = new RenderingLineAttributes("rulerCircleAlt");
circleAttrs.paint3.setTextSize(TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density); circleAttrsAlt.paint2.setTextSize(textSize);
circleAttrs.shadowPaint.setStrokeWidth(6); circleAttrsAlt.paint3.setTextSize(textSize);
circleAttrs.shadowPaint.setColor(Color.WHITE);
handler = new Handler() { handler = new Handler() {
@Override @Override
@ -117,23 +129,43 @@ public class RulerControlLayer extends OsmandMapLayer {
} }
} }
@Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
showDistBetweenFingerAndLocation = true;
singleTouchPointLatLon = tileBox.getLatLonFromPixel(event.getX(), event.getY());
} else if (event.getAction() == MotionEvent.ACTION_UP) {
showDistBetweenFingerAndLocation = false;
}
return false;
}
@Override @Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (rulerModeOn()) { if (rulerModeOn()) {
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);
circleAttrsAlt.updatePaints(view, settings, tb);
circleAttrsAlt.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 (view.isMultiTouch() && view.isZooming()) { if (view.isMultiTouch()) {
view.setWasZoomInMultiTouch(true); showDistBetweenFingerAndLocation = false;
} else if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) { } else if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) {
cacheMultiTouchEndTime = view.getMultiTouchEndTime(); cacheMultiTouchEndTime = view.getMultiTouchEndTime();
refreshMapDelayed(); refreshMapDelayed();
} }
showTwoFingersDistance = !view.isWasZoomInMultiTouch() && !view.isZooming() && (view.isMultiTouch() || System.currentTimeMillis() - cacheMultiTouchEndTime < DELAY); showTwoFingersDistance = !view.isWasZoomInMultiTouch() && !tb.isZoomAnimated() &&
if (showTwoFingersDistance) { (view.isMultiTouch() || System.currentTimeMillis() - cacheMultiTouchEndTime < DELAY);
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
if (showDistBetweenFingerAndLocation && currentLoc != null) {
float x = tb.getPixXFromLonNoRot(singleTouchPointLatLon.getLongitude());
float y = tb.getPixYFromLatNoRot(singleTouchPointLatLon.getLatitude());
drawDistBetweenFingerAndLocation(canvas, tb, x, y, currentLoc, settings.isNightMode());
} else if (showTwoFingersDistance) {
LatLon firstTouchPoint = view.getFirstTouchPointLatLon(); LatLon firstTouchPoint = view.getFirstTouchPointLatLon();
LatLon secondTouchPoint = view.getSecondTouchPointLatLon(); LatLon secondTouchPoint = view.getSecondTouchPointLatLon();
float x1 = tb.getPixXFromLonNoRot(firstTouchPoint.getLongitude()); float x1 = tb.getPixXFromLonNoRot(firstTouchPoint.getLongitude());
@ -141,18 +173,18 @@ public class RulerControlLayer extends OsmandMapLayer {
float x2 = tb.getPixXFromLonNoRot(secondTouchPoint.getLongitude()); float x2 = tb.getPixXFromLonNoRot(secondTouchPoint.getLongitude());
float y2 = tb.getPixYFromLatNoRot(secondTouchPoint.getLatitude()); float y2 = tb.getPixYFromLatNoRot(secondTouchPoint.getLatitude());
drawFingerDistance(canvas, x1, y1, x2, y2, settings.isNightMode()); drawFingerDistance(canvas, x1, y1, x2, y2, settings.isNightMode());
} else if (mode == RulerMode.FIRST) {
drawCenterIcon(canvas, tb, center, settings.isNightMode());
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
if (currentLoc != null) {
drawDistance(canvas, tb, center, currentLoc);
} }
} if (mode == RulerMode.FIRST || 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);
RenderingLineAttributes attrs;
if (mode == RulerMode.FIRST) {
attrs = circleAttrs;
} else {
attrs = circleAttrsAlt;
}
for (int i = 1; i <= cacheDistances.size(); i++) { for (int i = 1; i <= cacheDistances.size(); i++) {
drawCircle(canvas, tb, i, center); drawCircle(canvas, tb, i, center, attrs);
} }
} }
} }
@ -195,7 +227,8 @@ public class RulerControlLayer extends OsmandMapLayer {
canvas.rotate(tb.getRotate(), center.x, center.y); canvas.rotate(tb.getRotate(), center.x, center.y);
} }
private void drawDistance(Canvas canvas, RotatedTileBox tb, QuadPoint center, Location currentLoc) { private void drawDistBetweenFingerAndLocation(Canvas canvas, RotatedTileBox tb, float x, float y,
Location currentLoc, boolean nightMode) {
int currX = tb.getPixXFromLonNoRot(currentLoc.getLongitude()); int currX = tb.getPixXFromLonNoRot(currentLoc.getLongitude());
int currY = tb.getPixYFromLatNoRot(currentLoc.getLatitude()); int currY = tb.getPixYFromLatNoRot(currentLoc.getLatitude());
distancePath.reset(); distancePath.reset();
@ -204,11 +237,12 @@ public class RulerControlLayer extends OsmandMapLayer {
tx.add(currX); tx.add(currX);
ty.add(currY); ty.add(currY);
tx.add((int) center.x); tx.add((int) x);
ty.add((int) center.y); ty.add((int) y);
calculatePath(tb, tx, ty, distancePath); calculatePath(tb, tx, ty, distancePath);
canvas.drawPath(distancePath, lineAttrs.paint); canvas.drawPath(distancePath, lineAttrs.paint);
drawFingerTouchIcon(canvas, x, y, nightMode);
} }
private void updateData(RotatedTileBox tb, QuadPoint center) { private void updateData(RotatedTileBox tb, QuadPoint center) {
@ -268,11 +302,12 @@ 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,
if (!mapActivity.getMapView().isZooming()) { RenderingLineAttributes attrs) {
if (!tb.isZoomAnimated()) {
Rect bounds = new Rect(); Rect bounds = new Rect();
String text = cacheDistances.get(circleNumber - 1); String text = cacheDistances.get(circleNumber - 1);
circleAttrs.paint2.getTextBounds(text, 0, text.length(), bounds); attrs.paint2.getTextBounds(text, 0, text.length(), bounds);
// coords of left or top text // coords of left or top text
float x1 = 0; float x1 = 0;
@ -294,12 +329,12 @@ public class RulerControlLayer extends OsmandMapLayer {
} }
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, attrs.shadowPaint);
canvas.drawCircle(center.x, center.y, radius * circleNumber, circleAttrs.paint); canvas.drawCircle(center.x, center.y, radius * circleNumber, attrs.paint);
canvas.drawText(text, x1, y1, circleAttrs.paint3); canvas.drawText(text, x1, y1, attrs.paint3);
canvas.drawText(text, x1, y1, circleAttrs.paint2); canvas.drawText(text, x1, y1, attrs.paint2);
canvas.drawText(text, x2, y2, circleAttrs.paint3); canvas.drawText(text, x2, y2, attrs.paint3);
canvas.drawText(text, x2, y2, circleAttrs.paint2); canvas.drawText(text, x2, y2, attrs.paint2);
canvas.rotate(tb.getRotate(), center.x, center.y); canvas.rotate(tb.getRotate(), center.x, center.y);
} }
} }

View file

@ -188,22 +188,33 @@ public class MapInfoWidgetsFactory {
RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer(); RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();
LatLon cacheFirstTouchPoint = new LatLon(0, 0); LatLon cacheFirstTouchPoint = new LatLon(0, 0);
LatLon cacheSecondTouchPoint = new LatLon(0, 0); LatLon cacheSecondTouchPoint = new LatLon(0, 0);
LatLon cacheSingleTouchPoint = new LatLon(0, 0);
boolean fingerAndLocDistWasShown;
@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();
OsmandMapTileView view = map.getMapView(); OsmandMapTileView view = map.getMapView();
Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
if (rulerLayer.isShowTwoFingersDistance()) { if (rulerLayer.isShowDistBetweenFingerAndLocation() && currentLoc != null) {
if (!cacheSingleTouchPoint.equals(rulerLayer.getSingleTouchPointLatLon())) {
cacheSingleTouchPoint = rulerLayer.getSingleTouchPointLatLon();
setDistanceText(cacheSingleTouchPoint.getLatitude(), cacheSingleTouchPoint.getLongitude(),
currentLoc.getLatitude(), currentLoc.getLongitude());
fingerAndLocDistWasShown = true;
}
} else if (rulerLayer.isShowTwoFingersDistance()) {
if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) || if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) ||
!cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon())) { !cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon()) ||
fingerAndLocDistWasShown) {
cacheFirstTouchPoint = view.getFirstTouchPointLatLon(); cacheFirstTouchPoint = view.getFirstTouchPointLatLon();
cacheSecondTouchPoint = view.getSecondTouchPointLatLon(); cacheSecondTouchPoint = view.getSecondTouchPointLatLon();
setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(), setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(),
cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude()); cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude());
fingerAndLocDistWasShown = false;
} }
} else if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) { } else if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
LatLon centerLoc = map.getMapLocation(); LatLon centerLoc = map.getMapLocation();
if (currentLoc != null && centerLoc != null) { if (currentLoc != null && centerLoc != null) {
@ -258,9 +269,7 @@ public class MapInfoWidgetsFactory {
} }
private void setRulerControlIcon(TextInfoWidget rulerControl, RulerMode mode) { private void setRulerControlIcon(TextInfoWidget rulerControl, RulerMode mode) {
if (mode == RulerMode.FIRST) { if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
rulerControl.setIcons(R.drawable.widget_ruler_location_day, R.drawable.widget_ruler_location_night);
} else if (mode == RulerMode.SECOND) {
rulerControl.setIcons(R.drawable.widget_ruler_circle_day, R.drawable.widget_ruler_circle_night); rulerControl.setIcons(R.drawable.widget_ruler_circle_day, R.drawable.widget_ruler_circle_night);
} else { } else {
rulerControl.setIcons(R.drawable.widget_hidden_day, R.drawable.widget_hidden_night); rulerControl.setIcons(R.drawable.widget_hidden_day, R.drawable.widget_hidden_night);