diff --git a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml index 1e0030de66..27b9b86b1b 100644 --- a/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_show_direction_bottom_sheet_dialog.xml @@ -115,6 +115,67 @@ + + + + + + + + + + + + + + + + + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:background="@null" + android:clickable="false" + android:focusable="false"/> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ad814a51a3..953168a80d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Show guide line + Show arrows on the map Show passed Hide passed Remove from Map Markers diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b533b3857e..3a2eeb4405 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -713,6 +713,9 @@ public class OsmandSettings { public final CommonPreference RULER_MODE = new EnumIntPreference<>("ruler_mode", RulerMode.FIRST, RulerMode.values()).makeGlobal(); + public final CommonPreference SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", true).makeGlobal(); + public final CommonPreference SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", true).makeGlobal(); + public final CommonPreference USE_MAPILLARY_FILTER = new BooleanPreference("use_mapillary_filters", false).makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USER_KEY = new StringPreference("mapillary_filter_user_key", "").makeGlobal(); public final CommonPreference MAPILLARY_FILTER_USERNAME = new StringPreference("mapillary_filter_username", "").makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 43148b2a13..73038dbba8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapmarkers; +import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; @@ -12,6 +13,7 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; +import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.TextView; @@ -19,6 +21,7 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -38,8 +41,9 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final OsmandSettings settings = getMyApplication().getSettings(); portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = !getMyApplication().getSettings().isLightContent(); + night = !settings.isLightContent(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); @@ -47,7 +51,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); } - OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); + OsmandSettings.MapMarkersMode mode = settings.MAP_MARKERS_MODE.get(); highlightSelectedItem(mode, true); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { @@ -84,6 +88,32 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } + CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch); + showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); + mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + settings.SHOW_ARROWS_TO_FIRST_MARKERS.set(!settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()); + if (getMapActivity() != null) { + getMapActivity().refreshMap(); + } + dismiss(); + } + }); + + CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch); + showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get()); + mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + settings.SHOW_LINES_TO_FIRST_MARKERS.set(!settings.SHOW_LINES_TO_FIRST_MARKERS.get()); + if (getMapActivity() != null) { + getMapActivity().refreshMap(); + } + dismiss(); + } + }); + ImageView topBarIcon = (ImageView) mainView.findViewById(R.id.top_bar_icon); topBarIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color)); topBarIcon.setImageDrawable(getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue)); @@ -157,6 +187,14 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } } + private MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity != null) { + return (MapActivity) activity; + } + return null; + } + private void highlightSelectedItem(OsmandSettings.MapMarkersMode mode, boolean check) { int iconBgColor = check ? R.color.dashboard_blue : R.color.on_map_icon_color; int iconColor = check ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue; diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 8107ee7ba7..820ab2986b 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -8,13 +8,9 @@ import android.graphics.Path; import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; -import android.os.Handler; -import android.os.Message; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; -import android.view.GestureDetector; -import android.view.MotionEvent; import net.osmand.Location; import net.osmand.data.LatLon; @@ -23,7 +19,6 @@ import net.osmand.data.QuadPoint; import net.osmand.data.RotatedTileBox; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; -import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -39,8 +34,6 @@ import java.util.List; public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { protected static final int DIST_TO_SHOW = 80; - protected static final long USE_FINGER_LOCATION_DELAY = 1000; - private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 6; private final MapActivity map; private OsmandMapTileView view; @@ -66,17 +59,11 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private Bitmap arrowToDestination; private float[] calculations = new float[2]; + private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); private Paint paint; private Path path; private List route = new ArrayList<>(); - private LatLon fingerLocation; - private boolean hasMoved; - private boolean moving; - private boolean useFingerLocation; - private GestureDetector longTapDetector; - private Handler handler; - private ContextMenuLayer contextMenuLayer; public MapMarkersLayer(MapActivity map) { @@ -190,50 +177,23 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi @Override public void initLayer(OsmandMapTileView view) { this.view = view; - handler = new Handler(); initUI(); - longTapDetector = new GestureDetector(view.getContext(), new GestureDetector.OnGestureListener() { - @Override - public boolean onDown(MotionEvent e) { - return false; - } - - @Override - public void onShowPress(MotionEvent e) { - - } - - @Override - public boolean onSingleTapUp(MotionEvent e) { - return false; - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - return false; - } - - @Override - public void onLongPress(MotionEvent e) { - cancelFingerAction(); - } - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - return false; - } - }); } @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tileBox.getZoom()); + Location myLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation(); + widgetsFactory.updateInfo(myLoc == null + ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom()); + OsmandSettings settings = map.getMyApplication().getSettings(); - if (tileBox.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) { + if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) { return; } + lineAttrs.updatePaints(view, nightMode, tileBox); + MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); if (route.size() > 0) { path.reset(); @@ -259,6 +219,17 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } List activeMapMarkers = markersHelper.getMapMarkers(); + + if (settings.SHOW_LINES_TO_FIRST_MARKERS.get()) { + int locX = myLoc == null ? tileBox.getCenterPixelX() : tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); + int locY = myLoc == null ? tileBox.getCenterPixelY() : tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); + for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { + int markerX = tileBox.getPixXFromLonNoRot(activeMapMarkers.get(i).getLongitude()); + int markerY = tileBox.getPixYFromLatNoRot(activeMapMarkers.get(i).getLatitude()); + canvas.drawLine(locX, locY, markerX, markerY, lineAttrs.paint); + } + } + for (MapMarker marker : activeMapMarkers) { if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) && !isInMotion(marker)) { @@ -273,34 +244,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } } - boolean show = useFingerLocation || - (map.getMyApplication().getSettings().MAP_MARKERS_MODE.get() == OsmandSettings.MapMarkersMode.WIDGETS - && map.getMyApplication().getSettings().SHOW_DESTINATION_ARROW.get()); - if (show) { - LatLon loc = fingerLocation; - if (!useFingerLocation) { - loc = tileBox.getCenterLatLon(); - } - if (loc != null) { - List mapMarkers = markersHelper.getMapMarkers(); - int i = 0; - for (MapMarker marker : mapMarkers) { - if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { - canvas.save(); - net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), - marker.getLatitude(), marker.getLongitude(), calculations); - float bearing = calculations[1] - 90; - float radiusBearing = DIST_TO_SHOW * tileBox.getDensity(); - final QuadPoint cp = tileBox.getCenterPixelPoint(); - canvas.rotate(bearing, cp.x, cp.y); - canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity()); - canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex)); - canvas.restore(); - } - i++; - if (i > 1) { - break; - } + if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) { + LatLon loc = myLoc == null ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()); + List mapMarkers = markersHelper.getMapMarkers(); + int i = 0; + for (MapMarker marker : mapMarkers) { + if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { + canvas.save(); + net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), + marker.getLatitude(), marker.getLongitude(), calculations); + float bearing = calculations[1] - 90; + float radiusBearing = DIST_TO_SHOW * tileBox.getDensity(); + final QuadPoint cp = tileBox.getCenterPixelPoint(); + canvas.rotate(bearing, cp.x, cp.y); + canvas.translate(-24 * tileBox.getDensity() + radiusBearing, -22 * tileBox.getDensity()); + canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex)); + canvas.restore(); + } + i++; + if (i > 1) { + break; } } } @@ -354,57 +317,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi public void destroyLayer() { } - @Override - public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { - if (!longTapDetector.onTouchEvent(event)) { - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - float x = event.getX(); - float y = event.getY(); - fingerLocation = tileBox.getLatLonFromPixel(x, y); - hasMoved = false; - moving = true; - break; - - case MotionEvent.ACTION_MOVE: - if (!hasMoved) { - if (!handler.hasMessages(MAP_REFRESH_MESSAGE)) { - Message msg = Message.obtain(handler, new Runnable() { - @Override - public void run() { - handler.removeMessages(MAP_REFRESH_MESSAGE); - if (moving) { - if (!useFingerLocation) { - useFingerLocation = true; - map.refreshMap(); - } - } - } - }); - msg.what = MAP_REFRESH_MESSAGE; - handler.sendMessageDelayed(msg, USE_FINGER_LOCATION_DELAY); - } - hasMoved = true; - } - break; - - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - cancelFingerAction(); - break; - } - } - return super.onTouchEvent(event, tileBox); - } - - private void cancelFingerAction() { - handler.removeMessages(MAP_REFRESH_MESSAGE); - useFingerLocation = false; - moving = false; - fingerLocation = null; - map.refreshMap(); - } - @Override public boolean drawInScreenPixels() { return false;