Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-10-05 18:39:03 +02:00
commit 9873fadf14
16 changed files with 632 additions and 225 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -0,0 +1,226 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<ScrollView
android:id="@+id/sort_by_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/bottom_sheet_content_padding_small">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:gravity="center_vertical"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding"
android:text="@string/shared_string_options"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"/>
<LinearLayout
android:id="@+id/navigate_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding">
<ImageView
android:id="@+id/navigate_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/map_directions"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/shared_string_navigate"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
<LinearLayout
android:id="@+id/make_round_trip_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding">
<ImageView
android:id="@+id/make_round_trip_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_trip_round"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/make_round_trip"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/make_round_trip_descr"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
<android.support.v7.widget.SwitchCompat
android:id="@+id/make_round_trip_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/bottom_sheet_content_margin"
android:layout_marginStart="@dimen/bottom_sheet_content_margin"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/bottom_sheet_content_padding_small"
android:background="?attr/dashboard_divider"/>
<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:gravity="center_vertical"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding"
android:text="@string/sort_by"
android:textAllCaps="true"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"/>
<LinearLayout
android:id="@+id/door_to_door_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding">
<ImageView
android:id="@+id/door_to_door_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_sort_door_to_door"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/intermediate_items_sort_by_distance"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
<LinearLayout
android:id="@+id/reverse_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding">
<ImageView
android:id="@+id/reverse_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_sort_reverse_order"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/shared_string_reverse_order"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>

View file

@ -1,117 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<ScrollView
android:id="@+id/sort_by_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/bottom_sheet_content_padding_small">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:gravity="center_vertical"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding"
android:text="@string/sort_by"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"/>
<LinearLayout
android:id="@+id/door_to_door_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding">
<ImageView
android:id="@+id/door_to_door_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_sort_door_to_door"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/intermediate_items_sort_by_distance"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
<LinearLayout
android:id="@+id/reverse_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingEnd="@dimen/bottom_sheet_content_padding"
android:paddingLeft="@dimen/bottom_sheet_content_padding"
android:paddingRight="@dimen/bottom_sheet_content_padding"
android:paddingStart="@dimen/bottom_sheet_content_padding">
<ImageView
android:id="@+id/reverse_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_sort_reverse_order"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/shared_string_reverse_order"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>

View file

