Add attach roads card

This commit is contained in:
Vitaliy 2020-08-17 23:04:19 +03:00
parent a6c4456ca4
commit 26d88ccef2
10 changed files with 77 additions and 35 deletions

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="attach_to_the_roads">Attach to the roads</string>
<string name="nearest_point">Nearest point</string>
<string name="start_of_the_track">Start of the track</string>
<string name="pass_whole_track_descr">Point of the track to navigate</string>

View file

@ -34,7 +34,7 @@ import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.FollowTrackRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.GpxLocalRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.InterruptMusicRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameterGroup;
@ -163,7 +163,7 @@ public class RoutePreferencesMenu {
btn.performClick();
} else if (obj instanceof AvoidRoadsRoutingParameter) {
routingOptionsHelper.selectRestrictedRoads(mapActivity);
} else if (obj instanceof FollowTrackRoutingParameter) {
} else if (obj instanceof GpxLocalRoutingParameter) {
showOptionsMenu((TextView) view.findViewById(R.id.description));
} else {
CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
@ -287,7 +287,7 @@ public class RoutePreferencesMenu {
return v;
}
if (parameter instanceof FollowTrackRoutingParameter) {
if (parameter instanceof GpxLocalRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_gpx, null);
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) v.findViewById(R.id.title), nightMode);

View file

@ -418,7 +418,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (editingCtx.getPointsCount() > 0) {
if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT
&& editingCtx.isInSnapToRoadMode()) {
openSaveAsNewTrackMenu(mapActivity);
openSaveAsNewTrackMenu(mapActivity);
} else {
if (newGpxData == null) {
final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
@ -687,10 +687,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
@Override
public void saveAsNewTrackOnClick() {
openSaveAsNewTrackMenu(getMapActivity());
}
@Override
public void saveAsNewTrackOnClick() {
openSaveAsNewTrackMenu(getMapActivity());
}
@Override
public void addToTheTrackOnClick() {

View file

@ -43,6 +43,7 @@ import net.osmand.plus.measurementtool.NewGpxData;
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.OtherLocalRoutingParameter;
import net.osmand.plus.routepreparationmenu.cards.AttachTrackToRoadsCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.routepreparationmenu.cards.ImportTrackCard;
@ -207,6 +208,11 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
reverseTrackCard.setListener(this);
cardsContainer.addView(reverseTrackCard.build(mapActivity));
}
if (!gpxFile.hasRtePt()) {
AttachTrackToRoadsCard attachTrackCard = new AttachTrackToRoadsCard(mapActivity);
attachTrackCard.setListener(this);
cardsContainer.addView(attachTrackCard.build(mapActivity));
}
if (!rparams.isUseIntermediatePointsRTE()) {
setupNavigateOptionsCard(rparams);
}

View file

@ -2119,8 +2119,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
GPXRouteParamsBuilder routeParamsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
if (routeParamsBuilder != null) {
String description = new File(routeParamsBuilder.getFile().path).getName();
toText.setText(description);
String fileName = new File(routeParamsBuilder.getFile().path).getName();
toText.setText(GpxUiHelper.getGpxTitle(fileName));
toTitle.setText(R.string.follow_track);
} else {
TargetPointsHelper targets = app.getTargetPointsHelper();

View file

@ -39,7 +39,7 @@ import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DividerItem;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.FollowTrackRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.GpxLocalRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameterGroup;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.MuteSoundRoutingParameter;
@ -122,7 +122,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
items.add(createAvoidPTTypesItem(optionsItem));
} else if (optionsItem instanceof AvoidRoadsRoutingParameter) {
items.add(createAvoidRoadsItem(optionsItem));
} else if (optionsItem instanceof FollowTrackRoutingParameter) {
} else if (optionsItem instanceof GpxLocalRoutingParameter) {
items.add(createGpxRoutingItem(optionsItem));
} else if (optionsItem instanceof TimeConditionalRoutingItem) {
items.add(createTimeConditionalRoutingItem(optionsItem));
@ -576,11 +576,13 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
DividerItem.KEY,
AvoidRoadsRoutingParameter.KEY,
ShowAlongTheRouteItem.KEY,
DividerItem.KEY,
GpxLocalRoutingParameter.KEY,
DividerItem.KEY,
GeneralRouter.ALLOW_PRIVATE,
GeneralRouter.USE_SHORTEST_WAY,
TimeConditionalRoutingItem.KEY,
DividerItem.KEY,
FollowTrackRoutingParameter.KEY,
OtherSettingsRoutingParameter.KEY,
RouteSimulationItem.KEY),
@ -591,9 +593,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
GeneralRouter.ALLOW_MOTORWAYS,
AvoidRoadsRoutingParameter.KEY,
ShowAlongTheRouteItem.KEY,
GpxLocalRoutingParameter.KEY,
TimeConditionalRoutingItem.KEY,
DividerItem.KEY,
FollowTrackRoutingParameter.KEY,
OtherSettingsRoutingParameter.KEY,
RouteSimulationItem.KEY),
@ -602,9 +604,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
DividerItem.KEY,
AvoidRoadsRoutingParameter.KEY,
ShowAlongTheRouteItem.KEY,
GpxLocalRoutingParameter.KEY,
TimeConditionalRoutingItem.KEY,
DividerItem.KEY,
FollowTrackRoutingParameter.KEY,
OtherSettingsRoutingParameter.KEY,
RouteSimulationItem.KEY),
@ -620,9 +622,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
DividerItem.KEY,
AvoidRoadsRoutingParameter.KEY,
ShowAlongTheRouteItem.KEY,
GpxLocalRoutingParameter.KEY,
TimeConditionalRoutingItem.KEY,
DividerItem.KEY,
FollowTrackRoutingParameter.KEY,
OtherSettingsRoutingParameter.KEY,
RouteSimulationItem.KEY),
@ -630,7 +632,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
DividerItem.KEY,
ShowAlongTheRouteItem.KEY,
DividerItem.KEY,
FollowTrackRoutingParameter.KEY,
GpxLocalRoutingParameter.KEY,
OtherSettingsRoutingParameter.KEY,
RouteSimulationItem.KEY),
@ -638,7 +640,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
DividerItem.KEY,
ShowAlongTheRouteItem.KEY,
DividerItem.KEY,
FollowTrackRoutingParameter.KEY,
GpxLocalRoutingParameter.KEY,
OtherSettingsRoutingParameter.KEY,
RouteSimulationItem.KEY);

