Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-07-20 16:59:09 +02:00
commit c452c74bde
2 changed files with 46 additions and 26 deletions

View file

@ -173,6 +173,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
private LatLon firstTouchPointLatLon; private LatLon firstTouchPointLatLon;
private LatLon secondTouchPointLatLon; private LatLon secondTouchPointLatLon;
private boolean multiTouch; private boolean multiTouch;
private long multiTouchStartTime;
private long multiTouchEndTime; private long multiTouchEndTime;
private boolean wasZoomInMultiTouch; private boolean wasZoomInMultiTouch;
@ -335,6 +336,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
return multiTouch; return multiTouch;
} }
public long getMultiTouchStartTime() {
return multiTouchStartTime;
}
public long getMultiTouchEndTime() { public long getMultiTouchEndTime() {
return multiTouchEndTime; return multiTouchEndTime;
} }
@ -1076,6 +1081,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
secondTouchPointLatLon = currentViewport.getLatLonFromPixel(x2, y2); secondTouchPointLatLon = currentViewport.getLatLonFromPixel(x2, y2);
multiTouch = true; multiTouch = true;
wasZoomInMultiTouch = false; wasZoomInMultiTouch = false;
multiTouchStartTime = System.currentTimeMillis();
} }
} }

View file

@ -59,8 +59,10 @@ public class RulerControlLayer extends OsmandMapLayer {
private TIntArrayList ty; private TIntArrayList ty;
private LatLon touchPointLatLon; private LatLon touchPointLatLon;
private PointF touchPoint; private PointF touchPoint;
private PointF firstTouchPoint; private long touchStartTime;
private long touchTime; private long touchEndTime;
private boolean touched;
private boolean wasZoom;
private Bitmap centerIconDay; private Bitmap centerIconDay;
private Bitmap centerIconNight; private Bitmap centerIconNight;
@ -98,7 +100,6 @@ public class RulerControlLayer extends OsmandMapLayer {
distancePath = new Path(); distancePath = new Path();
tx = new TIntArrayList(); tx = new TIntArrayList();
ty = new TIntArrayList(); ty = new TIntArrayList();
firstTouchPoint = new PointF();
touchPoint = new PointF(); touchPoint = new PointF();
acceptableTouchRadius = mapActivity.getResources().getDimensionPixelSize(R.dimen.acceptable_touch_radius); acceptableTouchRadius = mapActivity.getResources().getDimensionPixelSize(R.dimen.acceptable_touch_radius);
@ -141,32 +142,29 @@ public class RulerControlLayer extends OsmandMapLayer {
@Override @Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if (rulerModeOn()) { if (rulerModeOn() && !showTwoFingersDistance) {
if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getAction() == MotionEvent.ACTION_DOWN) {
touched = true;
touchOutside = false; touchOutside = false;
firstTouchPoint.set(event.getX(), event.getY()); touchPoint.set(event.getX(), event.getY());
setSingleTouch(event.getX(), event.getY(), tileBox); touchPointLatLon = tileBox.getLatLonFromPixel(event.getX(), event.getY());
} else if (event.getAction() == MotionEvent.ACTION_MOVE) { touchStartTime = System.currentTimeMillis();
double d = Math.sqrt(Math.pow(event.getX() - firstTouchPoint.x, 2) + Math.pow(event.getY() - firstTouchPoint.y, 2)); wasZoom = false;
if (d < acceptableTouchRadius) { } else if (event.getAction() == MotionEvent.ACTION_MOVE && !touchOutside &&
setSingleTouch(event.getX(), event.getY(), tileBox); !(touched && showDistBetweenFingerAndLocation)) {
touchOutside = false; double d = Math.sqrt(Math.pow(event.getX() - touchPoint.x, 2) + Math.pow(event.getY() - touchPoint.y, 2));
} else { if (d > acceptableTouchRadius) {
touchOutside = true; touchOutside = true;
} }
} else if (event.getAction() == MotionEvent.ACTION_UP) { } else if (event.getAction() == MotionEvent.ACTION_UP) {
touched = false;
touchEndTime = System.currentTimeMillis();
refreshMapDelayed(); refreshMapDelayed();
} }
} }
return false; return false;
} }
private void setSingleTouch(float x, float y, RotatedTileBox tb) {
touchTime = System.currentTimeMillis();
touchPoint.set(x, y);
touchPointLatLon = tb.getLatLonFromPixel(x, y);
}
@Override @Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
if (rulerModeOn()) { if (rulerModeOn()) {
@ -177,17 +175,32 @@ public class RulerControlLayer extends OsmandMapLayer {
circleAttrsAlt.paint2.setStyle(Style.FILL); 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();
final long currentTime = System.currentTimeMillis();
if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) { if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) {
cacheMultiTouchEndTime = view.getMultiTouchEndTime(); cacheMultiTouchEndTime = view.getMultiTouchEndTime();
refreshMapDelayed(); refreshMapDelayed();
} }
boolean wasNotZoom = !view.isWasZoomInMultiTouch() && !tb.isZoomAnimated(); if (touched && view.isMultiTouch()) {
showTwoFingersDistance = wasNotZoom && touched = false;
(view.isMultiTouch() || System.currentTimeMillis() - cacheMultiTouchEndTime < DRAW_TIME); touchEndTime = currentTime;
showDistBetweenFingerAndLocation = !showTwoFingersDistance && wasNotZoom && !view.isMultiTouch() && }
!touchOutside && System.currentTimeMillis() - touchTime > DELAY_BEFORE_DRAW && if (tb.isZoomAnimated()) {
System.currentTimeMillis() - touchTime < DRAW_TIME; wasZoom = true;
}
showTwoFingersDistance = !tb.isZoomAnimated() &&
!view.isWasZoomInMultiTouch() &&
currentTime - view.getMultiTouchStartTime() > DELAY_BEFORE_DRAW &&
(view.isMultiTouch() || currentTime - cacheMultiTouchEndTime < DRAW_TIME);
showDistBetweenFingerAndLocation = !wasZoom &&
!showTwoFingersDistance &&
!view.isMultiTouch() &&
!touchOutside &&
touchStartTime - view.getMultiTouchStartTime() > DELAY_BEFORE_DRAW &&
currentTime - touchStartTime > DELAY_BEFORE_DRAW &&
(touched || currentTime - touchEndTime < DRAW_TIME);
drawCenterIcon(canvas, tb, center, settings.isNightMode(), mode); drawCenterIcon(canvas, tb, center, settings.isNightMode(), mode);
Location currentLoc = app.getLocationProvider().getLastKnownLocation(); Location currentLoc = app.getLocationProvider().getLastKnownLocation();
@ -202,7 +215,7 @@ public class RulerControlLayer extends OsmandMapLayer {
float y1 = tb.getPixYFromLatNoRot(firstTouchPoint.getLatitude()); float y1 = tb.getPixYFromLatNoRot(firstTouchPoint.getLatitude());
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()); 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);
@ -228,7 +241,7 @@ public class RulerControlLayer extends OsmandMapLayer {
handler.sendEmptyMessageDelayed(0, DRAW_TIME + 50); handler.sendEmptyMessageDelayed(0, DRAW_TIME + 50);
} }
private void drawFingerDistance(Canvas canvas, float x1, float y1, float x2, float y2, boolean nightMode) { private void drawTwoFingersDistance(Canvas canvas, float x1, float y1, float x2, float y2, boolean nightMode) {
canvas.drawLine(x1, y1, x2, y2, lineAttrs.paint); canvas.drawLine(x1, y1, x2, y2, lineAttrs.paint);
drawFingerTouchIcon(canvas, x1, y1, nightMode); drawFingerTouchIcon(canvas, x1, y1, nightMode);
drawFingerTouchIcon(canvas, x2, y2, nightMode); drawFingerTouchIcon(canvas, x2, y2, nightMode);
@ -272,6 +285,7 @@ public class RulerControlLayer extends OsmandMapLayer {
calculatePath(tb, tx, ty, distancePath); calculatePath(tb, tx, ty, distancePath);
canvas.drawPath(distancePath, lineAttrs.paint); canvas.drawPath(distancePath, lineAttrs.paint);
// canvas.drawLine(currX, currY, x, y, lineAttrs.paint);
drawFingerTouchIcon(canvas, x, y, nightMode); drawFingerTouchIcon(canvas, x, y, nightMode);
} }