@ -9,6 +9,9 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 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 PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="make_round_trip_descr">Add copy of start point as destination.</string>
<string name="make_round_trip">Make round trip</string>
<string name="shared_string_navigate">Navigate</string>
<string name="shared_string_markers">Markers</string> <string name="shared_string_markers">Markers</string>
<string name="coordinates_format">Coordinates format</string> <string name="coordinates_format">Coordinates format</string>
<string name="use_system_keyboard">Use system keyboard</string> <string name="use_system_keyboard">Use system keyboard</string>
@ -30,8 +33,8 @@
<string name="group_will_be_removed_after_restart">Group will be removed after restart</string> <string name="group_will_be_removed_after_restart">Group will be removed after restart</string>
<string name="show_guide_line">Show guide line</string> <string name="show_guide_line">Show guide line</string>
<string name="show_arrows_on_the_map">Show arrows on the map</string> <string name="show_arrows_on_the_map">Show arrows on the map</string>
<string name="show_passed">Show \'Last used\' date</string> <string name="show_passed">Show passed</string>
<string name="hide_passed">Hide \'Last used\' date</string> <string name="hide_passed">Hide passed</string>
<string name="remove_from_map_markers">Remove from Map Markers</string> <string name="remove_from_map_markers">Remove from Map Markers</string>
<string name="descendingly">descending</string> <string name="descendingly">descending</string>
<string name="ascendingly">ascending</string> <string name="ascendingly">ascending</string>
@ -45,7 +48,7 @@
<string name="marker_moved_to_active">Map marker moved to active</string> <string name="marker_moved_to_active">Map marker moved to active</string>
<string name="shared_string_list">List</string> <string name="shared_string_list">List</string>
<string name="shared_string_groups">Groups</string> <string name="shared_string_groups">Groups</string>
<string name="passed">Last used: %1$s</string> <string name="passed">Passed: %1$s</string>
<string name="make_active">Make active</string> <string name="make_active">Make active</string>
<string name="today">Today</string> <string name="today">Today</string>
<string name="yesterday">Yesterday</string> <string name="yesterday">Yesterday</string>
@ -270,7 +273,7 @@
<string name="osmo_share_location">Share</string> <string name="osmo_share_location">Share</string>
<string name="osmo_pause_location">Pause</string> <string name="osmo_pause_location">Pause</string>
<string name="osmo_service_running">OsMo service is running</string> <string name="osmo_service_running">OsMo service is running</string>
<string name="trip_rec_notification_settings">Trip recording (no data)</string> <string name="trip_rec_notification_settings">Enable recording quick start</string>
<string name="trip_rec_notification_settings_desc">Display a system notification allowing to start trip recording</string> <string name="trip_rec_notification_settings_desc">Display a system notification allowing to start trip recording</string>
<string name="shared_string_notifications">Notifications</string> <string name="shared_string_notifications">Notifications</string>
<string name="shared_string_continue">Continue</string> <string name="shared_string_continue">Continue</string>

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.Pair;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
@ -27,6 +28,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
@ -42,6 +44,9 @@ public class MapMarkersHelper {
private MapMarkersDbHelper markersDbHelper; private MapMarkersDbHelper markersDbHelper;
private boolean startFromMyLocation; private boolean startFromMyLocation;
private final Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints = new ConcurrentHashMap<>();
private ApplicationMode snappedMode;
public interface MapMarkerChangedListener { public interface MapMarkerChangedListener {
void onMapMarkerChanged(MapMarker mapMarker); void onMapMarkerChanged(MapMarker mapMarker);
@ -231,6 +236,18 @@ public class MapMarkersHelper {
createMapMarkersGroups(); createMapMarkersGroups();
} }
public Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedToRoadPoints() {
return snappedToRoadPoints;
}
public ApplicationMode getSnappedMode() {
return snappedMode;
}
public void setSnappedMode(ApplicationMode snappedMode) {
this.snappedMode = snappedMode;
}
public boolean isStartFromMyLocation() { public boolean isStartFromMyLocation() {
return startFromMyLocation; return startFromMyLocation;
} }

View file

@ -788,9 +788,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
mapActivity.enableDrawer(); mapActivity.enableDrawer();
getMyApplication().getMapMarkersHelper().removeListener(this); getMyApplication().getMapMarkersHelper().removeListener(this);
if (mapActivity.getMapLayers().getMapMarkersLayer().clearRoute()) { // if (mapActivity.getMapLayers().getMapMarkersLayer().clearRoute()) {
mapActivity.refreshMap(); // mapActivity.refreshMap();
} // }
if (swipeDismissListener != null) { if (swipeDismissListener != null) {
swipeDismissListener.discardUndo(); swipeDismissListener.discardUndo();
} }
@ -1691,7 +1691,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
public void showMarkersRouteOnMap() { public void showMarkersRouteOnMap() {
MapMarkersHelper helper = getMyApplication().getMapMarkersHelper(); MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
List<LatLon> points = helper.getSelectedMarkersLatLon(); List<LatLon> points = helper.getSelectedMarkersLatLon();
mapActivity.getMapLayers().getMapMarkersLayer().setRoute(points); // mapActivity.getMapLayers().getMapMarkersLayer().setRoute(points);
showRouteOnMap(points); showRouteOnMap(points);
} }

View file

@ -13,6 +13,7 @@ import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper; import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Pair;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -20,6 +21,7 @@ import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -29,6 +31,8 @@ import net.osmand.TspAnt;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
@ -38,26 +42,35 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.PlanRouteSortByBottomSheetDialogFragment.PlanRouteSortByFragmentListener; import net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener;
import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback; import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback;
import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter; import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter;
import net.osmand.plus.measurementtool.RecyclerViewFragment; import net.osmand.plus.measurementtool.RecyclerViewFragment;
import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment;
import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadFragmentListener; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadFragmentListener;
import net.osmand.plus.routing.RouteCalculationParams;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.MapMarkersLayer; import net.osmand.plus.views.MapMarkersLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.router.RouteCalculationProgress;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT; import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
public class PlanRouteFragment extends Fragment { public class PlanRouteFragment extends Fragment {
public static final String TAG = "PlanRouteFragment"; public static final String TAG = "PlanRouteFragment";
private static final int MAX_DIST_FOR_SNAP_TO_ROAD = 500 * 1000; // 500 km
private MapMarkersHelper markersHelper; private MapMarkersHelper markersHelper;
private MapMarkersListAdapter adapter; private MapMarkersListAdapter adapter;
@ -81,11 +94,19 @@ public class PlanRouteFragment extends Fragment {
private TextView timeTv; private TextView timeTv;
private TextView countTv; private TextView countTv;
private final Queue<Pair<WptPt, WptPt>> snapToRoadPairsToCalculate = new ConcurrentLinkedQueue<>();
private Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints;
private TrkSegment snapTrkSegment = new TrkSegment();
private RouteCalculationProgress calculationProgress;
private int calculatedPairs;
private boolean progressBarVisible;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = getMapActivity(); final MapActivity mapActivity = getMapActivity();
markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
snappedToRoadPoints = markersHelper.getSnappedToRoadPoints();
// Handling screen rotation // Handling screen rotation
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager(); FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
@ -93,9 +114,9 @@ public class PlanRouteFragment extends Fragment {
if (snapToRoadFragment != null) { if (snapToRoadFragment != null) {
((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener()); ((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener());
} }
Fragment sortByFragment = fragmentManager.findFragmentByTag(PlanRouteSortByBottomSheetDialogFragment.TAG); Fragment sortByFragment = fragmentManager.findFragmentByTag(PlanRouteOptionsBottomSheetDialogFragment.TAG);
if (sortByFragment != null) { if (sortByFragment != null) {
((PlanRouteSortByBottomSheetDialogFragment) sortByFragment).setListener(createSortByFragmentListener()); ((PlanRouteOptionsBottomSheetDialogFragment) sortByFragment).setListener(createOptionsFragmentListener());
} }
// If rotate the screen from landscape to portrait when the list of markers is displayed then // If rotate the screen from landscape to portrait when the list of markers is displayed then
// the RecyclerViewFragment will exist without view. This is necessary to remove it. // the RecyclerViewFragment will exist without view. This is necessary to remove it.
@ -158,9 +179,8 @@ public class PlanRouteFragment extends Fragment {
} }
adapter.calculateStartAndFinishPos(); adapter.calculateStartAndFinishPos();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
updateText();
updateSelectButton(); updateSelectButton();
showMarkersRouteOnMap(); recreateSnapTrkSegment();
mapActivity.refreshMap(); mapActivity.refreshMap();
} }
}); });
@ -168,9 +188,7 @@ public class PlanRouteFragment extends Fragment {
mainView.findViewById(R.id.sort_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.sort_button).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
PlanRouteSortByBottomSheetDialogFragment fragment = new PlanRouteSortByBottomSheetDialogFragment(); Toast.makeText(mapActivity, "Sort", Toast.LENGTH_SHORT).show();
fragment.setListener(createSortByFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), PlanRouteSortByBottomSheetDialogFragment.TAG);
} }
}); });
@ -192,6 +210,15 @@ public class PlanRouteFragment extends Fragment {
} }
} }
}); });
toolbarController.setSaveViewTextId(R.string.shared_string_options);
toolbarController.setOnSaveViewClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlanRouteOptionsBottomSheetDialogFragment fragment = new PlanRouteOptionsBottomSheetDialogFragment();
fragment.setListener(createOptionsFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), PlanRouteOptionsBottomSheetDialogFragment.TAG);
}
});
mapActivity.showTopToolbar(toolbarController); mapActivity.showTopToolbar(toolbarController);
if (portrait) { if (portrait) {
@ -203,6 +230,7 @@ public class PlanRouteFragment extends Fragment {
adapter = new MapMarkersListAdapter(mapActivity); adapter = new MapMarkersListAdapter(mapActivity);
adapter.setHasStableIds(true); adapter.setHasStableIds(true);
adapter.calculateStartAndFinishPos(); adapter.calculateStartAndFinishPos();
adapter.setSnappedToRoadPoints(snappedToRoadPoints);
final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter)); final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(markersRv); touchHelper.attachToRecyclerView(markersRv);
adapter.setAdapterListener(new MapMarkersListAdapter.MapMarkersListAdapterListener() { adapter.setAdapterListener(new MapMarkersListAdapter.MapMarkersListAdapterListener() {
@ -227,8 +255,7 @@ public class PlanRouteFragment extends Fragment {
adapter.calculateStartAndFinishPos(); adapter.calculateStartAndFinishPos();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
updateSelectButton(); updateSelectButton();
updateText(); recreateSnapTrkSegment();
showMarkersRouteOnMap();
} }
@Override @Override
@ -251,8 +278,7 @@ public class PlanRouteFragment extends Fragment {
// to avoid crash because of: // to avoid crash because of:
// java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
} }
updateText(); recreateSnapTrkSegment();
showMarkersRouteOnMap();
} }
} }
}); });
@ -296,6 +322,10 @@ public class PlanRouteFragment extends Fragment {
} }
}); });
if (progressBarVisible) {
showProgressBar();
}
return view; return view;
} }
@ -337,18 +367,36 @@ public class PlanRouteFragment extends Fragment {
@Override @Override
public void onApplicationModeItemClick(ApplicationMode mode) { public void onApplicationModeItemClick(ApplicationMode mode) {
appMode = mode; if (appMode != null && appMode != mode) {
setupAppModesBtn(); appMode = mode;
updateText(); snappedToRoadPoints.clear();
markersHelper.setSnappedMode(mode);
recreateSnapTrkSegment();
setupAppModesBtn();
}
} }
}; };
} }
private PlanRouteSortByFragmentListener createSortByFragmentListener() { private PlanRouteOptionsFragmentListener createOptionsFragmentListener() {
return new PlanRouteSortByFragmentListener() { return new PlanRouteOptionsFragmentListener() {
private MapActivity mapActivity = getMapActivity(); private MapActivity mapActivity = getMapActivity();
@Override
public void navigateOnClick() {
if (mapActivity != null) {
Toast.makeText(mapActivity, "navigate", Toast.LENGTH_SHORT).show();
}
}
@Override
public void makeRoundTripOnClick() {
if (mapActivity != null) {
Toast.makeText(mapActivity, "mare round trip", Toast.LENGTH_SHORT).show();
}
}
@Override @Override
public void doorToDoorOnClick() { public void doorToDoorOnClick() {
if (mapActivity != null) { if (mapActivity != null) {
@ -367,6 +415,7 @@ public class PlanRouteFragment extends Fragment {
markersHelper.reverseActiveMarkersOrder(); markersHelper.reverseActiveMarkersOrder();
adapter.calculateStartAndFinishPos(); adapter.calculateStartAndFinishPos();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
recreateSnapTrkSegment();
} }
} }
}; };
@ -399,15 +448,14 @@ public class PlanRouteFragment extends Fragment {
wasCollapseButtonVisible = false; wasCollapseButtonVisible = false;
} }
if (appMode == null) { if ((appMode = markersHelper.getSnappedMode()) == null) {
appMode = ApplicationMode.DEFAULT; appMode = ApplicationMode.DEFAULT;
} }
setupAppModesBtn(); setupAppModesBtn();
selectedCount = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkersCount(); selectedCount = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkersCount();
showMarkersRouteOnMap(); recreateSnapTrkSegment();
mapActivity.refreshMap(); mapActivity.refreshMap();
updateText();
updateSelectButton(); updateSelectButton();
} }
} }
@ -460,7 +508,8 @@ public class PlanRouteFragment extends Fragment {
mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE); mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE); mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
markersLayer.clearRoute(); cancelSnapToRoad();
markersLayer.setRoute(null);
mapActivity.refreshMap(); mapActivity.refreshMap();
} }
} }
@ -468,20 +517,13 @@ public class PlanRouteFragment extends Fragment {
private void updateText() { private void updateText() {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
boolean defaultMode = appMode.getStringKey().equals(ApplicationMode.DEFAULT.getStringKey()); boolean defaultMode = appMode == ApplicationMode.DEFAULT;
float dist = 0; float dist = 0;
Location myLoc = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); for (int i = 1; i < snapTrkSegment.points.size(); i++) {
boolean useLocation = myLoc != null && mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get(); WptPt pt1 = snapTrkSegment.points.get(i - 1);
List<LatLon> markers = markersHelper.getSelectedMarkersLatLon(); WptPt pt2 = snapTrkSegment.points.get(i);
if (useLocation ? markers.size() > 0 : markers.size() > 1) { dist += MapUtils.getDistance(pt1.lat, pt1.lon, pt2.lat, pt2.lon);
if (useLocation) {
dist += MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(),
markers.get(0).getLatitude(), markers.get(0).getLongitude());
}
for (int i = 1; i < markers.size(); i++) {
dist += MapUtils.getDistance(markers.get(i - 1), markers.get(i));
}
} }
distanceTv.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()) + (defaultMode ? "" : ",")); distanceTv.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()) + (defaultMode ? "" : ","));
@ -584,16 +626,17 @@ public class PlanRouteFragment extends Fragment {
} }
} }
private void showMarkersRouteOnMap() { private void showMarkersRouteOnMap(boolean adjustMap) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
List<LatLon> points = markersHelper.getSelectedMarkersLatLon(); mapActivity.getMapLayers().getMapMarkersLayer().setRoute(snapTrkSegment);
mapActivity.getMapLayers().getMapMarkersLayer().setRoute(points); if (adjustMap) {
showRouteOnMap(points); showRouteOnMap(snapTrkSegment.points);
}
} }
} }
private void showRouteOnMap(List<LatLon> points) { private void showRouteOnMap(List<WptPt> points) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (points.size() > 0 && mapActivity != null) { if (points.size() > 0 && mapActivity != null) {
OsmandMapTileView mapView = mapActivity.getMapView(); OsmandMapTileView mapView = mapActivity.getMapView();
@ -606,17 +649,17 @@ public class PlanRouteFragment extends Fragment {
top = myLocation.getLatitude(); top = myLocation.getLatitude();
bottom = myLocation.getLatitude(); bottom = myLocation.getLatitude();
} }
for (LatLon l : points) { for (WptPt pt : points) {
if (left == 0) { if (left == 0) {
left = l.getLongitude(); left = pt.getLongitude();
right = l.getLongitude(); right = pt.getLongitude();
top = l.getLatitude(); top = pt.getLatitude();
bottom = l.getLatitude(); bottom = pt.getLatitude();
} else { } else {
left = Math.min(left, l.getLongitude()); left = Math.min(left, pt.getLongitude());
right = Math.max(right, l.getLongitude()); right = Math.max(right, pt.getLongitude());
top = Math.max(top, l.getLatitude()); top = Math.max(top, pt.getLatitude());
bottom = Math.min(bottom, l.getLatitude()); bottom = Math.min(bottom, pt.getLatitude());
} }
} }
@ -721,12 +764,204 @@ public class PlanRouteFragment extends Fragment {
mapActivity.getMyApplication().getMapMarkersHelper().addSelectedMarkersToTop(res); mapActivity.getMyApplication().getMapMarkersHelper().addSelectedMarkersToTop(res);
adapter.calculateStartAndFinishPos(); adapter.calculateStartAndFinishPos();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
updateText(); recreateSnapTrkSegment();
showMarkersRouteOnMap();
} }
}.execute(); }.execute();
} }
private void cancelSnapToRoad() {
hideProgressBar();
snapToRoadPairsToCalculate.clear();
if (calculationProgress != null) {
calculationProgress.isCancelled = true;
}
}
private void scheduleRouteCalculateIfNotEmpty(List<WptPt> points) {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null || points.isEmpty()) {
return;
}
findPairsToCalculate(points);
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if (!snapToRoadPairsToCalculate.isEmpty() && !routingHelper.isRouteBeingCalculated()) {
routingHelper.startRouteCalculationThread(getParams(app), true, true);
app.runInUIThread(new Runnable() {
@Override
public void run() {
showProgressBar();
}
});
}
}
private void findPairsToCalculate(List<WptPt> points) {
snapToRoadPairsToCalculate.clear();
for (int i = 0; i < points.size() - 1; i++) {
Pair<WptPt, WptPt> pair = new Pair<>(points.get(i), points.get(i + 1));
if (snappedToRoadPoints.get(pair) == null) {
double dist = MapUtils.getDistance(pair.first.lat, pair.first.lon, pair.second.lat, pair.second.lon);
if (dist < MAX_DIST_FOR_SNAP_TO_ROAD) {
snapToRoadPairsToCalculate.add(pair);
}
}
}
}
private void recreateSnapTrkSegment() {
recreateSnapTrkSegment(true);
}
private void recreateSnapTrkSegment(boolean adjustMap) {
snapTrkSegment.points.clear();
List<WptPt> points = getPointsToCalculate();
if (appMode == ApplicationMode.DEFAULT) {
snapTrkSegment.points.addAll(points);
} else if (points.size() > 1) {
for (int i = 0; i < points.size() - 1; i++) {
Pair<WptPt, WptPt> pair = new Pair<>(points.get(i), points.get(i + 1));
List<WptPt> pts = snappedToRoadPoints.get(pair);
if (pts != null) {
snapTrkSegment.points.addAll(pts);
} else {
scheduleRouteCalculateIfNotEmpty(points);
snapTrkSegment.points.addAll(Arrays.asList(pair.first, pair.second));
}
}
}
showMarkersRouteOnMap(adjustMap);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
updateText();
}
});
}
}
private List<WptPt> getPointsToCalculate() {
List<WptPt> points = new LinkedList<>();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
Location myLoc = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
if (markersHelper.isStartFromMyLocation() && myLoc != null) {
addWptPt(points, myLoc.getLatitude(), myLoc.getLongitude());
}
for (LatLon l : markersHelper.getSelectedMarkersLatLon()) {
addWptPt(points, l.getLatitude(), l.getLongitude());
}
}
return points;
}
private void addWptPt(List<WptPt> points, double lat, double lon) {
WptPt pt = new WptPt();
pt.lat = lat;
pt.lon = lon;
points.add(pt);
}
private void showProgressBar() {
ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar);
progressBar.setVisibility(View.VISIBLE);
progressBar.setMinimumHeight(0);
progressBar.setProgress(0);
progressBarVisible = true;
}
private void updateProgress(int progress) {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
}
private void refresh() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.refreshMap();
}
}
private void hideProgressBar() {
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
progressBarVisible = false;
}
private RouteCalculationParams getParams(final OsmandApplication app) {
final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll();
Location start = new Location("");
start.setLatitude(currentPair.first.getLatitude());
start.setLongitude(currentPair.first.getLongitude());
LatLon end = new LatLon(currentPair.second.getLatitude(), currentPair.second.getLongitude());
final RouteCalculationParams params = new RouteCalculationParams();
params.inSnapToRoadMode = true;
params.start = start;
params.end = end;
RoutingHelper.applyApplicationSettings(params, app.getSettings(), appMode);
params.mode = appMode;
params.ctx = app;
params.calculationProgress = calculationProgress = new RouteCalculationProgress();
params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
@Override
public void updateProgress(int progress) {
int pairs = calculatedPairs + snapToRoadPairsToCalculate.size();
if (pairs != 0) {
int pairProgress = 100 / pairs;
progress = calculatedPairs * pairProgress + progress / pairs;
}
PlanRouteFragment.this.updateProgress(progress);
}
@Override
public void requestPrivateAccessRouting() {
}
@Override
public void finish() {
calculatedPairs = 0;
}
};
params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() {
@Override
public void onRouteCalculated(List<Location> locations) {
ArrayList<WptPt> pts = new ArrayList<>(locations.size());
for (Location loc : locations) {
WptPt pt = new WptPt();
pt.lat = loc.getLatitude();
pt.lon = loc.getLongitude();
pts.add(pt);
}
calculatedPairs++;
snappedToRoadPoints.put(currentPair, pts);
recreateSnapTrkSegment(false);
app.runInUIThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
refresh();
}
});
if (!snapToRoadPairsToCalculate.isEmpty()) {
app.getRoutingHelper().startRouteCalculationThread(getParams(app), true, true);
} else {
app.runInUIThread(new Runnable() {
@Override
public void run() {
hideProgressBar();
}
});
}
}
};
return params;
}
private class PlanRouteToolbarController extends TopToolbarController { private class PlanRouteToolbarController extends TopToolbarController {
PlanRouteToolbarController() { PlanRouteToolbarController() {
@ -737,6 +972,7 @@ public class PlanRouteFragment extends Fragment {
setBgIds(R.drawable.gradient_toolbar, R.drawable.gradient_toolbar, setBgIds(R.drawable.gradient_toolbar, R.drawable.gradient_toolbar,
R.drawable.gradient_toolbar, R.drawable.gradient_toolbar); R.drawable.gradient_toolbar, R.drawable.gradient_toolbar);
setCloseBtnVisible(false); setCloseBtnVisible(false);
setSaveViewVisible(true);
} }
@Override @Override

View file

@ -21,15 +21,15 @@ import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
public class PlanRouteSortByBottomSheetDialogFragment extends BottomSheetDialogFragment { public class PlanRouteOptionsBottomSheetDialogFragment extends BottomSheetDialogFragment {
public final static String TAG = "PlanRouteSortByBottomSheetDialogFragment"; public final static String TAG = "PlanRouteOptionsBottomSheetDialogFragment";
private boolean portrait; private boolean portrait;
private boolean night; private boolean night;
private PlanRouteSortByFragmentListener listener; private PlanRouteOptionsFragmentListener listener;
public void setListener(PlanRouteSortByFragmentListener listener) { public void setListener(PlanRouteOptionsFragmentListener listener) {
this.listener = listener; this.listener = listener;
} }
@ -40,7 +40,7 @@ public class PlanRouteSortByBottomSheetDialogFragment extends BottomSheetDialogF
night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); night = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_plan_route_sort_by_bottom_sheet_dialog, container); final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_plan_route_options_bottom_sheet_dialog, container);
if (portrait) { if (portrait) {
AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
} }
@ -49,9 +49,29 @@ public class PlanRouteSortByBottomSheetDialogFragment extends BottomSheetDialogF
((TextView) mainView.findViewById(R.id.title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); ((TextView) mainView.findViewById(R.id.title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark));
} }
((ImageView) mainView.findViewById(R.id.navigate_icon)).setImageDrawable(getContentIcon(R.drawable.map_directions));
((ImageView) mainView.findViewById(R.id.make_round_trip_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_trip_round));
((ImageView) mainView.findViewById(R.id.door_to_door_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_door_to_door)); ((ImageView) mainView.findViewById(R.id.door_to_door_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_door_to_door));
((ImageView) mainView.findViewById(R.id.reverse_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_reverse_order)); ((ImageView) mainView.findViewById(R.id.reverse_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_reverse_order));
mainView.findViewById(R.id.navigate_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.navigateOnClick();
dismiss();
}
}
});
mainView.findViewById(R.id.make_round_trip_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.makeRoundTripOnClick();
dismiss();
}
}
});
mainView.findViewById(R.id.door_to_door_row).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.door_to_door_row).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -133,7 +153,11 @@ public class PlanRouteSortByBottomSheetDialogFragment extends BottomSheetDialogF
return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
} }
interface PlanRouteSortByFragmentListener { interface PlanRouteOptionsFragmentListener {
void navigateOnClick();
void makeRoundTripOnClick();
void doorToDoorOnClick(); void doorToDoorOnClick();

View file

@ -3,6 +3,7 @@ package net.osmand.plus.mapmarkers.adapters;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.view.MotionEventCompat; import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Pair;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -10,6 +11,7 @@ import android.view.ViewGroup;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
@ -23,6 +25,7 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder>
implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter { implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter {
@ -37,10 +40,16 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
private int finishPos = -1; private int finishPos = -1;
private int firstSelectedMarkerPos = -1; private int firstSelectedMarkerPos = -1;
private Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints;
public void setAdapterListener(MapMarkersListAdapterListener listener) { public void setAdapterListener(MapMarkersListAdapterListener listener) {
this.listener = listener; this.listener = listener;
} }
public void setSnappedToRoadPoints(Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints) {
this.snappedToRoadPoints = snappedToRoadPoints;
}
public MapMarkersListAdapter(MapActivity mapActivity) { public MapMarkersListAdapter(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers(); markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
@ -65,7 +74,6 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
IconsCache iconsCache = app.getIconsCache(); IconsCache iconsCache = app.getIconsCache();
boolean locationItem = pos == 0; boolean locationItem = pos == 0;
boolean firstMarkerItem = pos == 1;
boolean lastMarkerItem = pos == getItemCount() - 1; boolean lastMarkerItem = pos == getItemCount() - 1;
boolean start = pos == startPos; boolean start = pos == startPos;
boolean finish = pos == finishPos && startPos != finishPos; boolean finish = pos == finishPos && startPos != finishPos;
@ -99,6 +107,13 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + ""); holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + "");
} }
boolean iconSettled = false;
if ((start || finish) && !locationItem) {
int res = start ? R.drawable.ic_action_point_start : R.drawable.ic_action_point_destination;
holder.icon.setImageDrawable(iconsCache.getIcon(res, MapMarker.getColorId(marker.colorIndex)));
iconSettled = true;
}
if (locationItem) { if (locationItem) {
holder.topDivider.setVisibility(View.VISIBLE); holder.topDivider.setVisibility(View.VISIBLE);
holder.flagIconLeftSpace.setVisibility(View.VISIBLE); holder.flagIconLeftSpace.setVisibility(View.VISIBLE);
@ -111,7 +126,9 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
} else { } else {
holder.topDivider.setVisibility(View.GONE); holder.topDivider.setVisibility(View.GONE);
holder.flagIconLeftSpace.setVisibility(View.GONE); holder.flagIconLeftSpace.setVisibility(View.GONE);
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(marker.colorIndex))); if (!iconSettled) {
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(marker.colorIndex)));
}
holder.point.setVisibility(View.VISIBLE); holder.point.setVisibility(View.VISIBLE);
holder.checkBox.setChecked(marker.selected); holder.checkBox.setChecked(marker.selected);
@ -157,7 +174,21 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
: getPreviousSelectedMarkerLatLon(pos - 1); : getPreviousSelectedMarkerLatLon(pos - 1);
float dist = 0; float dist = 0;
if (first != null && marker != null) { if (first != null && marker != null) {
dist = (float) MapUtils.getDistance(first, marker.point); WptPt pt1 = new WptPt();
pt1.lat = first.getLatitude();
pt1.lon = first.getLongitude();
WptPt pt2 = new WptPt();
pt2.lat = marker.getLatitude();
pt2.lon = marker.getLongitude();
List<WptPt> points = snappedToRoadPoints.get(new Pair<>(pt1, pt2));
if (points != null) {
for (int i = 0; i < points.size() - 1; i++) {
dist += (float) MapUtils.getDistance(points.get(i).lat, points.get(i).lon,
points.get(i + 1).lat, points.get(i + 1).lon);
}
} else {
dist = (float) MapUtils.getDistance(pt1.lat, pt1.lon, pt2.lat, pt2.lon);
}
} }
holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app)); holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
} }

