Add 2 fingers rotation

This commit is contained in:
vshcherb 2013-10-06 12:59:01 +03:00
parent 3a74fb7796
commit 3752cd25ab
17 changed files with 142 additions and 151 deletions

View file

@ -49,14 +49,8 @@ public class RenderingContext {
private float density = 1; private float density = 1;
public void setDensityValue(boolean highResMode, float mapTextSize, float density) { public void setDensityValue(float density) {
// boolean highResMode = false; this.density = density ;
// float mapTextSize = 1;
if (highResMode && density > 1) {
this.density = density * mapTextSize;
} else {
this.density = mapTextSize;
}
} }
public float getDensityValue(float val) { public float getDensityValue(float val) {

View file

@ -56,6 +56,7 @@ public class RotatedTileBox {
rotateSin = r.rotateSin; rotateSin = r.rotateSin;
oxTile = r.oxTile; oxTile = r.oxTile;
oyTile =r.oyTile; oyTile =r.oyTile;
if (r.tileBounds != null) {
tileBounds = new QuadRect(r.tileBounds); tileBounds = new QuadRect(r.tileBounds);
latLonBounds = new QuadRect(r.latLonBounds); latLonBounds = new QuadRect(r.latLonBounds);
tileLT = new QuadPoint(r.tileLT); tileLT = new QuadPoint(r.tileLT);
@ -63,6 +64,7 @@ public class RotatedTileBox {
tileRB = new QuadPoint(r.tileRB); tileRB = new QuadPoint(r.tileRB);
tileLB = new QuadPoint(r.tileLB); tileLB = new QuadPoint(r.tileLB);
} }
}
private void init(int pixWidth, int pixHeight, float centerX, float centerY, double lat, double lon, private void init(int pixWidth, int pixHeight, float centerX, float centerY, double lat, double lon,
int zoom, float zoomScale, float rotate, float density) { int zoom, float zoomScale, float rotate, float density) {
@ -94,7 +96,9 @@ public class RotatedTileBox {
while(rotate > 360){ while(rotate > 360){
rotate -= 360; rotate -= 360;
} }
calculateTileRectangle(); tileBounds = null;
// lazy
// calculateTileRectangle();
} }
public double getLatFromPixel(float x, float y) { public double getLatFromPixel(float x, float y) {
@ -163,6 +167,7 @@ public class RotatedTileBox {
public QuadRect getTileBounds() { public QuadRect getTileBounds() {
checkTileRectangleCalculated();
return tileBounds; return tileBounds;
} }
@ -266,6 +271,7 @@ public class RotatedTileBox {
} }
public QuadRect getLatLonBounds() { public QuadRect getLatLonBounds() {
checkTileRectangleCalculated();
return latLonBounds; return latLonBounds;
} }
@ -326,6 +332,12 @@ public class RotatedTileBox {
calculateDerivedFields(); calculateDerivedFields();
} }
public void setZoomAndAnimation(int zoom, float zoomAnimation) {
this.zoomAnimation = zoomAnimation;
this.zoom = zoom;
calculateDerivedFields();
}
public void setCenterLocation(float ratiocx, float ratiocy) { public void setCenterLocation(float ratiocx, float ratiocy) {
this.cx = (int) (pixWidth * ratiocx); this.cx = (int) (pixWidth * ratiocx);
this.cy = (int) (pixHeight * ratiocy); this.cy = (int) (pixHeight * ratiocy);
@ -333,16 +345,25 @@ public class RotatedTileBox {
} }
public QuadPoint getLeftTopTilePoint() { public QuadPoint getLeftTopTilePoint() {
checkTileRectangleCalculated();
return tileLT; return tileLT;
} }
public LatLon getLeftTopLatLon() { public LatLon getLeftTopLatLon() {
checkTileRectangleCalculated();
return new LatLon(MapUtils.getLatitudeFromTile(zoom, tileLT.y), return new LatLon(MapUtils.getLatitudeFromTile(zoom, tileLT.y),
MapUtils.getLongitudeFromTile(zoom, tileLT.x)); MapUtils.getLongitudeFromTile(zoom, tileLT.x));
} }
private void checkTileRectangleCalculated() {
if(tileBounds == null){
calculateTileRectangle();;
}
}
public LatLon getRightBottomLatLon() { public LatLon getRightBottomLatLon() {
checkTileRectangleCalculated();
return new LatLon(MapUtils.getLatitudeFromTile(zoom, tileRB.y), return new LatLon(MapUtils.getLatitudeFromTile(zoom, tileRB.y),
MapUtils.getLongitudeFromTile(zoom, tileRB.x)); MapUtils.getLongitudeFromTile(zoom, tileRB.x));
} }
@ -353,6 +374,11 @@ public class RotatedTileBox {
calculateDerivedFields(); calculateDerivedFields();
} }
public void setZoom(int zoom) {
this.zoom = zoom;
calculateDerivedFields();
}
public void setZoom(int zoom, float zoomScale, float zoomToAnimate) { public void setZoom(int zoom, float zoomScale, float zoomToAnimate) {
this.zoom = zoom; this.zoom = zoom;
this.zoomScale = zoomScale; this.zoomScale = zoomScale;
@ -379,6 +405,8 @@ public class RotatedTileBox {
public boolean containsTileBox(RotatedTileBox box) { public boolean containsTileBox(RotatedTileBox box) {
checkTileRectangleCalculated();
box.checkTileRectangleCalculated();
QuadPoint temp = new QuadPoint(); QuadPoint temp = new QuadPoint();
if(box.zoom != zoom){ if(box.zoom != zoom){
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View file

@ -612,14 +612,11 @@ public class OsmandSettings {
new BooleanAccessibilityPreference("accessibility_extensions", false).makeGlobal(); new BooleanAccessibilityPreference("accessibility_extensions", false).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> USE_HIGH_RES_MAPS = new BooleanPreference("use_high_res_maps", true).makeGlobal().cache();
public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", true).makeGlobal().cache(); public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", true).makeGlobal().cache();
public final OsmandPreference<Boolean> USE_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeGlobal().cache(); public final OsmandPreference<Boolean> USE_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeGlobal().cache();
// this value string is synchronized with settings_pref.xml preference name // public final OsmandPreference<Float> MAP_TEXT_SIZE = new FloatPreference("map_text_size", 1.0f).makeProfile().cache();
public final OsmandPreference<Float> MAP_TEXT_SIZE = new FloatPreference("map_text_size", 1.0f).makeProfile().cache(); public final OsmandPreference<Float> MAP_ZOOM_SCALE_BY_DENSITY = new FloatPreference("map_zoom_scale_by_density", 1.0f).makeProfile().cache();
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name

View file

@ -550,6 +550,7 @@ public class MapActivity extends AccessibleActivity {
mapLayers.getMapInfoLayer().recreateControls(); mapLayers.getMapInfoLayer().recreateControls();
} }
mapLayers.updateLayers(mapView); mapLayers.updateLayers(mapView);
mapView.setComplexZoom(mapView.getZoom(), mapView.getSettingsZoomScale());
app.getDaynightHelper().startSensorIfNeeded(new StateChangedListener<Boolean>() { app.getDaynightHelper().startSensorIfNeeded(new StateChangedListener<Boolean>() {
@Override @Override

View file

@ -100,8 +100,6 @@ public class SettingsRasterMapsActivity extends SettingsBaseActivity {
R.string.modify_transparency, 0, 255); R.string.modify_transparency, 0, 255);
cat.addPreference(sp); cat.addPreference(sp);
cat.addPreference(createCheckBoxPreference(settings.USE_HIGH_RES_MAPS,
R.string.use_high_res_maps, R.string.use_high_res_maps_descr));
} }

View file

@ -565,8 +565,7 @@ public class MapRenderRepositories {
currentRenderingContext.height = (int) (requestedBox.getPixHeight() / mapDensity); currentRenderingContext.height = (int) (requestedBox.getPixHeight() / mapDensity);
currentRenderingContext.nightMode = nightMode; currentRenderingContext.nightMode = nightMode;
currentRenderingContext.useEnglishNames = prefs.USE_ENGLISH_NAMES.get(); currentRenderingContext.useEnglishNames = prefs.USE_ENGLISH_NAMES.get();
currentRenderingContext.setDensityValue(prefs.USE_HIGH_RES_MAPS.get(), currentRenderingContext.setDensityValue(renderer.getDensity() * prefs.MAP_ZOOM_SCALE_BY_DENSITY.get());
prefs.MAP_TEXT_SIZE.get(), renderer.getDensity());
// init rendering context // init rendering context
currentRenderingContext.tileDivisor = (float) MapUtils.getPowZoom(31 - requestedBox.getZoom()); currentRenderingContext.tileDivisor = (float) MapUtils.getPowZoom(31 - requestedBox.getZoom());
if (checkWhetherInterrupted()) { if (checkWhetherInterrupted()) {

View file

@ -128,7 +128,7 @@ public class AnimateDraggingMapThread {
float mStX = rb.getPixXFromLatLon(startLat, startLon) - rb.getPixXFromLatLon(finalLat, finalLon); float mStX = rb.getPixXFromLatLon(startLat, startLon) - rb.getPixXFromLatLon(finalLat, finalLon);
float mStY = rb.getPixYFromLatLon(startLat, startLon) - rb.getPixYFromLatLon(finalLat, finalLon); float mStY = rb.getPixYFromLatLon(startLat, startLon) - rb.getPixYFromLatLon(finalLat, finalLon);
while (Math.abs(mStX) + Math.abs(mStY) > 1200) { while (Math.abs(mStX) + Math.abs(mStY) > 1200) {
rb.setZoom(rb.getZoom() - 1, zoomScale); rb.setZoom(rb.getZoom() - 1);
if(rb.getZoom() <= 4){ if(rb.getZoom() <= 4){
skipAnimation = true; skipAnimation = true;
} }

View file

@ -99,7 +99,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I
int ey = (int) point.y; int ey = (int) point.y;
for (FavouritePoint n : favorites.getFavouritePoints()) { for (FavouritePoint n : favorites.getFavouritePoints()) {
int x = tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude()); int x = tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude());
int y = tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude()); int y = tb.getPixYFromLatLon(n.getLatitude(), n.getLongitude());
if (calculateBelongs(ex, ey, x, y, r)) { if (calculateBelongs(ex, ey, x, y, r)) {
res.add(n); res.add(n);
} }

View file

@ -8,6 +8,7 @@ import net.londatiga.android.QuickAction;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -46,7 +47,6 @@ public class MapControlsLayer extends OsmandMapLayer {
private OsmandMapTileView view; private OsmandMapTileView view;
private DisplayMetrics dm;
private final MapActivity activity; private final MapActivity activity;
private Handler showUIHandler; private Handler showUIHandler;
@ -87,14 +87,7 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override @Override
public void initLayer(final OsmandMapTileView view) { public void initLayer(final OsmandMapTileView view) {
this.view = view; this.view = view;
dm = new DisplayMetrics(); scaleCoefficient = view.getScaleCoefficient();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
scaleCoefficient = dm.density;
if (Math.min(dm.widthPixels / (dm.density * 160), dm.heightPixels / (dm.density * 160)) > 2.5f) {
// large screen
scaleCoefficient *= 1.5f;
}
FrameLayout parent = (FrameLayout) view.getParent(); FrameLayout parent = (FrameLayout) view.getParent();
showUIHandler = new Handler(); showUIHandler = new Handler();
@ -340,7 +333,8 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
}); });
zoomInButton.setOnLongClickListener(new View.OnLongClickListener() { final OsmandSettings.OsmandPreference<Float> zoomScale = view.getSettings().MAP_ZOOM_SCALE_BY_DENSITY;
final View.OnLongClickListener listener = new View.OnLongClickListener() {
@Override @Override
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
@ -375,7 +369,8 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
float newScale = (float) Math.sqrt((tlist.get(which) - 100f) / 100f); float newScale = (float) Math.sqrt((tlist.get(which) - 100f) / 100f);
view.getAnimatedDraggingThread().startZooming(view.getZoom(), newScale, false); zoomScale.set(newScale - (float) Math.sqrt(Math.max(view.getDensity() - 1, 0)));
view.getAnimatedDraggingThread().startZooming(view.getZoom(), view.getSettingsZoomScale(), false);
dialog.dismiss(); dialog.dismiss();
} }
@ -383,14 +378,15 @@ public class MapControlsLayer extends OsmandMapLayer {
bld.show(); bld.show();
return true; return true;
} }
}); };
zoomInButton.setOnLongClickListener(listener);
zoomOutButton.setOnClickListener(new View.OnClickListener() { zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
activity.changeZoom(- 1); activity.changeZoom(- 1);
} }
}); });
zoomOutButton.setOnLongClickListener(listener);
} }

View file

@ -64,23 +64,41 @@ public class MapInfoLayer extends OsmandMapLayer {
private MonitoringInfoControl monitoringServices; private MonitoringInfoControl monitoringServices;
public MapInfoLayer(MapActivity map, RouteLayer layer){ public MapInfoLayer(MapActivity map, RouteLayer layer){
this.map = map; this.map = map;
this.routeLayer = layer; this.routeLayer = layer;
WindowManager mgr = (WindowManager) map.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
mgr.getDefaultDisplay().getMetrics(dm);
scaleCoefficient = dm.density;
if (Math.min(dm.widthPixels / (dm.density * 160), dm.heightPixels / (dm.density * 160)) > 2.5f) {
// large screen
scaleCoefficient *= 1.5f;
} }
public Paint getPaintSmallSubText() {
return paintSmallSubText;
}
public Paint getPaintText() {
return paintText;
}
public Paint getPaintSmallText() {
return paintSmallText;
}
public Paint getPaintSubText() {
return paintSubText;
}
public MonitoringInfoControl getMonitoringInfoControl() {
return monitoringServices;
}
public MapWidgetRegistry getMapInfoControls() {
return mapInfoControls;
}
@Override
public void initLayer(final OsmandMapTileView view) {
this.view = view;
scaleCoefficient = view.getScaleCoefficient();
paintText = new Paint(); paintText = new Paint();
paintText.setStyle(Style.FILL_AND_STROKE); paintText.setStyle(Style.FILL_AND_STROKE);
paintText.setColor(Color.BLACK); paintText.setColor(Color.BLACK);
@ -114,37 +132,7 @@ public class MapInfoLayer extends OsmandMapLayer {
mapInfoControls = new MapWidgetRegistry(map.getMyApplication().getSettings()); mapInfoControls = new MapWidgetRegistry(map.getMyApplication().getSettings());
monitoringServices = new MonitoringInfoControl();
}
public Paint getPaintSmallSubText() {
return paintSmallSubText;
}
public Paint getPaintText() {
return paintText;
}
public Paint getPaintSmallText() {
return paintSmallText;
}
public Paint getPaintSubText() {
return paintSubText;
}
public MonitoringInfoControl getMonitoringInfoControl() {
return monitoringServices;
}
public MapWidgetRegistry getMapInfoControls() {
return mapInfoControls;
}
@Override
public void initLayer(final OsmandMapTileView view) {
this.view = view;
registerAllControls(); registerAllControls();
createControls(); createControls();
} }

View file

@ -129,20 +129,16 @@ public class MapTileLayer extends BaseMapLayer {
final QuadRect tilesRect = tileBox.getTileBounds(); final QuadRect tilesRect = tileBox.getTileBounds();
// recalculate for ellipsoid coordinates // recalculate for ellipsoid coordinates
// TODO elliptic float ellipticTileCorrection = 0;
// if (map.isEllipticYTile()) { if (map.isEllipticYTile()) {
// return (float) MapUtils.getTileEllipsoidNumberY(getZoom(), currentViewport.get); ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
// float ellipticYTile = view.getEllipticYTile(); }
// tilesRect.bottom += (ellipticYTile - tileY);
// tilesRect.top += (ellipticYTile - tileY);
// tileY = ellipticYTile;
// }
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 + ellipticTileCorrection);
int width = (int) FloatMath.ceil(tilesRect.right - left); int width = (int) FloatMath.ceil(tilesRect.right - left);
int height = (int) FloatMath.ceil(tilesRect.bottom - top); int height = (int) FloatMath.ceil(tilesRect.bottom + ellipticTileCorrection - top);
boolean useInternet = settings.USE_INTERNET_TO_DOWNLOAD_TILES.get() boolean useInternet = settings.USE_INTERNET_TO_DOWNLOAD_TILES.get()
&& settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet(); && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet();
@ -154,25 +150,27 @@ public class MapTileLayer extends BaseMapLayer {
for (int j = 0; j < height; j++) { for (int j = 0; j < height; j++) {
int leftPlusI = left + i; int leftPlusI = left + i;
int topPlusJ = top + j; int topPlusJ = top + j;
int x1 = tileBox.getPixXFromTileXNoRot(leftPlusI); int x1 = tileBox.getPixXFromTileXNoRot(leftPlusI);
int x2 = tileBox.getPixXFromTileXNoRot(leftPlusI + 1); int x2 = tileBox.getPixXFromTileXNoRot(leftPlusI + 1);
int y1 = tileBox.getPixYFromTileYNoRot(topPlusJ);
int y2 = tileBox.getPixYFromTileYNoRot(topPlusJ + 1); int y1 = tileBox.getPixYFromTileYNoRot(topPlusJ - ellipticTileCorrection);
// TODO elliptic int y2 = tileBox.getPixYFromTileYNoRot(topPlusJ + 1 - ellipticTileCorrection);
// float y1 = (top + j - tileY) * ftileSize + h; final int tileX = leftPlusI;
String ordImgTile = mgr.calculateTileId(map, leftPlusI, topPlusJ, nzoom); final int tileY = topPlusJ;
String ordImgTile = mgr.calculateTileId(map, tileX, tileY, nzoom);
// asking tile image async // asking tile image async
boolean imgExist = mgr.tileExistOnFileSystem(ordImgTile, map, leftPlusI, topPlusJ, nzoom, false); boolean imgExist = mgr.tileExistOnFileSystem(ordImgTile, map, tileX, tileY, nzoom, false);
Bitmap bmp = null; Bitmap bmp = null;
boolean originalBeLoaded = useInternet && nzoom <= maxLevel; boolean originalBeLoaded = useInternet && nzoom <= maxLevel;
if (imgExist || originalBeLoaded) { if (imgExist || originalBeLoaded) {
bmp = mgr.getTileImageForMapAsync(ordImgTile, map, leftPlusI, topPlusJ, nzoom, useInternet); bmp = mgr.getTileImageForMapAsync(ordImgTile, map, tileX, tileY, nzoom, useInternet);
} }
if (bmp == null) { if (bmp == null) {
int div = 2; int div = 2;
// asking if there is small version of the map (in cache) // asking if there is small version of the map (in cache)
String imgTile2 = mgr.calculateTileId(map, leftPlusI / 2, topPlusJ / 2, nzoom - 1); String imgTile2 = mgr.calculateTileId(map, tileX / 2, tileY / 2, nzoom - 1);
String imgTile4 = mgr.calculateTileId(map, leftPlusI / 4, topPlusJ / 4, nzoom - 2); String imgTile4 = mgr.calculateTileId(map, tileX / 4, tileY / 4, nzoom - 2);
if (originalBeLoaded || imgExist) { if (originalBeLoaded || imgExist) {
bmp = mgr.getTileImageFromCache(imgTile2); bmp = mgr.getTileImageFromCache(imgTile2);
div = 2; div = 2;
@ -182,13 +180,13 @@ public class MapTileLayer extends BaseMapLayer {
} }
} }
if (!originalBeLoaded && !imgExist) { if (!originalBeLoaded && !imgExist) {
if (mgr.tileExistOnFileSystem(imgTile2, map, leftPlusI / 2, topPlusJ / 2, nzoom - 1, false) if (mgr.tileExistOnFileSystem(imgTile2, map, tileX / 2, tileY / 2, nzoom - 1, false)
|| (useInternet && nzoom - 1 <= maxLevel)) { || (useInternet && nzoom - 1 <= maxLevel)) {
bmp = mgr.getTileImageForMapAsync(imgTile2, map, leftPlusI / 2, topPlusJ / 2, nzoom - 1, useInternet); bmp = mgr.getTileImageForMapAsync(imgTile2, map, tileX / 2, tileY / 2, nzoom - 1, useInternet);
div = 2; div = 2;
} else if (mgr.tileExistOnFileSystem(imgTile4, map, leftPlusI / 4, topPlusJ / 4, nzoom - 2, false) } else if (mgr.tileExistOnFileSystem(imgTile4, map, tileX / 4, tileY / 4, nzoom - 2, false)
|| (useInternet && nzoom - 2 <= maxLevel)) { || (useInternet && nzoom - 2 <= maxLevel)) {
bmp = mgr.getTileImageForMapAsync(imgTile4, map, leftPlusI / 4, topPlusJ / 4, nzoom - 2, useInternet); bmp = mgr.getTileImageForMapAsync(imgTile4, map, tileX / 4, tileY / 4, nzoom - 2, useInternet);
div = 4; div = 4;
} }
} }

View file

@ -4,6 +4,7 @@ import java.lang.reflect.Method;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import android.content.Context; import android.content.Context;
@ -118,7 +119,7 @@ public class MultiTouchSupport {
return true; return true;
} else if(inZoomMode && actionCode == MotionEvent.ACTION_MOVE){ } else if(inZoomMode && actionCode == MotionEvent.ACTION_MOVE){
if(angleDefined) { if(angleDefined) {
angleRelative = angle - angleStarted; angleRelative = MapUtils.unifyRotationTo360(angle - angleStarted);
} }
zoomRelative = distance / zoomStartedDistance; zoomRelative = distance / zoomStartedDistance;
listener.onZoomingOrRotating(zoomRelative, angleRelative); listener.onZoomingOrRotating(zoomRelative, angleRelative);

View file

@ -234,7 +234,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
public void setIntZoom(int zoom) { public void setIntZoom(int zoom) {
if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) { if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) {
animatedDraggingThread.stopAnimating(); animatedDraggingThread.stopAnimating();
currentViewport.setZoom(zoom, currentViewport.getZoomScale(), 0); currentViewport.setZoomAndAnimation(zoom, 0);
currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0 ); currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0 );
refreshMap(); refreshMap();
} }
@ -294,6 +294,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
return currentViewport.getZoom(); return currentViewport.getZoom();
} }
public float getSettingsZoomScale(){
return settings.MAP_ZOOM_SCALE_BY_DENSITY.get() + (float)Math.sqrt(Math.max(0, getDensity() - 1));
}
public float getZoomScale() { public float getZoomScale() {
return currentViewport.getZoomScale(); return currentViewport.getZoomScale();
} }
@ -327,7 +331,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
if (mainLayer.getMinimumShownMapZoom() > zoom) { if (mainLayer.getMinimumShownMapZoom() > zoom) {
zoom = mainLayer.getMinimumShownMapZoom(); zoom = mainLayer.getMinimumShownMapZoom();
} }
currentViewport.setZoom(zoom, currentViewport.getZoomScale()); currentViewport.setZoomAndAnimation(zoom, 0);
refreshMap(); refreshMap();
} }
@ -527,8 +531,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
// for internal usage // for internal usage
protected void zoomToAnimate(float tzoom, boolean notify) { protected void zoomToAnimate(float tzoom, boolean notify) {
int zoom = getZoom(); int zoom = getZoom();
float zoomToScale = getZoomScale(); float zoomToAnimate = tzoom - zoom - getZoomScale();
float zoomToAnimate = tzoom - zoom - zoomToScale;
if(zoomToAnimate >= 1) { if(zoomToAnimate >= 1) {
zoom += (int) zoomToAnimate; zoom += (int) zoomToAnimate;
zoomToAnimate -= (int) zoomToAnimate; zoomToAnimate -= (int) zoomToAnimate;
@ -538,7 +541,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
zoomToAnimate += 1; zoomToAnimate += 1;
} }
if (mainLayer != null && mainLayer.getMaximumShownMapZoom() >= zoom && mainLayer.getMinimumShownMapZoom() <= zoom) { if (mainLayer != null && mainLayer.getMaximumShownMapZoom() >= zoom && mainLayer.getMinimumShownMapZoom() <= zoom) {
currentViewport.setZoom(zoom, zoomToScale, zoomToAnimate); currentViewport.setZoomAndAnimation(zoom, zoomToAnimate);
currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0 ); currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0 );
refreshMap(); refreshMap();
if (notify && locationListener != null) { if (notify && locationListener != null) {
@ -625,9 +628,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
@Override @Override
public void onZoomEnded(double relativeToStart, float angleRelative) { public void onZoomEnded(double relativeToStart, float angleRelative) {
// 1.5 works better even on dm.density=1 devices
float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f; float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f;
setComplexZoom(Math.round(dz) + initialViewport.getZoom(), initialViewport.getZoomScale()); setIntZoom(Math.round(dz) + initialViewport.getZoom());
if(Math.abs(angleRelative) < 15){ if(Math.abs(angleRelative) < 17){
angleRelative = 0; angleRelative = 0;
} }
rotateToAnimate(initialViewport.getRotate() + angleRelative); rotateToAnimate(initialViewport.getRotate() + angleRelative);
@ -667,7 +671,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
// keep only rotating // keep only rotating
dz = 0; dz = 0;
} }
if(Math.abs(relAngle) < 20 && !startRotating) { if(Math.abs(relAngle) < 17 && !startRotating) {
relAngle = 0; relAngle = 0;
} else { } else {
startRotating = true; startRotating = true;
@ -688,7 +692,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
float calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale(); float calcZoom = initialViewport.getZoom() + dz + initialViewport.getZoomScale();
float calcRotate = calc.getRotate() + angle; float calcRotate = calc.getRotate() + angle;
calc.setRotate(angle); calc.setRotate(angle);
calc.setZoom(initialViewport.getZoom(), dz + initialViewport.getZoomScale()); calc.setZoomAnimation(dz);
final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy); final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy);
setLatLon(r.getLatitude(), r.getLongitude()); setLatLon(r.getLatitude(), r.getLongitude());
if (Math.abs(currentViewport.getZoomAnimation() + currentViewport.getZoom() + currentViewport.getZoomScale() - if (Math.abs(currentViewport.getZoomAnimation() + currentViewport.getZoom() + currentViewport.getZoomScale() -

View file

@ -26,7 +26,6 @@ public class PointLocationLayer extends OsmandMapLayer {
private Paint aroundArea; private Paint aroundArea;
private Paint headingPaint; private Paint headingPaint;
private DisplayMetrics dm;
private OsmandMapTileView view; private OsmandMapTileView view;
private ApplicationMode appMode; private ApplicationMode appMode;
@ -65,9 +64,6 @@ public class PointLocationLayer extends OsmandMapLayer {
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
initUI(); initUI();
dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
} }
@ -96,7 +92,7 @@ public class PointLocationLayer extends OsmandMapLayer {
final double dist = box.getDistance(0, box.getPixHeight() / 2, box.getPixWidth(), box.getPixHeight() / 2); final double dist = box.getDistance(0, box.getPixHeight() / 2, box.getPixWidth(), box.getPixHeight() / 2);
int radius = (int) (((double) box.getPixWidth()) / dist * lastKnownLocation.getAccuracy()); int radius = (int) (((double) box.getPixWidth()) / dist * lastKnownLocation.getAccuracy());
if (radius > RADIUS * dm.density) { if (radius > RADIUS * box.getDensity()) {
int allowedRad = Math.min(box.getPixWidth() / 2, box.getPixHeight() / 2); int allowedRad = Math.min(box.getPixWidth() / 2, box.getPixHeight() / 2);
canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), area); canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), area);
canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), aroundArea); canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), aroundArea);

View file

@ -32,13 +32,12 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
private View info; private View info;
public static int directionInfo = -1; public static int directionInfo = -1;
private DisplayMetrics dm;
private final ContextMenuLayer contextMenu; private final ContextMenuLayer contextMenu;
public RouteInfoLayer(RoutingHelper routingHelper, MapActivity activity, ContextMenuLayer contextMenu){ public RouteInfoLayer(RoutingHelper routingHelper, MapActivity activity, ContextMenuLayer contextMenu){
createLayout(activity); createLayout(activity, activity.getMapView().getDensity());
this.routingHelper = routingHelper; this.routingHelper = routingHelper;
this.contextMenu = contextMenu; this.contextMenu = contextMenu;
routingHelper.addListener(this); routingHelper.addListener(this);
@ -50,12 +49,11 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
activity.accessibleContent.add(info); activity.accessibleContent.add(info);
} }
private void createLayout(MapActivity activity) { private void createLayout(MapActivity activity, float density) {
FrameLayout fl = (FrameLayout) activity.getMapView().getParent(); FrameLayout fl = (FrameLayout) activity.getMapView().getParent();
LinearLayout ll = new LinearLayout(activity); LinearLayout ll = new LinearLayout(activity);
ll.setOrientation(LinearLayout.HORIZONTAL); ll.setOrientation(LinearLayout.HORIZONTAL);
DisplayMetrics dm = activity.getResources().getDisplayMetrics(); ll.setPadding(0, 0, (int) (density * 15), (int) (density * 50));
ll.setPadding(0, 0, (int) (dm.density * 15), (int) (dm.density * 50));
fl.addView(ll, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER)); fl.addView(ll, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER));
prev = new ImageButton(activity); prev = new ImageButton(activity);
prev.setContentDescription(activity.getString(R.string.previous_button)); prev.setContentDescription(activity.getString(R.string.previous_button));
@ -63,12 +61,12 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
ll.addView(prev); ll.addView(prev);
info = new ImageButton(activity); info = new ImageButton(activity);
info.setContentDescription(activity.getString(R.string.info_button)); info.setContentDescription(activity.getString(R.string.info_button));
info.setPadding((int) (dm.density * 8), 0, 0, 0); info.setPadding((int) (density * 8), 0, 0, 0);
info.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.ax_2_action_about_light)); info.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.ax_2_action_about_light));
ll.addView(info); ll.addView(info);
next = new ImageButton(activity); next = new ImageButton(activity);
next.setContentDescription(activity.getString(R.string.next_button)); next.setContentDescription(activity.getString(R.string.next_button));
next.setPadding((int) (dm.density * 8), 0, 0, 0); next.setPadding((int) (density * 8), 0, 0, 0);
next.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.ax_1_navigation_next_item_light)); next.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.ax_1_navigation_next_item_light));
ll.addView(next); ll.addView(next);
} }
@ -76,9 +74,6 @@ public class RouteInfoLayer extends OsmandMapLayer implements IRouteInformationL
@Override @Override
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
} }
private void attachListeners() { private void attachListeners() {

View file

@ -25,7 +25,6 @@ public class TransportInfoLayer extends OsmandMapLayer {
private Paint paintInt; private Paint paintInt;
private Paint paintEnd; private Paint paintEnd;
private boolean visible = true; private boolean visible = true;
private DisplayMetrics dm;
public TransportInfoLayer(TransportRouteHelper routeHelper){ public TransportInfoLayer(TransportRouteHelper routeHelper){
this.routeHelper = routeHelper; this.routeHelper = routeHelper;
@ -34,9 +33,6 @@ public class TransportInfoLayer extends OsmandMapLayer {
@Override @Override
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
paintInt = new Paint(); paintInt = new Paint();
paintInt.setColor(view.getResources().getColor(R.color.transport_int)); paintInt.setColor(view.getResources().getColor(R.color.transport_int));
@ -56,9 +52,9 @@ public class TransportInfoLayer extends OsmandMapLayer {
public int getRadius(RotatedTileBox tb){ public int getRadius(RotatedTileBox tb){
final float zoom = tb.getZoom() + tb.getZoomScale(); final float zoom = tb.getZoom() + tb.getZoomScale();
if(zoom <= 16) { if(zoom <= 16) {
return (int) (dm.density * 8); return (int) (tb.getDensity() * 8);
} }
return (int) (dm.density * 10); return (int) (tb.getDensity() * 10);
} }
@Override @Override

View file

@ -107,7 +107,7 @@ public class AppearanceWidgetsFactory {
if (EXTRA_SETTINGS) { if (EXTRA_SETTINGS) {
// previous extra settings // previous extra settings
final OsmandSettings.OsmandPreference<Float> textSizePref = view.getSettings().MAP_TEXT_SIZE; /*final OsmandSettings.OsmandPreference<Float> textSizePref = view.getSettings().MAP_TEXT_SIZE;
final MapWidgetRegistry.MapWidgetRegInfo textSize = mapInfoControls.registerAppearanceWidget(R.drawable.widget_text_size, R.string.map_text_size, final MapWidgetRegistry.MapWidgetRegInfo textSize = mapInfoControls.registerAppearanceWidget(R.drawable.widget_text_size, R.string.map_text_size,
"text_size", textSizePref); "text_size", textSizePref);
textSize.setStateChangeListener(new Runnable() { textSize.setStateChangeListener(new Runnable() {
@ -132,7 +132,7 @@ public class AppearanceWidgetsFactory {
}); });
b.show(); b.show();
} }
}); });*/
final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler, final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler,
"showRuler", view.getSettings().SHOW_RULER); "showRuler", view.getSettings().SHOW_RULER);