Fix jumping animation

This commit is contained in:
max-klaus 2019-08-05 22:09:48 +03:00
parent 5e591194c0
commit ba6d3c1c85
2 changed files with 8 additions and 11 deletions

View file

@ -1698,7 +1698,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
public void centerMarkerLocation() { public void centerMarkerLocation() {
centered = true; centered = true;
showOnMap(menu.getLatLon(), true, true, false, getZoom()); showOnMap(menu.getLatLon(), true, false, getZoom());
} }
private int getZoom() { private int getZoom() {
@ -1722,8 +1722,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f); cp.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
cp.setLatLonCenter(flat, flon); cp.setLatLonCenter(flat, flon);
cp.setZoom(zoom); cp.setZoom(zoom);
flat = cp.getLatFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2); flat = cp.getLatFromPixel(cp.getPixWidth() / 2f, cp.getPixHeight() / 2f);
flon = cp.getLonFromPixel(cp.getPixWidth() / 2, cp.getPixHeight() / 2); flon = cp.getLonFromPixel(cp.getPixWidth() / 2f, cp.getPixHeight() / 2f);
if (updateOrigXY) { if (updateOrigXY) {
origMarkerX = cp.getCenterPixelX(); origMarkerX = cp.getCenterPixelX();
@ -1732,22 +1732,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
return new LatLon(flat, flon); return new LatLon(flat, flon);
} }
private void showOnMap(LatLon latLon, boolean updateCoords, boolean needMove, boolean alreadyAdjusted, int zoom) { private void showOnMap(LatLon latLon, boolean updateCoords, boolean alreadyAdjusted, int zoom) {
AnimateDraggingMapThread thread = map.getAnimatedDraggingThread(); AnimateDraggingMapThread thread = map.getAnimatedDraggingThread();
LatLon calcLatLon = calculateCenterLatLon(latLon, zoom, updateCoords); LatLon calcLatLon = calculateCenterLatLon(latLon, zoom, updateCoords);
if (updateCoords) { if (updateCoords) {
mapCenter = calcLatLon; mapCenter = calcLatLon;
menu.setMapCenter(mapCenter); menu.setMapCenter(mapCenter);
} }
if (!alreadyAdjusted) { if (!alreadyAdjusted) {
calcLatLon = getAdjustedMarkerLocation(getPosY(), calcLatLon, true, zoom); calcLatLon = getAdjustedMarkerLocation(getPosY(), calcLatLon, true, zoom);
} }
if (needMove) {
thread.startMoving(calcLatLon.getLatitude(), calcLatLon.getLongitude(), zoom, true); thread.startMoving(calcLatLon.getLatitude(), calcLatLon.getLongitude(), zoom, true);
} }
}
private void setAddressLocation() { private void setAddressLocation() {
if (view != null) { if (view != null) {
@ -2021,7 +2017,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
} }
if (animated) { if (animated) {
showOnMap(latlon, false, true, true, zoom); showOnMap(latlon, false, true, zoom);
} else { } else {
if (dZoom != 0) { if (dZoom != 0) {
map.setIntZoom(zoom); map.setIntZoom(zoom);

View file

@ -180,6 +180,7 @@ public class AnimateDraggingMapThread {
public void startMoving(final double finalLat, final double finalLon, final int endZoom, public void startMoving(final double finalLat, final double finalLon, final int endZoom,
final boolean notifyListener, final Runnable finishAnimationCallback) { final boolean notifyListener, final Runnable finishAnimationCallback) {
boolean wasAnimating = isAnimating();
stopAnimatingSync(); stopAnimatingSync();
final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy(); final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy();
@ -202,7 +203,7 @@ public class AnimateDraggingMapThread {
final int moveZoom = rb.getZoom(); final int moveZoom = rb.getZoom();
// check if animation needed // check if animation needed
skipAnimation = skipAnimation || (Math.abs(moveZoom - startZoom) >= 3 || Math.abs(endZoom - moveZoom) > 3); skipAnimation = skipAnimation || (Math.abs(moveZoom - startZoom) >= 3 || Math.abs(endZoom - moveZoom) > 3);
if (skipAnimation) { if (skipAnimation || wasAnimating) {
tileView.setLatLonAnimate(finalLat, finalLon, notifyListener); tileView.setLatLonAnimate(finalLat, finalLon, notifyListener);
tileView.setFractionalZoom(endZoom, 0, notifyListener); tileView.setFractionalZoom(endZoom, 0, notifyListener);
if (finishAnimationCallback != null) { if (finishAnimationCallback != null) {