View file

@ -8,7 +8,6 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.measurementtool.command.MeasurementCommandManager; import net.osmand.plus.measurementtool.command.MeasurementCommandManager;
import net.osmand.plus.routing.RouteCalculationParams; import net.osmand.plus.routing.RouteCalculationParams;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
@ -259,8 +258,6 @@ public class MeasurementEditingContext {
} }
private RouteCalculationParams getParams() { private RouteCalculationParams getParams() {
OsmandSettings settings = application.getSettings();
final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll(); final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll();
Location start = new Location(""); Location start = new Location("");
@ -273,9 +270,7 @@ public class MeasurementEditingContext {
params.inSnapToRoadMode = true; params.inSnapToRoadMode = true;
params.start = start; params.start = start;
params.end = end; params.end = end;
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving; RoutingHelper.applyApplicationSettings(params, application.getSettings(), snapToRoadAppMode);
params.fast = settings.FAST_ROUTE_MODE.getModeValue(snapToRoadAppMode);
params.type = settings.ROUTER_SERVICE.getModeValue(snapToRoadAppMode);
params.mode = snapToRoadAppMode; params.mode = snapToRoadAppMode;
params.ctx = application; params.ctx = application;
params.calculationProgress = calculationProgress = new RouteCalculationProgress(); params.calculationProgress = calculationProgress = new RouteCalculationProgress();

View file

@ -1008,6 +1008,12 @@ public class RoutingHelper {
} }
} }
public static void applyApplicationSettings(RouteCalculationParams params, OsmandSettings settings, ApplicationMode mode) {
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
params.type = settings.ROUTER_SERVICE.getModeValue(mode);
}
public void setProgressBar(RouteCalculationProgressCallback progressRoute) { public void setProgressBar(RouteCalculationProgressCallback progressRoute) {
this.progressRoute = progressRoute; this.progressRoute = progressRoute;
} }

