Change Measure distance -> Plan a route

This commit is contained in:
Dima-1 2020-07-16 12:03:16 +03:00
parent 2db3b07225
commit 255f52f52c
12 changed files with 226 additions and 149 deletions

View file

@ -46,6 +46,8 @@ public class GPXUtilities {
private static final String ICON_NAME_EXTENSION = "icon";
private static final String DEFAULT_ICON_NAME = "special_star";
private static final String BACKGROUND_TYPE_EXTENSION = "background";
private static final String PROFILE_TYPE_EXTENSION = "profile";
private static final String TRKPT_INDEX_EXTENSION = "trkpt_idx";
private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$
@ -302,6 +304,26 @@ public class GPXUtilities {
getExtensionsToWrite().put(BACKGROUND_TYPE_EXTENSION, backType);
}
public String getProfileType() {
return getExtensionsToRead().get(PROFILE_TYPE_EXTENSION);
}
public void setProfileType(String profileType) {
getExtensionsToWrite().put(PROFILE_TYPE_EXTENSION, profileType);
}
public int getTrkPtIndex() {
try {
return Integer.parseInt(getExtensionsToRead().get(TRKPT_INDEX_EXTENSION));
}catch(NumberFormatException e){
return -1;
}
}
public void setTrkPtIndex(int index) {
getExtensionsToWrite().put(TRKPT_INDEX_EXTENSION, String.valueOf(index));
}
@Override
public int hashCode() {
final int prime = 31;

View file

@ -163,30 +163,25 @@
android:paddingStart="@dimen/measurement_tool_text_button_padding"
android:text="@string/shared_string_options"
android:textColor="?attr/color_dialog_buttons"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"/>
</FrameLayout>
<ImageButton
android:id="@+id/undo_point_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingEnd="@dimen/measurement_tool_undo_redo_padding_small"
android:paddingLeft="@dimen/measurement_tool_undo_redo_padding"
android:paddingRight="@dimen/measurement_tool_undo_redo_padding_small"
android:paddingStart="@dimen/measurement_tool_undo_redo_padding_small"
android:padding="@dimen/measurement_tool_undo_redo_padding_small"
tools:src="@drawable/ic_action_undo_dark"/>
<ImageButton
android:id="@+id/redo_point_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/measurement_tool_button_padding"
android:layout_marginStart="@dimen/measurement_tool_button_padding"
android:background="?attr/selectableItemBackground"
android:paddingEnd="@dimen/measurement_tool_undo_redo_padding"
android:paddingLeft="@dimen/measurement_tool_undo_redo_padding_small"
android:paddingRight="@dimen/measurement_tool_undo_redo_padding"
android:paddingStart="@dimen/measurement_tool_undo_redo_padding_small"
android:padding="@dimen/measurement_tool_undo_redo_padding_small"
tools:src="@drawable/ic_action_redo_dark"/>
<FrameLayout
@ -204,14 +199,13 @@
android:layout_marginRight="@dimen/measurement_tool_button_margin"
android:layout_marginTop="@dimen/measurement_tool_button_margin"
android:background="?attr/btn_round"
osmand:drawableLeftCompat="@drawable/ic_action_plus"
osmand:drawableStartCompat="@drawable/ic_action_plus"
android:maxLines="1"
android:minHeight="@dimen/measurement_tool_button_height"
android:paddingLeft="@dimen/measurement_tool_button_padding"
android:paddingRight="@dimen/measurement_tool_button_padding"
android:text="@string/shared_string_add"
android:textColor="@color/color_white"
android:textAllCaps="false"
android:paddingEnd="@dimen/measurement_tool_button_padding"
android:paddingStart="@dimen/measurement_tool_button_padding" />
</FrameLayout>
@ -242,6 +236,7 @@
android:paddingRight="@dimen/measurement_tool_button_padding"
android:text="@string/shared_string_apply"
android:textColor="@color/color_white"
android:textAllCaps="false"
android:paddingEnd="@dimen/measurement_tool_button_padding"
android:paddingStart="@dimen/measurement_tool_button_padding" />
@ -304,6 +299,7 @@
android:paddingRight="@dimen/measurement_tool_button_padding"
android:text="@string/shared_string_apply"
android:textColor="?attr/color_dialog_buttons"
android:textAllCaps="false"
android:paddingEnd="@dimen/measurement_tool_button_padding"
android:paddingStart="@dimen/measurement_tool_button_padding" />
@ -316,13 +312,12 @@
android:layout_marginRight="@dimen/measurement_tool_button_margin"
android:layout_marginTop="@dimen/measurement_tool_button_margin"
android:background="?attr/btn_round"
osmand:drawableLeftCompat="@drawable/ic_action_plus"
osmand:drawableStartCompat="@drawable/ic_action_plus"
android:minHeight="@dimen/measurement_tool_button_height"
android:paddingLeft="@dimen/measurement_tool_button_padding"
android:paddingRight="@dimen/measurement_tool_button_padding"
android:text="@string/shared_string_add"
android:textColor="@color/color_white"
android:textAllCaps="false"
android:paddingStart="@dimen/measurement_tool_button_padding"
android:paddingEnd="@dimen/measurement_tool_button_padding" />
</LinearLayout>

View file

@ -39,10 +39,10 @@
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/bottom_sheet_content_margin"
android:layout_marginLeft="@dimen/bottom_sheet_content_margin"
android:layout_marginRight="@dimen/bottom_sheet_content_margin"
android:layout_marginStart="@dimen/bottom_sheet_content_margin"
android:layout_marginEnd="@dimen/measurement_tool_text_button_padding"
android:layout_marginLeft="@dimen/measurement_tool_text_button_padding"
android:layout_marginRight="@dimen/measurement_tool_text_button_padding"
android:layout_marginStart="@dimen/measurement_tool_text_button_padding"
android:background="@null"
tools:src="@drawable/ic_action_ruler"/>
@ -64,11 +64,11 @@
android:id="@+id/measurement_distance_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/measurement_tool_button_padding"
android:layout_marginEnd="@dimen/text_margin_small"
android:layout_marginLeft="@dimen/measurement_tool_text_margin"
android:layout_marginLeft="@dimen/measurement_tool_text_button_padding"
android:layout_marginRight="@dimen/text_margin_small"
android:layout_marginStart="@dimen/measurement_tool_text_margin"
android:layout_marginStart="@dimen/measurement_tool_text_button_padding"
android:layout_toEndOf="@id/main_icon"
android:layout_toRightOf="@id/main_icon"
android:textAppearance="@style/TextAppearance.ListItemTitle"
@ -78,7 +78,7 @@
android:id="@+id/measurement_points_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/measurement_tool_button_padding"
android:layout_toEndOf="@id/measurement_distance_text_view"
android:layout_toRightOf="@id/measurement_distance_text_view"
android:textColor="?android:textColorSecondary"
@ -87,17 +87,15 @@
<TextView
android:id="@+id/distance_to_center_text_view"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/measurement_points_text_view"
android:layout_toLeftOf="@id/up_down_button"
android:layout_toRightOf="@id/measurement_points_text_view"
android:layout_toStartOf="@id/up_down_button"
android:textColor="@color/color_distance"
android:textSize="@dimen/default_list_text_size"
android:layout_below="@id/measurement_points_text_view"
android:layout_alignStart="@+id/measurement_distance_text_view"
android:layout_alignLeft="@+id/measurement_distance_text_view"
android:maxLines="1"
tools:text=" 700 m"/>
android:textColor="@color/color_distance"
android:textSize="@dimen/default_desc_text_size"
tools:text=" 700 m" />
<TextView
android:id="@+id/move_point_text"
@ -161,7 +159,11 @@
<LinearLayout
android:id="@+id/measure_mode_controls"
android:layout_width="match_parent"
android:layout_height="@dimen/measurement_tool_controls_height">
android:layout_height="@dimen/measurement_tool_controls_height"
android:paddingTop="@dimen/measurement_tool_button_padding_top"
android:paddingBottom="@dimen/measurement_tool_button_padding_top"
android:paddingLeft="@dimen/measurement_tool_button_margin"
android:paddingRight="@dimen/measurement_tool_button_margin">
<FrameLayout
android:layout_width="0dp"
@ -176,36 +178,28 @@
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingEnd="@dimen/measurement_tool_text_button_padding_small"
android:paddingLeft="@dimen/measurement_tool_text_button_padding"
android:paddingRight="@dimen/measurement_tool_text_button_padding_small"
android:paddingStart="@dimen/measurement_tool_text_button_padding"
android:padding="@dimen/measurement_tool_text_button_padding_small"
android:text="@string/shared_string_options"
android:textColor="?attr/color_dialog_buttons"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"/>
</FrameLayout>
<ImageButton
android:id="@+id/undo_point_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingEnd="@dimen/measurement_tool_undo_redo_padding_small"
android:paddingLeft="@dimen/measurement_tool_undo_redo_padding"
android:paddingRight="@dimen/measurement_tool_undo_redo_padding_small"
android:paddingStart="@dimen/measurement_tool_undo_redo_padding"
android:padding="@dimen/measurement_tool_undo_redo_padding_small"
tools:src="@drawable/ic_action_undo_dark"/>
<ImageButton
android:id="@+id/redo_point_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/measurement_tool_button_padding"
android:layout_marginStart="@dimen/measurement_tool_button_padding"
android:background="?attr/selectableItemBackground"
android:paddingEnd="@dimen/measurement_tool_undo_redo_padding"
android:paddingLeft="@dimen/measurement_tool_undo_redo_padding_small"
android:paddingRight="@dimen/measurement_tool_undo_redo_padding"
android:paddingStart="@dimen/measurement_tool_undo_redo_padding_small"
android:padding="@dimen/measurement_tool_undo_redo_padding_small"
tools:src="@drawable/ic_action_redo_dark"/>
<FrameLayout
@ -218,13 +212,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginBottom="@dimen/measurement_tool_button_margin"
android:layout_marginEnd="@dimen/measurement_tool_button_margin"
android:layout_marginRight="@dimen/measurement_tool_button_margin"
android:layout_marginTop="@dimen/measurement_tool_button_margin"
android:background="?attr/btn_round"
osmand:drawableLeftCompat="@drawable/ic_action_plus"
osmand:drawableStartCompat="@drawable/ic_action_plus"
android:ellipsize="end"
android:maxLines="1"
android:minHeight="@dimen/measurement_tool_button_height"
@ -232,6 +220,7 @@
android:paddingRight="@dimen/measurement_tool_button_padding"
android:text="@string/shared_string_add"
android:textColor="@color/color_white"
android:textAllCaps="false"
android:paddingEnd="@dimen/measurement_tool_button_padding"
android:paddingStart="@dimen/measurement_tool_button_padding" />
</FrameLayout>
@ -261,6 +250,7 @@
android:paddingRight="@dimen/measurement_tool_button_padding"
android:text="@string/shared_string_apply"
android:textColor="@color/color_white"
android:textAllCaps="false"
android:paddingEnd="@dimen/measurement_tool_button_padding"
android:paddingStart="@dimen/measurement_tool_button_padding" />
@ -268,15 +258,12 @@
android:id="@+id/cancel_move_point_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="@dimen/measurement_tool_button_margin"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:paddingEnd="12dp"
android:paddingLeft="16dp"
android:paddingRight="12dp"
android:paddingStart="16dp"
android:padding="@dimen/measurement_tool_text_button_padding_small"
android:text="@string/shared_string_cancel"
android:textColor="?attr/color_dialog_buttons"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"/>
</RelativeLayout>
@ -292,15 +279,12 @@
android:id="@+id/cancel_point_before_after_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="@dimen/measurement_tool_button_margin"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:paddingEnd="@dimen/measurement_tool_text_button_padding_small"
android:paddingLeft="@dimen/measurement_tool_text_button_padding"
android:paddingRight="@dimen/measurement_tool_text_button_padding_small"
android:paddingStart="@dimen/measurement_tool_text_button_padding"
android:padding="@dimen/measurement_tool_text_button_padding_small"
android:text="@string/shared_string_cancel"
android:textColor="?attr/color_dialog_buttons"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"/>
<View
@ -322,6 +306,7 @@
android:paddingRight="@dimen/measurement_tool_button_padding"
android:text="@string/shared_string_apply"
android:textColor="?attr/color_dialog_buttons"
android:textAllCaps="false"
android:paddingEnd="@dimen/measurement_tool_button_padding"
android:paddingStart="@dimen/measurement_tool_button_padding" />
@ -334,13 +319,12 @@
android:layout_marginRight="@dimen/measurement_tool_button_margin"
android:layout_marginTop="@dimen/measurement_tool_button_margin"
android:background="?attr/btn_round"
osmand:drawableLeftCompat="@drawable/ic_action_plus"
osmand:drawableStartCompat="@drawable/ic_action_plus"
android:minHeight="@dimen/measurement_tool_button_height"
android:paddingLeft="@dimen/measurement_tool_button_padding"
android:paddingRight="@dimen/measurement_tool_button_padding"
android:text="@string/shared_string_add"
android:textColor="@color/color_white"
android:textAllCaps="false"
android:paddingEnd="@dimen/measurement_tool_button_padding"
android:paddingStart="@dimen/measurement_tool_button_padding" />
</LinearLayout>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -14,10 +13,10 @@
android:layout_height="@dimen/dashboard_map_toolbar"
android:minHeight="@dimen/dashboard_map_toolbar"
android:visibility="gone"
app:contentInsetLeft="54dp"
app:contentInsetStart="54dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
osmand:contentInsetLeft="@dimen/toolbar_inset_start"
osmand:contentInsetStart="@dimen/toolbar_inset_start"
osmand:contentInsetRight="0dp"
osmand:contentInsetEnd="0dp"
tools:visibility="visible">
<LinearLayout
@ -63,8 +62,8 @@
android:id="@+id/toolbar_divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginLeft="54dp"
android:layout_marginStart="54dp"
android:layout_marginLeft="@dimen/toolbar_inset_start"
android:layout_marginStart="@dimen/toolbar_inset_start"
android:visibility="gone"
tools:background="?attr/dashboard_divider"
tools:visibility="visible"/>
@ -81,7 +80,7 @@
<LinearLayout
android:id="@+id/up_down_row"
android:layout_width="match_parent"
android:layout_height="@dimen/measurement_tool_up_down_row_height"
android:layout_height="@dimen/route_info_modes_height"
android:background="?attr/selectableItemBackground">
<androidx.appcompat.widget.AppCompatImageView
@ -151,10 +150,10 @@
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingEnd="@dimen/measurement_tool_text_button_padding_small"
android:paddingLeft="@dimen/measurement_tool_text_button_padding"
android:paddingRight="@dimen/measurement_tool_text_button_padding_small"
android:paddingStart="@dimen/measurement_tool_text_button_padding"
android:paddingEnd="@dimen/route_info_details_padding"
android:paddingLeft="@dimen/route_info_buttons_padding_top_bottom"
android:paddingRight="@dimen/route_info_details_padding"
android:paddingStart="@dimen/route_info_buttons_padding_top_bottom"
android:text="@string/shared_string_select_all"
android:textColor="?attr/color_dialog_buttons"
osmand:textAllCapsCompat="true"

View file

@ -80,7 +80,7 @@
<dimen name="measurement_tool_text_margin">12dp</dimen>
<dimen name="measurement_tool_points_list_container_height">330dp</dimen>
<dimen name="measurement_tool_up_down_row_height">48dp</dimen>
<dimen name="measurement_tool_controls_height">78dp</dimen>
<dimen name="measurement_tool_controls_height">84dp</dimen>
<dimen name="measurement_tool_text_button_padding_small">18dp</dimen>
<dimen name="measurement_tool_text_button_padding">24dp</dimen>
<dimen name="measurement_tool_undo_redo_padding_small">18dp</dimen>
@ -88,6 +88,7 @@
<dimen name="measurement_tool_undo_redo_padding">24dp</dimen>
<dimen name="measurement_tool_button_margin">12dp</dimen>
<dimen name="measurement_tool_button_padding">12dp</dimen>
<dimen name="measurement_tool_button_padding_top">15dp</dimen>
<dimen name="measurement_tool_button_height">54dp</dimen>
<!--Route info-->

View file

@ -251,15 +251,16 @@
<dimen name="text_margin_small">4dp</dimen>
<dimen name="measurement_tool_text_margin">8dp</dimen>
<dimen name="measurement_tool_points_list_container_height">220dp</dimen>
<dimen name="measurement_tool_up_down_row_height">48dp</dimen>
<dimen name="measurement_tool_controls_height">52dp</dimen>
<dimen name="measurement_tool_text_button_padding_small">12dp</dimen>
<dimen name="measurement_tool_up_down_row_height">60dp</dimen>
<dimen name="measurement_tool_controls_height">56dp</dimen>
<dimen name="measurement_tool_text_button_padding_small">8dp</dimen>
<dimen name="measurement_tool_text_button_padding">16dp</dimen>
<dimen name="measurement_tool_undo_redo_padding_small">12dp</dimen>
<dimen name="measurement_tool_undo_redo_padding_small">6dp</dimen>
<dimen name="measurement_tool_undo_redo_padding_medium">14dp</dimen>
<dimen name="measurement_tool_undo_redo_padding">16dp</dimen>
<dimen name="measurement_tool_button_margin">8dp</dimen>
<dimen name="measurement_tool_button_padding">8dp</dimen>
<dimen name="measurement_tool_button_padding_top">10dp</dimen>
<dimen name="measurement_tool_button_height">36dp</dimen>
<dimen name="bottom_sheet_title_height">52dp</dimen>
<dimen name="bottom_sheet_descr_height">44dp</dimen>
@ -340,6 +341,7 @@
<dimen name="toolbar_height">56dp</dimen>
<dimen name="toolbar_height_expanded">96dp</dimen>
<dimen name="toolbar_inset_start_with_navigation">72dp</dimen>
<dimen name="toolbar_inset_start">54dp</dimen>
<dimen name="wikivoyage_search_list_header_height">36dp</dimen>
<dimen name="wikivoyage_article_card_icon_size">80dp</dimen>

View file

@ -11,6 +11,9 @@
Thx - Hardy
-->
<string name="add_to_a_track">Add to a Track</string>
<string name="plan_a_route">Plan a route</string>
<string name="route_between_points">Route between points</string>
<string name="osm_edit_closed_note">Closed OSM Note</string>
<string name="app_mode_go_cart">Go-cart</string>
<string name="app_mode_wheelchair_forward">Wheelchair forward</string>

View file

@ -1,6 +1,5 @@
package net.osmand.plus.activities;
import android.Manifest;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
@ -21,7 +20,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
@ -425,7 +423,7 @@ public class MapActivityActions implements DialogProvider {
}
adapter.addItem(itemBuilder
.setTitleId(R.string.measurement_tool, mapActivity)
.setTitleId(R.string.plan_a_route, mapActivity)
.setId(MAP_CONTEXT_MENU_MEASURE_DISTANCE)
.setIcon(R.drawable.ic_action_ruler)
.setOrder(MEASURE_DISTANCE_ITEM_ORDER)
@ -473,7 +471,7 @@ public class MapActivityActions implements DialogProvider {
// new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
// REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION);
//}
} else if (standardId == R.string.measurement_tool) {
} else if (standardId == R.string.plan_a_route) {
mapActivity.getContextMenu().close();
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude));
} else if (standardId == R.string.avoid_road) {
@ -932,7 +930,7 @@ public class MapActivityActions implements DialogProvider {
}
}).createItem());
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.measurement_tool, mapActivity)
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.plan_a_route, mapActivity)
.setId(DRAWER_MEASURE_DISTANCE_ID)
.setIcon(R.drawable.ic_action_ruler)
.setListener(new ItemClickListener() {

View file

@ -17,6 +17,7 @@ import net.osmand.plus.routing.RouteCalculationParams;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.router.RouteCalculationProgress;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Arrays;
@ -45,6 +46,7 @@ public class MeasurementEditingContext {
private boolean inSnapToRoadMode;
private boolean needUpdateCacheForSnap;
private int calculatedPairs;
private int trkptIndex;
private SnapToRoadProgressListener progressListener;
private ApplicationMode snapToRoadAppMode;
private RouteCalculationProgress calculationProgress;
@ -112,7 +114,7 @@ public class MeasurementEditingContext {
this.progressListener = progressListener;
}
ApplicationMode getSnapToRoadAppMode() {
public ApplicationMode getSnapToRoadAppMode() {
return snapToRoadAppMode;
}
@ -260,6 +262,54 @@ public class MeasurementEditingContext {
}
}
void addPoints() {
List<WptPt> points = getNewGpxData().getTrkSegment().points;
if (isSnapToRoadTrack()) {
List<WptPt> routePoints = getNewGpxData().getGpxFile().getRoutePoints();
int prevPointIndex = 0;
for (int i = 0; i < routePoints.size() - 1; i++) {
Pair<WptPt, WptPt> pair = new Pair<>(routePoints.get(i), routePoints.get(i + 1));
int startIndex = pair.first.getTrkPtIndex();
if (startIndex < 0 || startIndex < prevPointIndex || startIndex >= points.size()) {
startIndex = findPointIndex(pair.first, points, prevPointIndex);
}
int endIndex = pair.second.getTrkPtIndex() + 1;
if (endIndex < 0 || endIndex < startIndex || endIndex >= points.size()) {
endIndex = findPointIndex(pair.second, points, startIndex);
}
if (startIndex >= 0 && endIndex >= 0) {
List<WptPt> cacheSegment = new ArrayList<>();
for (int j = startIndex; j < endIndex && j < points.size(); j++) {
cacheSegment.add(points.get(j));
prevPointIndex = j;
}
snappedToRoadPoints.put(pair, cacheSegment);
}
}
addPoints(routePoints);
} else {
addPoints(points);
}
}
private int findPointIndex(WptPt point, List<WptPt> points, int firstIndex) {
double minDistance = Double.MAX_VALUE;
int index = 0;
for (int i = Math.max(0, firstIndex); i < points.size(); i++) {
double distance = MapUtils.getDistance(point.lat, point.lon, points.get(i).lat, points.get(i).lon);
if (distance < minDistance) {
minDistance = distance;
index = i;
}
}
return index;
}
boolean isSnapToRoadTrack() {
return !getNewGpxData().getTrkSegment().points.isEmpty()
&& !getNewGpxData().getGpxFile().getRoutePoints().isEmpty();
}
private void updateCacheForSnapIfNeeded(boolean both) {
if (needUpdateCacheForSnap) {
recreateCacheForSnap(beforeCacheForSnap = new TrkSegment(), before);
@ -342,6 +392,9 @@ public class MeasurementEditingContext {
}
calculatedPairs++;
snappedToRoadPoints.put(currentPair, pts);
trkptIndex = currentPair.first.getTrkPtIndex();
trkptIndex += pts.size() - 1;
currentPair.second.setTrkPtIndex(trkptIndex);
updateCacheForSnapIfNeeded(true);
application.runInUIThread(new Runnable() {
@Override

View file

@ -74,6 +74,7 @@ import net.osmand.plus.measurementtool.command.ReorderPointCommand;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.util.Algorithms;
import java.io.File;
import java.text.MessageFormat;
@ -220,7 +221,15 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
final NewGpxData newGpxData = editingCtx.getNewGpxData();
if (editingCtx.getNewGpxData() != null) {
if (newGpxData != null) {
List<WptPt> points = newGpxData.getGpxFile().getRoutePoints();
if (!points.isEmpty()) {
ApplicationMode snapToRoadAppMode = ApplicationMode
.valueOfStringKey(points.get(points.size() - 1).getProfileType(), null);
if (snapToRoadAppMode != null) {
enableSnapToRoadMode(snapToRoadAppMode);
}
}
ActionType actionType = newGpxData.getActionType();
if (actionType == ActionType.ADD_SEGMENT || actionType == ActionType.EDIT_SEGMENT) {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
@ -467,9 +476,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
enterMeasurementMode();
if (editingCtx.isInSnapToRoadMode()) {
showSnapToRoadControls();
}
if (newGpxData != null && !gpxPointsAdded) {
ActionType actionType = newGpxData.getActionType();
@ -560,7 +567,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
if (rememberPreviousTitle) {
previousToolBarTitle = toolBarController.getTitle();
}
toolBarController.setTitle(getString(R.string.snap_to_road));
toolBarController.setTitle(getString(R.string.route_between_points));
mapActivity.refreshMap();
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
fragment.setListener(createSnapToRoadFragmentListener());
@ -587,6 +594,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
public void addToGpxOnClick() {
if (mapActivity != null && measurementLayer != null) {
if (editingCtx.getPointsCount() > 0) {
if (editingCtx.isInSnapToRoadMode()) {
editingCtx.getPoints().clear();
editingCtx.getPoints().addAll(editingCtx.getBeforePoints());
editingCtx.getBeforePoints().clear();
editingCtx.getBeforePoints().addAll(editingCtx.getBeforeTrkSegmentLine().points);
}
addToGpx(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
@ -803,14 +816,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
private void showSnapToRoadControls() {
final MapActivity mapActivity = getMapActivity();
final ApplicationMode appMode = editingCtx.getSnapToRoadAppMode();
if (mapActivity != null && appMode != null) {
toolBarController.setTopBarSwitchVisible(true);
toolBarController.setTopBarSwitchChecked(true);
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_snap_to_road));
if (mapActivity != null) {
Drawable icon;
if (appMode == null) {
icon = getActiveIcon(R.drawable.ic_action_split_interval);
} else {
icon = getIcon(appMode.getIconRes(), appMode.getIconColorInfo().getColor(nightMode));
}
ImageButton snapToRoadBtn = (ImageButton) mapActivity.findViewById(R.id.snap_to_road_image_button);
snapToRoadBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle);
snapToRoadBtn.setImageDrawable(getIcon(appMode.getIconRes(), appMode.getIconColorInfo().getColor(nightMode)));
snapToRoadBtn.setImageDrawable(icon);
snapToRoadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -829,11 +844,18 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
editingCtx.setInSnapToRoadMode(false);
editingCtx.cancelSnapToRoad();
hideSnapToRoadIcon();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
mapActivity.refreshMap();
}
}
private void hideSnapToRoadIcon() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
mapActivity.refreshMap();
}
}
@ -851,11 +873,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
private void displaySegmentPoints() {
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
TrkSegment segment = editingCtx.getNewGpxData().getTrkSegment();
List<WptPt> points = segment.points;
if (measurementLayer != null) {
editingCtx.addPoints(points);
editingCtx.addPoints();
adapter.notifyDataSetChanged();
updateText();
}
@ -898,6 +917,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
WptPt newPoint = measurementLayer.getMovedPointToApply();
String profileType = editingCtx.getSnapToRoadAppMode().getStringKey();
if (!Algorithms.isEmpty(profileType)) {
newPoint.setProfileType(profileType);
}
WptPt oldPoint = editingCtx.getOriginalPointToMove();
int position = editingCtx.getSelectedPointPosition();
editingCtx.getCommandManager().execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position));
@ -1309,6 +1332,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
editingCtx.exportRouteAsGpx(trackName, new MeasurementEditingContext.ExportAsGpxListener() {
@Override
public void onExportAsGpxFinished(GPXFile gpx) {
gpx.addRoutePoints(editingCtx.getPoints());
final Exception res = GPXUtilities.writeGpxFile(toSave, gpx);
gpx.path = toSave.getAbsolutePath();
OsmandApplication app = getMyApplication();
@ -1594,6 +1618,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
}
if (editingCtx.isInSnapToRoadMode()) {
disableSnapToRoadMode();
} else {
hideSnapToRoadIcon();
}
if (editingCtx.getNewGpxData() != null) {
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();

View file

@ -10,7 +10,6 @@ import android.graphics.PointF;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
@ -20,6 +19,7 @@ import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.Renderable;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
@ -322,6 +322,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
pt.lon = l.getLongitude();
boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
if (allowed) {
String profileType = editingCtx.getSnapToRoadAppMode().getStringKey();
if (!Algorithms.isEmpty(profileType)) {
pt.setProfileType(profileType);
}
editingCtx.addPoint(pt);
return pt;
}
@ -338,6 +342,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
pressedPointLatLon = null;
boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
if (allowed) {
String profileType = editingCtx.getSnapToRoadAppMode().getStringKey();
if (!Algorithms.isEmpty(profileType)) {
pt.setProfileType(profileType);
}
editingCtx.addPoint(pt);
moveMapToLatLon(lat, lon);
return pt;

View file

@ -6,7 +6,7 @@ import android.view.View;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
@ -32,14 +32,11 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
items.add(new TitleItem(getString(R.string.shared_string_options)));
BaseBottomSheetItem snapToRoadItem = new BottomSheetItemWithCompoundButton.Builder()
.setChecked(snapToRoadEnabled)
.setDescription(getString(snapToRoadEnabled ? R.string.shared_string_on : R.string.shared_string_off))
.setIcon(snapToRoadEnabled
? getActiveIcon(R.drawable.ic_action_snap_to_road)
: getContentIcon(R.drawable.ic_action_snap_to_road))
.setTitle(getString(R.string.snap_to_road))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp)
BaseBottomSheetItem snapToRoadItem = new BottomSheetItemWithDescription.Builder()
.setDescription(getString(R.string.routing_profile_straightline))
.setIcon(getContentIcon(R.drawable.ic_action_split_interval))
.setTitle(getString(R.string.route_between_points))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -72,21 +69,7 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
items.add(saveAsNewSegmentItem);
} else if (addLineMode) {
BaseBottomSheetItem saveAsNewTrackItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
.setTitle(getString(R.string.shared_string_save_as_gpx))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.saveAsNewTrackOnClick();
}
dismiss();
}
})
.create();
items.add(saveAsNewTrackItem);
items.add(getSaveAsNewTrackItem());
BaseBottomSheetItem saveAsNewSegmentItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
@ -104,25 +87,11 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
.create();
items.add(saveAsNewSegmentItem);
} else {
BaseBottomSheetItem saveAsNewTrackItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
.setTitle(getString(R.string.shared_string_save_as_gpx))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.saveAsNewTrackOnClick();
}
dismiss();
}
})
.create();
items.add(saveAsNewTrackItem);
items.add(getSaveAsNewTrackItem());
BaseBottomSheetItem addToTrackItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_split_interval))
.setTitle(getString(R.string.add_segment_to_the_track))
.setTitle(getString(R.string.add_to_a_track))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
@ -156,6 +125,23 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
items.add(clearAllItem);
}
private BaseBottomSheetItem getSaveAsNewTrackItem() {
return new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_save_to_file))
.setTitle(getString(R.string.edit_filter_save_as_menu_item))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.saveAsNewTrackOnClick();
}
dismiss();
}
})
.create();
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_close;