Refactor structure
This commit is contained in:
parent
4e72e3c3b5
commit
2b383859a5
5 changed files with 133 additions and 111 deletions
|
@ -51,6 +51,7 @@ import net.osmand.plus.views.POIMapLayer;
|
|||
import net.osmand.plus.views.PointLocationLayer;
|
||||
import net.osmand.plus.views.PointNavigationLayer;
|
||||
import net.osmand.plus.views.RouteLayer;
|
||||
import net.osmand.plus.views.RulerControlLayer;
|
||||
import net.osmand.plus.views.TransportStopsLayer;
|
||||
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
|
||||
|
||||
|
@ -75,6 +76,7 @@ public class MapActivityLayers {
|
|||
private FavouritesLayer mFavouritesLayer;
|
||||
private TransportStopsLayer transportStopsLayer;
|
||||
private PointLocationLayer locationLayer;
|
||||
private RulerControlLayer rulerControlLayer;
|
||||
private PointNavigationLayer navigationLayer;
|
||||
private MapMarkersLayer mapMarkersLayer;
|
||||
private ImpassableRoadsLayer impassableRoadsLayer;
|
||||
|
@ -162,6 +164,9 @@ public class MapActivityLayers {
|
|||
// 7.5 Impassible roads
|
||||
impassableRoadsLayer = new ImpassableRoadsLayer(activity);
|
||||
mapView.addLayer(impassableRoadsLayer, 7.5f);
|
||||
// 7.8 ruler control layer
|
||||
rulerControlLayer = new RulerControlLayer(activity);
|
||||
mapView.addLayer(rulerControlLayer, 7.8f);
|
||||
// 8. context menu layer
|
||||
// 9. map info layer
|
||||
mapInfoLayer = new MapInfoLayer(activity, routeLayer);
|
||||
|
@ -586,6 +591,10 @@ public class MapActivityLayers {
|
|||
return locationLayer;
|
||||
}
|
||||
|
||||
public RulerControlLayer getRulerControlLayer() {
|
||||
return rulerControlLayer;
|
||||
}
|
||||
|
||||
public MapInfoLayer getMapInfoLayer() {
|
||||
return mapInfoLayer;
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
registerSideWidget(plainTime, R.drawable.ic_action_time, R.string.map_widget_plain_time, "plain_time", false, 41);
|
||||
TextInfoWidget battery = ric.createBatteryControl(map);
|
||||
registerSideWidget(battery, R.drawable.ic_action_battery, R.string.map_widget_battery, "battery", false, 42);
|
||||
TextInfoWidget ruler = ric.createRulerControl(map);
|
||||
TextInfoWidget ruler = mic.createRulerControl(map);
|
||||
registerSideWidget(ruler, R.drawable.ic_action_ruler, R.string.map_widget_show_ruler, "ruler", false, 43);
|
||||
}
|
||||
|
||||
|
|
101
OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java
Normal file
101
OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java
Normal file
|
@ -0,0 +1,101 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.DashPathEffect;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.QuadPoint;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
public class RulerControlLayer extends OsmandMapLayer {
|
||||
|
||||
private Bitmap centerIcon;
|
||||
private Paint bitmapPaint;
|
||||
private Paint linePaint;
|
||||
private Location currentLoc;
|
||||
private LatLon centerLoc;
|
||||
private String title;
|
||||
private String text;
|
||||
private String subtext;
|
||||
private MapActivity mapActivity;
|
||||
|
||||
public RulerControlLayer(MapActivity mapActivity) {
|
||||
this.mapActivity = mapActivity;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getSubtext() {
|
||||
return subtext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
centerIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center);
|
||||
title = view.getResources().getString(R.string.map_widget_show_ruler);
|
||||
text = title;
|
||||
|
||||
bitmapPaint = new Paint();
|
||||
bitmapPaint.setAntiAlias(true);
|
||||
bitmapPaint.setDither(true);
|
||||
bitmapPaint.setFilterBitmap(true);
|
||||
|
||||
linePaint = new Paint();
|
||||
linePaint.setAntiAlias(true);
|
||||
linePaint.setStyle(Style.STROKE);
|
||||
linePaint.setStrokeWidth(10);
|
||||
linePaint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
if (mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler")) {
|
||||
final QuadPoint centerPos = tileBox.getCenterPixelPoint();
|
||||
canvas.drawBitmap(centerIcon, centerPos.x - centerIcon.getWidth() / 2,
|
||||
centerPos.y - centerIcon.getHeight() / 2, bitmapPaint);
|
||||
centerLoc = tileBox.getCenterLatLon();
|
||||
updateText();
|
||||
if (currentLoc != null) {
|
||||
int currentLocX = tileBox.getPixXFromLonNoRot(currentLoc.getLongitude());
|
||||
int currentLocY = tileBox.getPixYFromLatNoRot(currentLoc.getLatitude());
|
||||
canvas.drawLine(currentLocX, currentLocY, centerPos.x, centerPos.y, linePaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateText() {
|
||||
currentLoc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
if (currentLoc != null && centerLoc != null) {
|
||||
float dist = (float) MapUtils.getDistance(currentLoc.getLatitude(), currentLoc.getLongitude(),
|
||||
centerLoc.getLatitude(), centerLoc.getLongitude());
|
||||
String distance = OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication());
|
||||
int ls = distance.lastIndexOf(' ');
|
||||
text = distance.substring(0, ls);
|
||||
subtext = distance.substring(ls + 1);
|
||||
} else {
|
||||
text = title;
|
||||
subtext = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drawInScreenPixels() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package net.osmand.plus.views.mapwidgets;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -29,6 +28,7 @@ import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
|||
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||
import net.osmand.plus.views.RulerControlLayer;
|
||||
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable;
|
||||
import net.osmand.router.TurnType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -108,6 +108,27 @@ public class MapInfoWidgetsFactory {
|
|||
return gpsInfoControl;
|
||||
}
|
||||
|
||||
public TextInfoWidget createRulerControl(final MapActivity map) {
|
||||
final RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();
|
||||
TextInfoWidget rulerControl = new TextInfoWidget(map) {
|
||||
@Override
|
||||
public boolean updateInfo(DrawSettings drawSettings) {
|
||||
setText(rulerLayer.getText(), rulerLayer.getSubtext());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
rulerControl.setIcons(R.drawable.widget_distance_day, R.drawable.widget_distance_night);
|
||||
rulerControl.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return rulerControl;
|
||||
}
|
||||
|
||||
public static class TopToolbarController {
|
||||
private TopToolbarControllerType type;
|
||||
|
||||
|
|
|
@ -380,115 +380,6 @@ public class RouteInfoWidgetsFactory {
|
|||
return batteryControl;
|
||||
}
|
||||
|
||||
public TextInfoWidget createRulerControl(final MapActivity map) {
|
||||
RulerControl rulerControl = new RulerControl(map);
|
||||
map.getMapView().addLayer(rulerControl.getRulerControlLayer(), 4.5f);
|
||||
return rulerControl;
|
||||
}
|
||||
|
||||
public class RulerControl extends TextInfoWidget {
|
||||
|
||||
private String title;
|
||||
private MapActivity mapActivity;
|
||||
private Location currentLoc;
|
||||
private LatLon centerLoc;
|
||||
|
||||
public RulerControl(Activity activity) {
|
||||
super(activity);
|
||||
mapActivity = (MapActivity) activity;
|
||||
title = mapActivity.getResources().getString(R.string.map_widget_show_ruler);
|
||||
|
||||
setIcons(R.drawable.widget_distance_day, R.drawable.widget_distance_night);
|
||||
setText(title, null);
|
||||
addOnClickListener();
|
||||
addLocationListener();
|
||||
}
|
||||
|
||||
private void addOnClickListener() {
|
||||
setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addLocationListener() {
|
||||
mapActivity.getMyApplication().getLocationProvider().addLocationListener(new OsmAndLocationListener() {
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
currentLoc = location;
|
||||
updateText();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public OsmandMapLayer getRulerControlLayer() {
|
||||
return new RulerControlLayer();
|
||||
}
|
||||
|
||||
private void updateText() {
|
||||
if (currentLoc != null && centerLoc != null) {
|
||||
float dist = (float) MapUtils.getDistance(currentLoc.getLatitude(), currentLoc.getLongitude(),
|
||||
centerLoc.getLatitude(), centerLoc.getLongitude());
|
||||
String distance = OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication());
|
||||
int ls = distance.lastIndexOf(' ');
|
||||
setText(distance.substring(0, ls), distance.substring(ls + 1));
|
||||
} else {
|
||||
setText(title, null);
|
||||
}
|
||||
}
|
||||
|
||||
private class RulerControlLayer extends OsmandMapLayer {
|
||||
|
||||
private Bitmap centerIcon;
|
||||
private Paint bitmapPaint;
|
||||
private Paint linePaint;
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
centerIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center);
|
||||
|
||||
bitmapPaint = new Paint();
|
||||
bitmapPaint.setAntiAlias(true);
|
||||
bitmapPaint.setDither(true);
|
||||
bitmapPaint.setFilterBitmap(true);
|
||||
|
||||
linePaint = new Paint();
|
||||
linePaint.setAntiAlias(true);
|
||||
linePaint.setStyle(Style.STROKE);
|
||||
linePaint.setStrokeWidth(10);
|
||||
linePaint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
if (isVisible()) {
|
||||
final QuadPoint centerPos = tileBox.getCenterPixelPoint();
|
||||
canvas.drawBitmap(centerIcon, centerPos.x - centerIcon.getWidth() / 2,
|
||||
centerPos.y - centerIcon.getHeight() / 2, bitmapPaint);
|
||||
centerLoc = tileBox.getCenterLatLon();
|
||||
updateText();
|
||||
if (currentLoc != null) {
|
||||
int currentLocX = tileBox.getPixXFromLonNoRot(currentLoc.getLongitude());
|
||||
int currentLocY = tileBox.getPixYFromLatNoRot(currentLoc.getLatitude());
|
||||
canvas.drawLine(currentLocX, currentLocY, centerPos.x, centerPos.y, linePaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drawInScreenPixels() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextInfoWidget createMaxSpeedControl(final MapActivity map) {
|
||||
final RoutingHelper rh = map.getMyApplication().getRoutingHelper();
|
||||
final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider();
|
||||
|
|
Loading…
Reference in a new issue