Show points by location, not by pixels
This commit is contained in:
parent
143297bee9
commit
bcfce50305
4 changed files with 28 additions and 62 deletions
|
@ -33,8 +33,6 @@ public class MultiTouchSupport {
|
|||
|
||||
public void onGestureInit(float x1, float y1, float x2, float y2);
|
||||
|
||||
public void onActionPointerDownOrMove(float x1, float y1, float x2, float y2);
|
||||
|
||||
public void onActionPointerUp();
|
||||
|
||||
public void onActionCancel();
|
||||
|
@ -111,9 +109,7 @@ public class MultiTouchSupport {
|
|||
angleDefined = true;
|
||||
angle = (float) (Math.atan2(y2 - y1, x2 -x1) * 180 / Math.PI);
|
||||
}
|
||||
if (actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_MOVE) {
|
||||
listener.onActionPointerDownOrMove(x1, y1, x2, y2);
|
||||
} else if (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_UP) {
|
||||
if (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_POINTER_UP) {
|
||||
listener.onActionPointerUp();
|
||||
}
|
||||
if (actionCode == ACTION_POINTER_DOWN) {
|
||||
|
|
|
@ -161,10 +161,8 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
private boolean afterDoubleTap = false;
|
||||
private boolean wasMapLinkedBeforeGesture = false;
|
||||
|
||||
private float firstTouchPointX;
|
||||
private float firstTouchPointY;
|
||||
private float secondTouchPointX;
|
||||
private float secondTouchPointY;
|
||||
private LatLon firstTouchPointLatLon;
|
||||
private LatLon secondTouchPointLatLon;
|
||||
private boolean multiTouch;
|
||||
private long multiTouchEndTime;
|
||||
private boolean wasZoomInMultiTouch;
|
||||
|
@ -313,20 +311,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
}
|
||||
|
||||
// ///////////////////////// NON UI PART (could be extracted in common) /////////////////////////////
|
||||
public float getFirstTouchPointX() {
|
||||
return firstTouchPointX;
|
||||
public LatLon getFirstTouchPointLatLon() {
|
||||
return firstTouchPointLatLon;
|
||||
}
|
||||
|
||||
public float getFirstTouchPointY() {
|
||||
return firstTouchPointY;
|
||||
}
|
||||
|
||||
public float getSecondTouchPointX() {
|
||||
return secondTouchPointX;
|
||||
}
|
||||
|
||||
public float getSecondTouchPointY() {
|
||||
return secondTouchPointY;
|
||||
public LatLon getSecondTouchPointLatLon() {
|
||||
return secondTouchPointLatLon;
|
||||
}
|
||||
|
||||
public boolean isMultiTouch() {
|
||||
|
@ -1048,24 +1038,13 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
if (x1 != x2 || y1 != y2) {
|
||||
firstTouchPointX = x1;
|
||||
firstTouchPointY = y1;
|
||||
secondTouchPointX = x2;
|
||||
secondTouchPointY = y2;
|
||||
firstTouchPointLatLon = currentViewport.getLatLonFromPixel(x1, y1);
|
||||
secondTouchPointLatLon = currentViewport.getLatLonFromPixel(x2, y2);
|
||||
multiTouch = true;
|
||||
wasZoomInMultiTouch = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionPointerDownOrMove(float x1, float y1, float x2, float y2) {
|
||||
firstTouchPointX = x1;
|
||||
firstTouchPointY = y1;
|
||||
secondTouchPointX = x2;
|
||||
secondTouchPointY = y2;
|
||||
multiTouch = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionPointerUp() {
|
||||
multiTouch = false;
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.os.Message;
|
|||
import android.view.View;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.QuadPoint;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
|
@ -125,11 +126,13 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
}
|
||||
showTwoFingersDistance = !view.isWasZoomInMultiTouch() && !view.isZooming() && (view.isMultiTouch() || System.currentTimeMillis() - cacheMultiTouchEndTime < DELAY);
|
||||
if (showTwoFingersDistance) {
|
||||
float x1 = view.getFirstTouchPointX();
|
||||
float y1 = view.getFirstTouchPointY();
|
||||
float x2 = view.getSecondTouchPointX();
|
||||
float y2 = view.getSecondTouchPointY();
|
||||
drawFingerDistance(canvas, tb, center, x1, y1, x2, y2, settings.isNightMode());
|
||||
LatLon firstTouchPoint = view.getFirstTouchPointLatLon();
|
||||
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());
|
||||
drawFingerDistance(canvas, x1, y1, x2, y2, settings.isNightMode());
|
||||
} else if (mode == RulerMode.FIRST) {
|
||||
drawCenterIcon(canvas, tb, center, settings.isNightMode());
|
||||
Location currentLoc = app.getLocationProvider().getLastKnownLocation();
|
||||
|
@ -151,12 +154,10 @@ public class RulerControlLayer extends OsmandMapLayer {
|
|||
handler.sendEmptyMessageDelayed(0, DELAY + 50);
|
||||
}
|
||||
|
||||
private void drawFingerDistance(Canvas canvas, RotatedTileBox tb, QuadPoint center, float x1, float y1, float x2, float y2, boolean nightMode) {
|
||||
canvas.rotate(-tb.getRotate(), center.x, center.y);
|
||||
private void drawFingerDistance(Canvas canvas, float x1, float y1, float x2, float y2, boolean nightMode) {
|
||||
canvas.drawLine(x1, y1, x2, y2, lineAttrs.paint);
|
||||
drawFingerTouchIcon(canvas, x1, y1, nightMode);
|
||||
drawFingerTouchIcon(canvas, x2, y2, nightMode);
|
||||
canvas.rotate(tb.getRotate(), center.x, center.y);
|
||||
}
|
||||
|
||||
private void drawFingerTouchIcon(Canvas canvas, float x, float y, boolean nightMode) {
|
||||
|
|
|
@ -150,7 +150,7 @@ public class MapInfoWidgetsFactory {
|
|||
RulerMode mode = rulerMode.get();
|
||||
if (mode == RulerMode.FIRST) {
|
||||
return RULER_CONTROL_WIDGET_STATE_FIRST_MODE;
|
||||
} else if (mode == RulerMode.SECOND){
|
||||
} else if (mode == RulerMode.SECOND) {
|
||||
return RULER_CONTROL_WIDGET_STATE_SECOND_MODE;
|
||||
} else {
|
||||
return RULER_CONTROL_WIDGET_STATE_EMPTY_MODE;
|
||||
|
@ -184,31 +184,23 @@ public class MapInfoWidgetsFactory {
|
|||
|
||||
public TextInfoWidget createRulerControl(final MapActivity map) {
|
||||
final String title = map.getResources().getString(R.string.map_widget_show_ruler);
|
||||
final TextInfoWidget rulerControl = new TextInfoWidget(map) {
|
||||
boolean needNewLatLon;
|
||||
long cacheMultiTouchEndTime;
|
||||
final TextInfoWidget rulerControl = new TextInfoWidget(map) {
|
||||
RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();
|
||||
LatLon cacheFirstTouchPoint = new LatLon(0, 0);
|
||||
LatLon cacheSecondTouchPoint = new LatLon(0, 0);
|
||||
|
||||
@Override
|
||||
public boolean updateInfo(DrawSettings drawSettings) {
|
||||
RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get();
|
||||
OsmandMapTileView view = map.getMapView();
|
||||
|
||||
if (cacheMultiTouchEndTime != view.getMultiTouchEndTime()) {
|
||||
cacheMultiTouchEndTime = view.getMultiTouchEndTime();
|
||||
needNewLatLon = true;
|
||||
}
|
||||
if (rulerLayer.isShowTwoFingersDistance()) {
|
||||
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;
|
||||
if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) ||
|
||||
!cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon())) {
|
||||
cacheFirstTouchPoint = view.getFirstTouchPointLatLon();
|
||||
cacheSecondTouchPoint = view.getSecondTouchPointLatLon();
|
||||
setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(),
|
||||
cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude());
|
||||
}
|
||||
} else if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) {
|
||||
Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
|
@ -218,10 +210,8 @@ public class MapInfoWidgetsFactory {
|
|||
setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(),
|
||||
centerLoc.getLatitude(), centerLoc.getLongitude());
|
||||
}
|
||||
needNewLatLon = true;
|
||||
} else {
|
||||
setText(title, null);
|
||||
needNewLatLon = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue