Add NavigateTrackOptionsCard

This commit is contained in:
Vitaliy 2020-08-07 18:42:16 +03:00
parent 6d359fdd00
commit a719ce7912
7 changed files with 216 additions and 20 deletions

View file

@ -0,0 +1,38 @@
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing"
android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingBottom="@dimen/context_menu_padding_margin_tiny"
android:singleLine="true"
android:text="@string/navigate_to_track_descr"
android:textColor="@color/preference_category_title"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" />
<include
android:id="@+id/pass_whole_route_container"
layout="@layout/radio_buttons_with_descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_half" />
<include
android:id="@+id/navigation_type_container"
layout="@layout/radio_buttons_with_descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding" />
</LinearLayout>

View file

@ -0,0 +1,21 @@
<?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:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/setting_list_item_small_height"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/pass_whole_track_descr" />
<include layout="@layout/custom_radio_buttons" />
</LinearLayout>

View file

@ -11,6 +11,10 @@
Thx - Hardy
-->
<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>
<string name="navigate_to_track_descr">Navigate from my location to the track</string>
<string name="select_another_track">Select another track</string>
<string name="import_track_descr">Choose track file to follow or import it from device.</string>
<string name="follow_track_descr">Choose track file to follow</string>

View file

@ -41,14 +41,18 @@ import net.osmand.plus.measurementtool.MeasurementToolFragment;
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.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.routepreparationmenu.cards.ImportTrackCard;
import net.osmand.plus.routepreparationmenu.cards.NavigateTrackOptionsCard;
import net.osmand.plus.routepreparationmenu.cards.ReverseTrackCard;
import net.osmand.plus.routepreparationmenu.cards.SelectTrackCard;
import net.osmand.plus.routepreparationmenu.cards.TrackEditCard;
import net.osmand.plus.routepreparationmenu.cards.TracksToFollowCard;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import org.apache.commons.logging.Log;
@ -196,11 +200,34 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
cardsContainer.addView(selectTrackCard.build(mapActivity));
ApplicationMode mode = app.getRoutingHelper().getAppMode();
LocalRoutingParameter reverseParameter = app.getRoutingOptionsHelper().getReverseTrackParameter(mode);
if (reverseParameter != null) {
ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, reverseParameter);
reverseTrackCard.setListener(this);
cardsContainer.addView(reverseTrackCard.build(mapActivity));
RoutingHelper routingHelper = app.getRoutingHelper();
GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND;
if (rparams != null && osmandRouter) {
if (!routingHelper.isCurrentGPXRouteV2()) {
int textId = R.string.gpx_option_reverse_route;
String title = app.getString(textId);
LocalRoutingParameter parameter = new OtherLocalRoutingParameter(textId, title, rparams.isReverse());
ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, parameter);
reverseTrackCard.setListener(this);
cardsContainer.addView(reverseTrackCard.build(mapActivity));
}
if (!rparams.isUseIntermediatePointsRTE()) {
int passRouteId = R.string.gpx_option_from_start_point;
LocalRoutingParameter passWholeRoute = new OtherLocalRoutingParameter(passRouteId,
app.getString(passRouteId), rparams.isPassWholeRoute());
int navigationTypeId = R.string.gpx_option_calculate_first_last_segment;
LocalRoutingParameter navigationType = new OtherLocalRoutingParameter(navigationTypeId,
app.getString(navigationTypeId), rparams.isCalculateOsmAndRouteParts());
NavigateTrackOptionsCard navigateTrackCard = new NavigateTrackOptionsCard(mapActivity, passWholeRoute, navigationType);
navigateTrackCard.setListener(this);
cardsContainer.addView(navigateTrackCard.build(mapActivity));
}
}
}
}
@ -302,7 +329,8 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
dismiss();
} else if (card instanceof SelectTrackCard) {
updateSelectionMode(true);
} else if (card instanceof ReverseTrackCard) {
} else if (card instanceof ReverseTrackCard
|| card instanceof NavigateTrackOptionsCard) {
updateMenu();
}
}

View file