View file

@ -19,6 +19,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint; import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
@ -71,8 +72,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine");
private final RenderingLineAttributes textAttrs = new RenderingLineAttributes("rulerLineFont"); private final RenderingLineAttributes textAttrs = new RenderingLineAttributes("rulerLineFont");
private Paint paint; private Paint paint;
private Path path; private TrkSegment route;
private List<LatLon> route = new ArrayList<>();
private TIntArrayList tx = new TIntArrayList(); private TIntArrayList tx = new TIntArrayList();
private TIntArrayList ty = new TIntArrayList(); private TIntArrayList ty = new TIntArrayList();
@ -120,7 +120,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
bitmapPaintDestTeal = createPaintDest(R.color.marker_teal); bitmapPaintDestTeal = createPaintDest(R.color.marker_teal);
bitmapPaintDestPurple = createPaintDest(R.color.marker_purple); bitmapPaintDestPurple = createPaintDest(R.color.marker_purple);
path = new Path();
paint = new Paint(); paint = new Paint();
paint.setStyle(Paint.Style.STROKE); paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(7 * view.getDensity()); paint.setStrokeWidth(7 * view.getDensity());
@ -191,15 +190,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
} }
} }
public void setRoute(List<LatLon> points) { public void setRoute(TrkSegment route) {
route.clear(); this.route = route;
route.addAll(points);
}
public boolean clearRoute() {
boolean res = route.size() > 0;
route.clear();
return res;
} }
@Override @Override
@ -214,26 +206,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers(); List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
if (route.size() > 0) { if (route != null && route.points.size() > 0) {
path.reset(); route.renders.clear();
boolean first = true; route.renders.add(new Renderable.StandardTrack(new ArrayList<>(route.points), 17.2));
if (markersHelper.isStartFromMyLocation() && myLoc != null) { route.drawRenderers(view.getZoom(), paint, canvas, tileBox);
int locationX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude());
int locationY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude());
path.moveTo(locationX, locationY);
first = false;
}
for (LatLon point : route) {
int locationX = tileBox.getPixXFromLonNoRot(point.getLongitude());
int locationY = tileBox.getPixYFromLatNoRot(point.getLatitude());
if (first) {
path.moveTo(locationX, locationY);
first = false;
} else {
path.lineTo(locationX, locationY);
}
}
canvas.drawPath(path, paint);
} }
if (markersHelper.isStartFromMyLocation() && myLoc != null) { if (markersHelper.isStartFromMyLocation() && myLoc != null) {

View file

@ -249,6 +249,8 @@ public class MapInfoWidgetsFactory {
String title = ""; String title = "";
String description = null; String description = null;
int saveViewTextId = -1;
OnClickListener onBackButtonClickListener; OnClickListener onBackButtonClickListener;
OnClickListener onTitleClickListener; OnClickListener onTitleClickListener;
OnClickListener onCloseButtonClickListener; OnClickListener onCloseButtonClickListener;
@ -337,6 +339,10 @@ public class MapInfoWidgetsFactory {
this.saveViewVisible = visible; this.saveViewVisible = visible;
} }
public void setSaveViewTextId(int id) {
this.saveViewTextId = id;
}
public void setTopBarSwitchVisible(boolean visible) { public void setTopBarSwitchVisible(boolean visible) {
this.topBarSwitchVisible = visible; this.topBarSwitchVisible = visible;
} }
@ -649,6 +655,10 @@ public class MapInfoWidgetsFactory {
refreshButton.setVisibility(View.GONE); refreshButton.setVisibility(View.GONE);
} }
if (controller.saveViewVisible) { if (controller.saveViewVisible) {
if (controller.saveViewTextId != -1) {
saveView.setText(map.getString(controller.saveViewTextId));
saveView.setContentDescription(map.getString(controller.saveViewTextId));
}
if (saveView.getVisibility() == View.GONE) { if (saveView.getVisibility() == View.GONE) {
saveView.setVisibility(View.VISIBLE); saveView.setVisibility(View.VISIBLE);
} }
@ -749,7 +759,7 @@ public class MapInfoWidgetsFactory {
if (text == null) { if (text == null) {
text = ""; text = "";
} else { } else {
if(type[0] == null){ if (type[0] == null) {
showMarker = true; showMarker = true;
} else { } else {
turnDrawable.setColor(R.color.nav_arrow); turnDrawable.setColor(R.color.nav_arrow);
@ -784,16 +794,16 @@ public class MapInfoWidgetsFactory {
rt.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()), rt.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()),
rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)), rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)),
rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)), rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)),
"»"); "»");
} }
if (text == null) { if (text == null) {
text = ""; text = "";
} else { } else {
Location lastKnownLocation = locationProvider.getLastKnownLocation(); Location lastKnownLocation = locationProvider.getLastKnownLocation();
if(!Algorithms.isEmpty(text) && lastKnownLocation != null) { if (!Algorithms.isEmpty(text) && lastKnownLocation != null) {
double dist = double dist =
CurrentPositionHelper.getOrthogonalDistance(rt, lastKnownLocation); CurrentPositionHelper.getOrthogonalDistance(rt, lastKnownLocation);
if(dist < 50) { if (dist < 50) {
showMarker = true; showMarker = true;
} else { } else {
text = map.getResources().getString(R.string.shared_string_near) + " " + text; text = map.getResources().getString(R.string.shared_string_near) + " " + text;