View file

@ -17,7 +17,6 @@ import androidx.appcompat.widget.AppCompatCheckedTextView;
import androidx.core.content.ContextCompat;
import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities;
import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.data.LatLon;
@ -392,8 +391,8 @@ public class RoutingOptionsHelper {
return new AvoidPTTypesRoutingParameter();
case AvoidRoadsRoutingParameter.KEY:
return new AvoidRoadsRoutingParameter();
case FollowTrackRoutingParameter.KEY:
return new FollowTrackRoutingParameter();
case GpxLocalRoutingParameter.KEY:
return new GpxLocalRoutingParameter();
case TimeConditionalRoutingItem.KEY:
return new TimeConditionalRoutingItem();
case OtherSettingsRoutingParameter.KEY:
@ -440,7 +439,7 @@ public class RoutingOptionsHelper {
list.add(2, new InterruptMusicRoutingParameter());
list.add(3, new AvoidRoadsRoutingParameter());
list.add(4, new TimeConditionalRoutingItem());
list.add(new FollowTrackRoutingParameter());
list.add(new GpxLocalRoutingParameter());
list.add(new OtherSettingsRoutingParameter());
return list;
}
@ -891,8 +890,7 @@ public class RoutingOptionsHelper {
}
}
public static class FollowTrackRoutingParameter extends LocalRoutingParameter {
public static class GpxLocalRoutingParameter extends LocalRoutingParameter {
public static final String KEY = "FollowTrackRoutingParameter";
@ -904,7 +902,7 @@ public class RoutingOptionsHelper {
return false;
}
public FollowTrackRoutingParameter() {
public GpxLocalRoutingParameter() {
super(null);
}

View file

@ -0,0 +1,42 @@
package net.osmand.plus.routepreparationmenu.cards;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
public class AttachTrackToRoadsCard extends BaseCard {
public AttachTrackToRoadsCard(@NonNull MapActivity mapActivity) {
super(mapActivity);
}
@Override
public int getCardLayoutId() {
return R.layout.bottom_sheet_item_simple;
}
@Override
protected void updateContent() {
TextView titleTv = view.findViewById(R.id.title);
titleTv.setText(R.string.attach_to_the_roads);
ImageView icon = view.findViewById(R.id.icon);
icon.setImageDrawable(getContentIcon(R.drawable.ic_action_snap_to_road));
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CardListener listener = getListener();
if (listener != null) {
listener.onCardPressed(AttachTrackToRoadsCard.this);
}
}
});
}
}

View file

@ -38,8 +38,6 @@ public class ReverseTrackCard extends BaseCard {
compoundButton.setChecked(parameter.isSelected(app.getSettings()));
UiUtilities.setupCompoundButton(nightMode, getActiveColor(), compoundButton);
int minHeight = app.getResources().getDimensionPixelSize(R.dimen.route_info_list_text_padding);
view.setMinimumHeight(minHeight);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -3,7 +3,6 @@ package net.osmand.plus.routepreparationmenu.cards;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import net.osmand.AndroidUtils;
@ -51,18 +50,11 @@ public class TrackEditCard extends BaseCard {
@Override
protected void updateContent() {
int minCardHeight = app.getResources().getDimensionPixelSize(R.dimen.setting_list_item_large_height);
int listContentPadding = app.getResources().getDimensionPixelSize(R.dimen.list_content_padding);
String fileName = Algorithms.getFileWithoutDirs(gpxInfo.getFileName());
String title = GpxUiHelper.getGpxTitle(fileName);
GpxDataItem dataItem = getDataItem(gpxInfo);
GpxUiHelper.updateGpxInfoView(view, title, gpxInfo, dataItem, false, app);
ImageView trackIcon = view.findViewById(R.id.icon);
trackIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
trackIcon.setVisibility(View.VISIBLE);
ImageButton editButton = view.findViewById(R.id.show_on_map);
editButton.setVisibility(View.VISIBLE);
editButton.setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark));
@ -76,6 +68,9 @@ public class TrackEditCard extends BaseCard {
}
});
int minCardHeight = app.getResources().getDimensionPixelSize(R.dimen.setting_list_item_large_height);
int listContentPadding = app.getResources().getDimensionPixelSize(R.dimen.list_content_padding);
LinearLayout container = view.findViewById(R.id.container);
container.setMinimumHeight(minCardHeight);
AndroidUtils.setPadding(container, listContentPadding, 0, 0, 0);