Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-02-26 11:29:25 +01:00
commit 82fc61f3fd
5 changed files with 110 additions and 4 deletions

View file

@ -202,6 +202,16 @@ public class MapMarkersHelper {
return list;
}
public List<LatLon> getSelectedMarkersLatLon() {
List<LatLon> list = new ArrayList<>();
for (MapMarker m : this.mapMarkers) {
if (m.selected) {
list.add(m.point);
}
}
return list;
}
public List<LatLon> getMarkersHistoryLatLon() {
List<LatLon> list = new ArrayList<>();
for (MapMarker m : this.mapMarkersHistory) {

View file

@ -38,11 +38,13 @@ import com.github.ksoichiro.android.observablescrollview.ScrollState;
import net.osmand.PlatformUtil;
import net.osmand.ValueHolder;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.OsmandApplication;
@ -772,6 +774,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} else {
if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION) {
getMyApplication().getMapMarkersHelper().removeListener(this);
mapActivity.getMapLayers().getMapMarkersLayer().clearRoute();
}
if (swipeDismissListener != null) {
swipeDismissListener.discardUndo();
@ -859,6 +862,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
setDynamicListItems(listView, listAdapter);
updateListAdapter(listAdapter, listener);
if (visibleType == DashboardType.MAP_MARKERS_SELECTION) {
showMarkersRouteOnMap();
}
} else {
@ -904,7 +910,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
View v = listView.getChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop());
updateListAdapter();
((ListView)listView).setSelectionFromTop(index, top);
((ListView) listView).setSelectionFromTop(index, top);
} else {
listAdapter.notifyDataSetChanged();
}
@ -1388,6 +1394,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} else if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION) {
List<MapMarker> markers = (List<MapMarker>) (Object) items;
getMyApplication().getMapMarkersHelper().saveMapMarkers(markers, null);
if (visibleType == DashboardType.MAP_MARKERS_SELECTION) {
showMarkersRouteOnMap();
}
}
if (swipeDismissListener != null) {
@ -1426,6 +1435,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
waypointDialogHelper.reloadListAdapter(stableAdapter);
} else if (DashboardType.MAP_MARKERS == visibleType || visibleType == DashboardType.MAP_MARKERS_SELECTION) {
mapMarkerDialogHelper.reloadListAdapter(stableAdapter);
if (visibleType == DashboardType.MAP_MARKERS_SELECTION) {
showMarkersRouteOnMap();
}
}
setDynamicListItems(listView, stableAdapter);
}
@ -1446,4 +1458,44 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
public void deleteMapMarker(int position) {
deleteSwipeItem(position);
}
@Override
public void showMarkersRouteOnMap() {
MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
List<LatLon> points = helper.getSelectedMarkersLatLon();
mapActivity.getMapLayers().getMapMarkersLayer().setRoute(points);
showRouteOnMap(points);
}
public void showRouteOnMap(List<LatLon> points) {
if (points.size() > 0 && mapActivity != null) {
OsmandMapTileView mapView = mapActivity.getMapView();
double left = 0, right = 0;
double top = 0, bottom = 0;
for (LatLon l : points) {
if (left == 0) {
left = l.getLongitude();
right = l.getLongitude();
top = l.getLatitude();
bottom = l.getLatitude();
} else {
left = Math.min(left, l.getLongitude());
right = Math.max(right, l.getLongitude());
top = Math.max(top, l.getLatitude());
bottom = Math.min(bottom, l.getLatitude());
}
}
RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
int tileBoxWidthPx = 0;
int tileBoxHeightPx = 0;
if (landscape) {
tileBoxWidthPx = tb.getPixWidth() - dashboardView.getWidth();
} else if (listBackgroundView != null) {
tileBoxHeightPx = 3 * (mFlexibleSpaceImageHeight - mFlexibleBlurSpaceHeight) / 4;
}
mapView.fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, mFlexibleBlurSpaceHeight * 3/2);
}
}
}

View file

@ -76,8 +76,8 @@ public class MapMarkerDialogHelper {
public interface MapMarkersDialogHelperCallbacks {
void reloadAdapter();
void deleteMapMarker(int position);
void showMarkersRouteOnMap();
}
public MapMarkerDialogHelper(MapActivity mapActivity) {
@ -126,6 +126,9 @@ public class MapMarkerDialogHelper {
checkBox.setChecked(!checkBox.isChecked());
marker.selected = checkBox.isChecked();
markersHelper.updateMapMarker(marker, false);
if (helperCallbacks != null) {
helperCallbacks.showMarkersRouteOnMap();
}
} else {
if (!marker.history) {
showMarkerOnMap(mapActivity, marker);

View file

@ -4,6 +4,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
@ -12,7 +13,6 @@ import android.os.Message;
import android.view.GestureDetector;
import android.view.MotionEvent;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
@ -26,6 +26,7 @@ import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProviderSelection;
import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory;
import java.util.ArrayList;
import java.util.List;
public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection {
@ -57,6 +58,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
private Bitmap arrowToDestination;
private float[] calculations = new float[2];
private Paint paint;
private Path path;
private List<LatLon> route = new ArrayList<>();
private LatLon fingerLocation;
private boolean hasMoved;
private boolean moving;
@ -94,6 +99,16 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
bitmapPaintDestTeal = createPaintDest(R.color.marker_teal);
bitmapPaintDestPurple = createPaintDest(R.color.marker_purple);
path = new Path();
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(7 * view.getDensity());
paint.setAntiAlias(true);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setColor(map.getResources().getColor(R.color.marker_red));
paint.setAlpha(200);
widgetsFactory = new MapMarkersWidgetsFactory(map);
}
@ -149,6 +164,15 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
}
}
public void setRoute(List<LatLon> points) {
route.clear();
route.addAll(points);
}
public void clearRoute() {
route.clear();
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
@ -196,6 +220,22 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
return;
}
if (route.size() > 0) {
path.reset();
boolean first = true;
for (LatLon point : route) {
int locationX = tb.getPixXFromLonNoRot(point.getLongitude());
int locationY = tb.getPixYFromLatNoRot(point.getLatitude());
if (first) {
path.moveTo(locationX, locationY);
first = false;
} else {
path.lineTo(locationX, locationY);
}
}
canvas.drawPath(path, paint);
}
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
List<MapMarker> activeMapMarkers = markersHelper.getActiveMapMarkers();
for (int i = 0; i < activeMapMarkers.size(); i++) {

View file

@ -169,7 +169,8 @@ public class MapMarkersWidgetsFactory {
}
public boolean isTopBarVisible() {
return topBar.getVisibility() == View.VISIBLE;
return topBar.getVisibility() == View.VISIBLE
&& map.findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE;
}
public void updateInfo(LatLon customLocation, int zoom) {