@ -487,19 +487,6 @@ public class RoutingOptionsHelper {
return list;
}
public LocalRoutingParameter getReverseTrackParameter(ApplicationMode mode) {
RoutingHelper routingHelper = app.getRoutingHelper();
GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
boolean osmandRouter = mode.getRouteService() == RouteService.OSMAND;
if (rparams != null && osmandRouter) {
if (!routingHelper.isCurrentGPXRouteV2()) {
int textId = R.string.gpx_option_reverse_route;
return new OtherLocalRoutingParameter(textId, app.getString(textId), rparams.isReverse());
}
}
return null;
}
public List<LocalRoutingParameter> getRoutingParametersInner(ApplicationMode am) {
boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND;
if (!osmandRouter) {

View file

@ -0,0 +1,118 @@
package net.osmand.plus.routepreparationmenu.cards;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.LEFT;
import static net.osmand.plus.UiUtilities.CustomRadioButtonType.RIGHT;
public class NavigateTrackOptionsCard extends BaseCard {
private LocalRoutingParameter passWholeRoute;
private LocalRoutingParameter navigationType;
public NavigateTrackOptionsCard(@NonNull MapActivity mapActivity,
@NonNull LocalRoutingParameter passWholeRoute,
@NonNull LocalRoutingParameter navigationType) {
super(mapActivity);
this.passWholeRoute = passWholeRoute;
this.navigationType = navigationType;
}
@Override
public int getCardLayoutId() {
return R.layout.navigate_track_options_card;
}
@Override
protected void updateContent() {
setupPassWholeRoute(view.findViewById(R.id.pass_whole_route_container));
setupNavigationType(view.findViewById(R.id.navigation_type_container));
}
private void setupPassWholeRoute(final View parameterView) {
View buttonsView = parameterView.findViewById(R.id.custom_radio_buttons);
TextView leftButton = parameterView.findViewById(R.id.left_button);
TextView rightButton = parameterView.findViewById(R.id.right_button);
TextView description = parameterView.findViewById(R.id.description);
boolean enabled = passWholeRoute.isSelected(app.getSettings());
CustomRadioButtonType buttonType = enabled ? LEFT : RIGHT;
UiUtilities.updateCustomRadioButtons(app, buttonsView, nightMode, buttonType);
leftButton.setText(R.string.start_of_the_track);
rightButton.setText(R.string.nearest_point);
description.setText(R.string.pass_whole_track_descr);
leftButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!passWholeRoute.isSelected(app.getSettings())) {
applyParameter(parameterView, passWholeRoute, LEFT, true);
}
}
});
rightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (passWholeRoute.isSelected(app.getSettings())) {
applyParameter(parameterView, passWholeRoute, RIGHT, false);
}
}
});
}
private void setupNavigationType(final View parameterView) {
View buttonsView = parameterView.findViewById(R.id.custom_radio_buttons);
TextView description = parameterView.findViewById(R.id.description);
TextView leftButton = parameterView.findViewById(R.id.left_button);
TextView rightButton = parameterView.findViewById(R.id.right_button);
description.setText(R.string.nav_type_hint);
leftButton.setText(R.string.routing_profile_straightline);
rightButton.setText(app.getRoutingHelper().getAppMode().toHumanString());
boolean enabled = navigationType.isSelected(app.getSettings());
CustomRadioButtonType buttonType = enabled ? RIGHT : LEFT;
UiUtilities.updateCustomRadioButtons(app, buttonsView, nightMode, buttonType);
leftButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (navigationType.isSelected(app.getSettings())) {
applyParameter(parameterView, navigationType, LEFT, false);
}
}
});
rightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!navigationType.isSelected(app.getSettings())) {
applyParameter(parameterView, navigationType, RIGHT, true);
}
}
});
}
private void applyParameter(View parameterView, LocalRoutingParameter parameter, CustomRadioButtonType buttonType, boolean isChecked) {
updateModeButtons(parameterView, buttonType);
app.getRoutingOptionsHelper().applyRoutingParameter(parameter, isChecked);
CardListener listener = getListener();
if (listener != null) {
listener.onCardPressed(NavigateTrackOptionsCard.this);
}
}
private void updateModeButtons(View customRadioButton, CustomRadioButtonType buttonType) {
UiUtilities.updateCustomRadioButtons(app, customRadioButton, nightMode, buttonType);
}
}

View file

@ -32,7 +32,7 @@ public class ReverseTrackCard extends BaseCard {
titleTv.setText(R.string.gpx_option_reverse_route);
ImageView icon = view.findViewById(R.id.icon);
icon.setImageDrawable(getActiveIcon(R.drawable.ic_action_change_navigation_points));
icon.setImageDrawable(getContentIcon(R.drawable.ic_action_change_navigation_points));
final CompoundButton compoundButton = view.findViewById(R.id.compound_button);
compoundButton.setChecked(parameter.isSelected(app.getSettings()));