Small refactoring + TODO for map speed up
This commit is contained in:
parent
d950574234
commit
e9317a4b89
6 changed files with 237 additions and 199 deletions
|
@ -14,12 +14,14 @@ public class ToDoConstants {
|
||||||
// || 124 || Animated transition using only raster images (?) - skip animations (!) - don not render vectoring for animations (Issue 238) ||
|
// || 124 || Animated transition using only raster images (?) - skip animations (!) - don not render vectoring for animations (Issue 238) ||
|
||||||
// Fix issue with min/max zoom
|
// Fix issue with min/max zoom
|
||||||
// Refactoring animation (no need source tile size?)
|
// Refactoring animation (no need source tile size?)
|
||||||
|
// Empty screen replace (?)
|
||||||
// Refactoring ResourceManager with cached images (tiles density)
|
// Refactoring ResourceManager with cached images (tiles density)
|
||||||
// YandexLayer goes to MapTileLayer
|
// YandexLayer goes to MapTileLayer
|
||||||
// Add transparency filter to bitmap layers
|
// Add transparency filter to bitmap layers
|
||||||
// Download layers from internet (?) and allow to add own tile sources
|
// Download layers from internet (?) and allow to add own tile sources
|
||||||
// Manage tile sources and allow to compact them into sqlite db
|
// Manage tile sources and allow to compact them into sqlite db
|
||||||
|
|
||||||
|
|
||||||
// === Refactoring issues ===
|
// === Refactoring issues ===
|
||||||
// !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. ||
|
// !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. ||
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,11 @@ public class BinaryRouteDataReader {
|
||||||
boolean highway = "highway".equals(pair.tag);
|
boolean highway = "highway".equals(pair.tag);
|
||||||
double priority = highway && autoPriorityValues.containsKey(pair.value) ? autoPriorityValues.get(pair.value) : 1d;
|
double priority = highway && autoPriorityValues.containsKey(pair.value) ? autoPriorityValues.get(pair.value) : 1d;
|
||||||
if(speed == 0 && highway) {
|
if(speed == 0 && highway) {
|
||||||
speed = autoNotDefinedValues.get(pair.value) / 3.6d;
|
Double value = autoNotDefinedValues.get(pair.value);
|
||||||
|
if(value == null){
|
||||||
|
value = 50d;
|
||||||
|
}
|
||||||
|
speed = value / 3.6d;
|
||||||
}
|
}
|
||||||
return speed * priority;
|
return speed * priority;
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
||||||
// use only gps (not network) for 12 seconds
|
// use only gps (not network) for 12 seconds
|
||||||
private static final int USE_ONLY_GPS_INTERVAL = 12000;
|
private static final int USE_ONLY_GPS_INTERVAL = 12000;
|
||||||
|
|
||||||
|
private static final int SHOW_POSITION_MSG_ID = 7;
|
||||||
|
private static final int SHOW_POSITION_DELAY = 2500;
|
||||||
|
|
||||||
private boolean providerSupportsBearing = false;
|
private boolean providerSupportsBearing = false;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private boolean providerSupportsSpeed = false;
|
private boolean providerSupportsSpeed = false;
|
||||||
|
@ -794,7 +797,6 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
||||||
if(!currentShowingAngle){
|
if(!currentShowingAngle){
|
||||||
locationLayer.setHeading(null);
|
locationLayer.setHeading(null);
|
||||||
}
|
}
|
||||||
locationLayer.setAppMode(settings.getApplicationMode());
|
|
||||||
routingHelper.setAppMode(settings.getApplicationMode());
|
routingHelper.setAppMode(settings.getApplicationMode());
|
||||||
mapView.setMapPosition(settings.POSITION_ON_MAP.get());
|
mapView.setMapPosition(settings.POSITION_ON_MAP.get());
|
||||||
registerUnregisterSensor(getLastKnownLocation());
|
registerUnregisterSensor(getLastKnownLocation());
|
||||||
|
@ -962,25 +964,24 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void showAndHideMapPosition(){
|
public void showAndHideMapPosition() {
|
||||||
mapView.setShowMapPosition(true);
|
mapView.setShowMapPosition(true);
|
||||||
if(mapPositionHandler == null){
|
if (mapPositionHandler == null) {
|
||||||
mapPositionHandler = new Handler();
|
mapPositionHandler = new Handler();
|
||||||
}
|
}
|
||||||
Message msg = Message.obtain(mapPositionHandler, new Runnable(){
|
Message msg = Message.obtain(mapPositionHandler, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if(mapView.isShowMapPosition()){
|
if (mapView.isShowMapPosition()) {
|
||||||
mapView.setShowMapPosition(false);
|
mapView.setShowMapPosition(false);
|
||||||
mapView.refreshMap();
|
mapView.refreshMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
msg.what = 7;
|
msg.what = SHOW_POSITION_MSG_ID;
|
||||||
mapPositionHandler.removeMessages(7);
|
mapPositionHandler.removeMessages(SHOW_POSITION_MSG_ID);
|
||||||
mapPositionHandler.sendMessageDelayed(msg, 2500);
|
mapPositionHandler.sendMessageDelayed(msg, SHOW_POSITION_DELAY);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -404,6 +404,48 @@ public class MapInfoLayer implements OsmandMapLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyLayer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean drawInScreenPixels() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onLongPressEvent(PointF point) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(PointF point) {
|
||||||
|
if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) {
|
||||||
|
if (boundsForMiniRoute.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) {
|
||||||
|
showMiniMap = !showMiniMap;
|
||||||
|
view.refreshMap();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (boundsForLeftTime.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) {
|
||||||
|
showArrivalTime = !showArrivalTime;
|
||||||
|
view.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME.set(showArrivalTime);
|
||||||
|
view.refreshMap();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(cachedDistString != null && boundsForDist.contains(point.x, point.y)){
|
||||||
|
AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
|
||||||
|
LatLon pointToNavigate = view.getSettings().getPointToNavigate();
|
||||||
|
if(pointToNavigate != null){
|
||||||
|
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
|
||||||
|
thread.startMoving(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), pointToNavigate.getLongitude(),
|
||||||
|
view.getZoom(), fZoom, view.getSourceTileSize(), view.getRotate(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// draw path 96x96
|
// draw path 96x96
|
||||||
public static void calcTurnPath(Path pathForTurn, TurnType turnType, Matrix transform) {
|
public static void calcTurnPath(Path pathForTurn, TurnType turnType, Matrix transform) {
|
||||||
if(turnType == null){
|
if(turnType == null){
|
||||||
|
@ -534,46 +576,6 @@ public class MapInfoLayer implements OsmandMapLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroyLayer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean drawInScreenPixels() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onLongPressEvent(PointF point) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onTouchEvent(PointF point) {
|
|
||||||
if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) {
|
|
||||||
if (boundsForMiniRoute.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) {
|
|
||||||
showMiniMap = !showMiniMap;
|
|
||||||
view.refreshMap();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (boundsForLeftTime.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) {
|
|
||||||
showArrivalTime = !showArrivalTime;
|
|
||||||
view.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME.set(showArrivalTime);
|
|
||||||
view.refreshMap();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(cachedDistString != null && boundsForDist.contains(point.x, point.y)){
|
|
||||||
AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
|
|
||||||
LatLon pointToNavigate = view.getSettings().getPointToNavigate();
|
|
||||||
if(pointToNavigate != null){
|
|
||||||
int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
|
|
||||||
thread.startMoving(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), pointToNavigate.getLongitude(),
|
|
||||||
view.getZoom(), fZoom, view.getSourceTileSize(), view.getRotate(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,7 @@ import android.view.GestureDetector.OnDoubleTapListener;
|
||||||
import android.view.GestureDetector.OnGestureListener;
|
import android.view.GestureDetector.OnGestureListener;
|
||||||
import android.view.SurfaceHolder.Callback;
|
import android.view.SurfaceHolder.Callback;
|
||||||
|
|
||||||
public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback, AnimateDraggingCallback, OnGestureListener,
|
public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback, AnimateDraggingCallback {
|
||||||
OnDoubleTapListener, MultiTouchZoomListener {
|
|
||||||
|
|
||||||
|
|
||||||
protected final int emptyTileDivisor = 16;
|
protected final int emptyTileDivisor = 16;
|
||||||
|
@ -100,10 +99,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
|
|
||||||
private AnimateDraggingMapThread animatedDraggingThread;
|
private AnimateDraggingMapThread animatedDraggingThread;
|
||||||
|
|
||||||
private float initialMultiTouchZoom;
|
|
||||||
private PointF initialMultiTouchCenterPoint;
|
|
||||||
private LatLon initialMultiTouchLocation;
|
|
||||||
|
|
||||||
private GestureDetector gestureDetector;
|
private GestureDetector gestureDetector;
|
||||||
|
|
||||||
private MultiTouchSupport multiTouchSupport;
|
private MultiTouchSupport multiTouchSupport;
|
||||||
|
@ -164,9 +159,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
|
|
||||||
animatedDraggingThread = new AnimateDraggingMapThread();
|
animatedDraggingThread = new AnimateDraggingMapThread();
|
||||||
animatedDraggingThread.setCallback(this);
|
animatedDraggingThread.setCallback(this);
|
||||||
gestureDetector = new GestureDetector(getContext(), this);
|
gestureDetector = new GestureDetector(getContext(), new MapTileViewOnGestureListener());
|
||||||
multiTouchSupport = new MultiTouchSupport(getContext(), this);
|
multiTouchSupport = new MultiTouchSupport(getContext(), new MapTileViewMultiTouchZoomListener());
|
||||||
gestureDetector.setOnDoubleTapListener(this);
|
gestureDetector.setOnDoubleTapListener(new MapTileViewOnDoubleTapListener());
|
||||||
|
|
||||||
WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
|
WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
|
||||||
dm = new DisplayMetrics();
|
dm = new DisplayMetrics();
|
||||||
|
@ -424,15 +419,15 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshMapInternal() {
|
private void refreshMapInternal() {
|
||||||
if (handler.hasMessages(1)) {
|
handler.removeMessages(1);
|
||||||
return;
|
|
||||||
}
|
long time = System.currentTimeMillis();
|
||||||
|
|
||||||
boolean useInternet = getSettings().USE_INTERNET_TO_DOWNLOAD_TILES.get();
|
boolean useInternet = getSettings().USE_INTERNET_TO_DOWNLOAD_TILES.get();
|
||||||
if (useInternet) {
|
if (useInternet) {
|
||||||
MapTileDownloader.getInstance().refuseAllPreviousRequests();
|
MapTileDownloader.getInstance().refuseAllPreviousRequests();
|
||||||
}
|
}
|
||||||
float ftileSize = getTileSize();
|
|
||||||
|
|
||||||
SurfaceHolder holder = getHolder();
|
SurfaceHolder holder = getHolder();
|
||||||
synchronized (holder) {
|
synchronized (holder) {
|
||||||
|
@ -443,8 +438,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
float h = getCenterPointY();
|
float h = getCenterPointY();
|
||||||
Canvas canvas = holder.lockCanvas();
|
Canvas canvas = holder.lockCanvas();
|
||||||
if (canvas != null) {
|
if (canvas != null) {
|
||||||
canvas.save();
|
|
||||||
boolean nightMode = false;
|
boolean nightMode = false;
|
||||||
|
log.info("Canvas " + (System.currentTimeMillis() - time));
|
||||||
if (application != null) {
|
if (application != null) {
|
||||||
Boolean dayNightRenderer = application.getDaynightHelper().getDayNightRenderer();
|
Boolean dayNightRenderer = application.getDaynightHelper().getDayNightRenderer();
|
||||||
if (dayNightRenderer != null) {
|
if (dayNightRenderer != null) {
|
||||||
|
@ -456,21 +451,32 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
calculateTileRectangle(boundsRect, w, h, tileX, tileY, tilesRect);
|
calculateTileRectangle(boundsRect, w, h, tileX, tileY, tilesRect);
|
||||||
int left = (int) FloatMath.floor(tilesRect.left);
|
int left = (int) FloatMath.floor(tilesRect.left);
|
||||||
int top = (int) FloatMath.floor(tilesRect.top);
|
int top = (int) FloatMath.floor(tilesRect.top);
|
||||||
int width = (int) FloatMath.ceil(tilesRect.right - left);
|
|
||||||
int height = (int) FloatMath.ceil(tilesRect.bottom - top);
|
|
||||||
latlonRect.top = (float) MapUtils.getLatitudeFromTile(nzoom, tilesRect.top);
|
latlonRect.top = (float) MapUtils.getLatitudeFromTile(nzoom, tilesRect.top);
|
||||||
latlonRect.left = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.left);
|
latlonRect.left = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.left);
|
||||||
latlonRect.bottom = (float) MapUtils.getLatitudeFromTile(nzoom, tilesRect.bottom);
|
latlonRect.bottom = (float) MapUtils.getLatitudeFromTile(nzoom, tilesRect.bottom);
|
||||||
latlonRect.right = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.right);
|
latlonRect.right = (float) MapUtils.getLongitudeFromTile(nzoom, tilesRect.right);
|
||||||
|
log.info("Calc" + (System.currentTimeMillis() - time));
|
||||||
for (int i = 0; i < width; i++) {
|
if(nightMode){
|
||||||
for (int j = 0; j < height; j++) {
|
canvas.drawARGB(255, 220, 220, 220);
|
||||||
float x1 = (i + left - tileX) * ftileSize + w;
|
} else {
|
||||||
float y1 = (j + top - tileY) * ftileSize + h;
|
canvas.drawARGB(255, 240, 240, 240);
|
||||||
drawEmptyTile(canvas, x1, y1, ftileSize, nightMode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// TODO map
|
||||||
|
// float ftileSize = getTileSize();
|
||||||
|
// int width = (int) FloatMath.ceil(tilesRect.right - left);
|
||||||
|
// int height = (int) FloatMath.ceil(tilesRect.bottom - top);
|
||||||
|
// for (int i = 0; i < width; i++) {
|
||||||
|
// for (int j = 0; j < height; j++) {
|
||||||
|
// float x1 = (i + left - tileX) * ftileSize + w;
|
||||||
|
// float y1 = (j + top - tileY) * ftileSize + h;
|
||||||
|
// drawEmptyTile(canvas, x1, y1, ftileSize, nightMode);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
log.info("Draw before layers" + (System.currentTimeMillis() - time));
|
||||||
|
|
||||||
drawOverMap(canvas, latlonRect, tilesRect, nightMode);
|
drawOverMap(canvas, latlonRect, tilesRect, nightMode);
|
||||||
|
|
||||||
|
log.info("Draw with layers " + (System.currentTimeMillis() - time));
|
||||||
} finally {
|
} finally {
|
||||||
holder.unlockCanvasAndPost(canvas);
|
holder.unlockCanvasAndPost(canvas);
|
||||||
}
|
}
|
||||||
|
@ -481,21 +487,32 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
private void drawOverMap(Canvas canvas, RectF latlonRect, RectF tilesRect, boolean nightMode) {
|
private void drawOverMap(Canvas canvas, RectF latlonRect, RectF tilesRect, boolean nightMode) {
|
||||||
int w = getCenterPointX();
|
int w = getCenterPointX();
|
||||||
int h = getCenterPointY();
|
int h = getCenterPointY();
|
||||||
canvas.restore();
|
|
||||||
|
|
||||||
for (int i = -1; i < layers.size(); i++) {
|
// long prev = System.currentTimeMillis();
|
||||||
|
canvas.save();
|
||||||
|
boolean rotated = false;
|
||||||
|
for (int i = 0; i < layers.size(); i++) {
|
||||||
try {
|
try {
|
||||||
OsmandMapLayer layer = layers.get(i);
|
OsmandMapLayer layer = layers.get(i);
|
||||||
canvas.save();
|
// rotate if needed
|
||||||
if (!layer.drawInScreenPixels()) {
|
if ((!layer.drawInScreenPixels()) != rotated) {
|
||||||
canvas.rotate(rotate, w, h);
|
canvas.restore();
|
||||||
|
rotated = !layer.drawInScreenPixels();
|
||||||
|
canvas.save();
|
||||||
|
if(rotated){
|
||||||
|
canvas.rotate(rotate, w, h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
layer.onDraw(canvas, latlonRect, tilesRect, nightMode);
|
layer.onDraw(canvas, latlonRect, tilesRect, nightMode);
|
||||||
canvas.restore();
|
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
// skip it
|
// skip it
|
||||||
}
|
}
|
||||||
|
// long time = System.currentTimeMillis();
|
||||||
|
// log.debug("Layer time " + (time - prev) + " " + zOrders.get(layers.get(i)));
|
||||||
|
// prev = time;
|
||||||
}
|
}
|
||||||
|
canvas.restore();
|
||||||
if (showMapPosition) {
|
if (showMapPosition) {
|
||||||
canvas.drawCircle(w, h, 3 * dm.density, paintCenter);
|
canvas.drawCircle(w, h, 3 * dm.density, paintCenter);
|
||||||
canvas.drawCircle(w, h, 7 * dm.density, paintCenter);
|
canvas.drawCircle(w, h, 7 * dm.density, paintCenter);
|
||||||
|
@ -660,29 +677,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
this.onClickListener = l;
|
this.onClickListener = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onDown(MotionEvent e) {
|
|
||||||
// enable double tap animation
|
|
||||||
// animatedDraggingThread.stopAnimating();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public LatLon getLatLonFromScreenPoint(float x, float y) {
|
||||||
public void onZoomEnded(float distance, float relativeToStart) {
|
|
||||||
float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5);
|
|
||||||
float calcZoom = initialMultiTouchZoom + dz;
|
|
||||||
setZoom(Math.round(calcZoom));
|
|
||||||
zoomPositionChanged(getZoom());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onZoomStarted(float distance, PointF centerPoint) {
|
|
||||||
initialMultiTouchCenterPoint = centerPoint;
|
|
||||||
initialMultiTouchLocation = getLatLonFromScreenPoint(centerPoint.x, centerPoint.y);
|
|
||||||
initialMultiTouchZoom = zoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LatLon getLatLonFromScreenPoint(float x, float y) {
|
|
||||||
float dx = x - getCenterPointX();
|
float dx = x - getCenterPointX();
|
||||||
float dy = y - getCenterPointY();
|
float dy = y - getCenterPointY();
|
||||||
float fy = calcDiffTileY(dx, dy);
|
float fy = calcDiffTileY(dx, dy);
|
||||||
|
@ -692,112 +688,144 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
return new LatLon(latitude, longitude);
|
return new LatLon(latitude, longitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void zoomPositionChanged(float calcZoom) {
|
|
||||||
float dx = initialMultiTouchCenterPoint.x - getCenterPointX();
|
|
||||||
float dy = initialMultiTouchCenterPoint.y - getCenterPointY();
|
|
||||||
float ex = calcDiffTileX(dx, dy);
|
|
||||||
float ey = calcDiffTileY(dx, dy);
|
|
||||||
int z = (int)calcZoom;
|
|
||||||
double tx = MapUtils.getTileNumberX(z, initialMultiTouchLocation.getLongitude());
|
|
||||||
double ty = MapUtils.getTileNumberY(z, initialMultiTouchLocation.getLatitude());
|
|
||||||
double lat = MapUtils.getLatitudeFromTile(z, ty - ey);
|
|
||||||
double lon = MapUtils.getLongitudeFromTile(z, tx - ex);
|
|
||||||
setLatLon(lat, lon);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onZooming(float distance, float relativeToStart) {
|
|
||||||
float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5);
|
|
||||||
float calcZoom = initialMultiTouchZoom + dz;
|
|
||||||
if (Math.abs(calcZoom - zoom) > 0.05) {
|
|
||||||
setZoom(calcZoom);
|
|
||||||
zoomPositionChanged(calcZoom);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public AnimateDraggingMapThread getAnimatedDraggingThread() {
|
public AnimateDraggingMapThread getAnimatedDraggingThread() {
|
||||||
return animatedDraggingThread;
|
return animatedDraggingThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start OnGestureListener
|
|
||||||
@Override
|
private class MapTileViewMultiTouchZoomListener implements MultiTouchZoomListener {
|
||||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
private float initialMultiTouchZoom;
|
||||||
if (Math.abs(e1.getX() - e2.getX()) + Math.abs(e1.getX() - e2.getX()) > 50 * dm.density) {
|
private PointF initialMultiTouchCenterPoint;
|
||||||
animatedDraggingThread.startDragging(Math.abs(velocityX / 1000), Math.abs(velocityY / 1000), e1.getX(), e1.getY(), e2.getX(),
|
private LatLon initialMultiTouchLocation;
|
||||||
e2.getY());
|
|
||||||
} else {
|
@Override
|
||||||
onScroll(e1, e2, e1.getX() - e2.getX(), e1.getY() - e2.getY());
|
public void onZoomEnded(float distance, float relativeToStart) {
|
||||||
|
float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5);
|
||||||
|
float calcZoom = initialMultiTouchZoom + dz;
|
||||||
|
setZoom(Math.round(calcZoom));
|
||||||
|
zoomPositionChanged(getZoom());
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
@Override
|
||||||
|
public void onZoomStarted(float distance, PointF centerPoint) {
|
||||||
|
initialMultiTouchCenterPoint = centerPoint;
|
||||||
|
initialMultiTouchLocation = getLatLonFromScreenPoint(centerPoint.x, centerPoint.y);
|
||||||
|
initialMultiTouchZoom = zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onZooming(float distance, float relativeToStart) {
|
||||||
|
float dz = (float) (Math.log(relativeToStart) / Math.log(2) * 1.5);
|
||||||
|
float calcZoom = initialMultiTouchZoom + dz;
|
||||||
|
if (Math.abs(calcZoom - zoom) > 0.05) {
|
||||||
|
setZoom(calcZoom);
|
||||||
|
zoomPositionChanged(calcZoom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void zoomPositionChanged(float calcZoom) {
|
||||||
|
float dx = initialMultiTouchCenterPoint.x - getCenterPointX();
|
||||||
|
float dy = initialMultiTouchCenterPoint.y - getCenterPointY();
|
||||||
|
float ex = calcDiffTileX(dx, dy);
|
||||||
|
float ey = calcDiffTileY(dx, dy);
|
||||||
|
int z = (int)calcZoom;
|
||||||
|
double tx = MapUtils.getTileNumberX(z, initialMultiTouchLocation.getLongitude());
|
||||||
|
double ty = MapUtils.getTileNumberY(z, initialMultiTouchLocation.getLatitude());
|
||||||
|
double lat = MapUtils.getLatitudeFromTile(z, ty - ey);
|
||||||
|
double lon = MapUtils.getLongitudeFromTile(z, tx - ex);
|
||||||
|
setLatLon(lat, lon);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MapTileViewOnGestureListener implements OnGestureListener {
|
||||||
|
@Override
|
||||||
|
public boolean onDown(MotionEvent e) {
|
||||||
|
// enable double tap animation
|
||||||
|
// animatedDraggingThread.stopAnimating();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongPress(MotionEvent e) {
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||||
if (multiTouchSupport.isInZoomMode()) {
|
if (Math.abs(e1.getX() - e2.getX()) + Math.abs(e1.getX() - e2.getX()) > 50 * dm.density) {
|
||||||
return;
|
animatedDraggingThread.startDragging(Math.abs(velocityX / 1000), Math.abs(velocityY / 1000), e1.getX(), e1.getY(), e2
|
||||||
|
.getX(), e2.getY());
|
||||||
|
} else {
|
||||||
|
onScroll(e1, e2, e1.getX() - e2.getX(), e1.getY() - e2.getY());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("On long click event " + e.getX() + " " + e.getY()); //$NON-NLS-1$ //$NON-NLS-2$
|
@Override
|
||||||
}
|
public void onLongPress(MotionEvent e) {
|
||||||
PointF point = new PointF(e.getX(), e.getY());
|
if (multiTouchSupport.isInZoomMode()) {
|
||||||
for (int i = layers.size() - 1; i >= 0; i--) {
|
return;
|
||||||
if (layers.get(i).onLongPressEvent(point)) {
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("On long click event " + e.getX() + " " + e.getY()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
|
PointF point = new PointF(e.getX(), e.getY());
|
||||||
|
for (int i = layers.size() - 1; i >= 0; i--) {
|
||||||
|
if (layers.get(i).onLongPressEvent(point)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (onLongClickListener != null && onLongClickListener.onLongPressEvent(point)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (onLongClickListener != null && onLongClickListener.onLongPressEvent(point)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||||
dragTo(e2.getX() + distanceX, e2.getY() + distanceY, e2.getX(), e2.getY(), true);
|
dragTo(e2.getX() + distanceX, e2.getY() + distanceY, e2.getX(), e2.getY(), true);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onShowPress(MotionEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onSingleTapUp(MotionEvent e) {
|
|
||||||
PointF point = new PointF(e.getX(), e.getY());
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("On click event " + point.x + " " + point.y); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
for (int i = layers.size() - 1; i >= 0; i--) {
|
|
||||||
if (layers.get(i).onTouchEvent(point)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (onClickListener != null && onClickListener.onPressEvent(point)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// End OnGestureListener
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShowPress(MotionEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
// Start OnDoubleTapListener
|
@Override
|
||||||
@Override
|
public boolean onSingleTapUp(MotionEvent e) {
|
||||||
public boolean onDoubleTap(MotionEvent e) {
|
PointF point = new PointF(e.getX(), e.getY());
|
||||||
LatLon l = getLatLonFromScreenPoint(e.getX(), e.getY());
|
if (log.isDebugEnabled()) {
|
||||||
getAnimatedDraggingThread().startMoving(getLatitude(), getLongitude(), l.getLatitude(), l.getLongitude(), getZoom(), getZoom() + 1,
|
log.debug("On click event " + point.x + " " + point.y); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
getSourceTileSize(), getRotate(), true);
|
}
|
||||||
return true;
|
for (int i = layers.size() - 1; i >= 0; i--) {
|
||||||
|
if (layers.get(i).onTouchEvent(point)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (onClickListener != null && onClickListener.onPressEvent(point)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onDoubleTapEvent(MotionEvent e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
private class MapTileViewOnDoubleTapListener implements OnDoubleTapListener {
|
||||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
@Override
|
||||||
return false;
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
}
|
LatLon l = getLatLonFromScreenPoint(e.getX(), e.getY());
|
||||||
|
getAnimatedDraggingThread().startMoving(getLatitude(), getLongitude(), l.getLatitude(), l.getLongitude(), getZoom(),
|
||||||
|
getZoom() + 1, getSourceTileSize(), getRotate(), true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// End OnDoubleTapListener
|
@Override
|
||||||
|
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public class PointLocationLayer implements OsmandMapLayer {
|
||||||
private Paint area;
|
private Paint area;
|
||||||
private Paint headingPaint;
|
private Paint headingPaint;
|
||||||
private Path pathForDirection;
|
private Path pathForDirection;
|
||||||
private ApplicationMode appMode = ApplicationMode.DEFAULT;
|
|
||||||
|
|
||||||
protected Location lastKnownLocation = null;
|
protected Location lastKnownLocation = null;
|
||||||
private DisplayMetrics dm;
|
private DisplayMetrics dm;
|
||||||
|
@ -34,6 +33,8 @@ public class PointLocationLayer implements OsmandMapLayer {
|
||||||
|
|
||||||
private Float heading = null;
|
private Float heading = null;
|
||||||
|
|
||||||
|
private ApplicationMode appMode;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void initUI() {
|
private void initUI() {
|
||||||
|
@ -84,8 +85,11 @@ public class PointLocationLayer implements OsmandMapLayer {
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, boolean nightMode) {
|
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, boolean nightMode) {
|
||||||
if (isLocationVisible(lastKnownLocation)) {
|
if (isLocationVisible(lastKnownLocation)) {
|
||||||
|
checkAppMode(view.getSettings().getApplicationMode());
|
||||||
|
|
||||||
int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude());
|
int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude());
|
||||||
int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude());
|
int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude());
|
||||||
|
|
||||||
int radius = MapUtils.getLengthXFromMeters(view.getZoom(), view.getLatitude(), view.getLongitude(),
|
int radius = MapUtils.getLengthXFromMeters(view.getZoom(), view.getLatitude(), view.getLongitude(),
|
||||||
lastKnownLocation.getAccuracy(), view.getTileSize(), view.getWidth());
|
lastKnownLocation.getAccuracy(), view.getTileSize(), view.getWidth());
|
||||||
|
|
||||||
|
@ -180,15 +184,14 @@ public class PointLocationLayer implements OsmandMapLayer {
|
||||||
public void destroyLayer() {
|
public void destroyLayer() {
|
||||||
|
|
||||||
}
|
}
|
||||||
public ApplicationMode getAppMode() {
|
public void checkAppMode(ApplicationMode appMode) {
|
||||||
return appMode;
|
if (appMode != this.appMode) {
|
||||||
}
|
this.appMode = appMode;
|
||||||
public void setAppMode(ApplicationMode appMode) {
|
if (this.appMode == ApplicationMode.CAR || this.appMode == ApplicationMode.BICYCLE) {
|
||||||
this.appMode = appMode;
|
this.bearing.setAlpha(180);
|
||||||
if(this.appMode == ApplicationMode.CAR || this.appMode == ApplicationMode.BICYCLE){
|
} else {
|
||||||
this.bearing.setAlpha(180);
|
this.bearing.setAlpha(150);
|
||||||
} else {
|
}
|
||||||
this.bearing.setAlpha(150);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -207,6 +210,4 @@ public class PointLocationLayer implements OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue