Plan route config profile

This commit is contained in:
Dima-1 2020-12-07 10:11:10 +02:00
parent abbe0ccf95
commit 892ff7addb
12 changed files with 257 additions and 30 deletions

View file

@ -0,0 +1,10 @@
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/map_button_inset_shadow"
android:insetTop="@dimen/map_button_inset_shadow"
android:insetRight="@dimen/map_button_inset_shadow"
android:insetBottom="@dimen/map_button_inset_shadow">
<shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark" />
<corners android:radius="48dp" />
</shape>
</inset>

View file

@ -0,0 +1,10 @@
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/map_button_inset_shadow"
android:insetTop="@dimen/map_button_inset_shadow"
android:insetRight="@dimen/map_button_inset_shadow"
android:insetBottom="@dimen/map_button_inset_shadow">
<shape android:shape="rectangle">
<solid android:color="@color/map_widget_light" />
<corners android:radius="48dp" />
</shape>
</inset>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="@color/map_widget_dark_pressed" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="@color/color_transparent" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="@color/map_widget_light_pressed" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="@color/map_widget_light" />
</shape>
</item>
</selector>

View file

@ -112,6 +112,10 @@
android:contentDescription="@string/layer_route"
tools:src="@drawable/ic_action_remove_dark" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/snap_to_road_image_button"
android:layout_width="@dimen/map_button_size"
@ -119,7 +123,18 @@
android:layout_gravity="bottom"
android:background="@drawable/btn_circle"
android:visibility="gone"
tools:src="@drawable/ic_action_remove_dark"/>
tools:src="@drawable/ic_action_remove_dark"
android:contentDescription="@string/snap_to_road" />
<include
android:id="@+id/profile_with_config_btn"
android:layout_width="wrap_content"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="bottom"
layout="@layout/profile_with_config_btn_layout"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>

View file

@ -106,6 +106,10 @@
android:contentDescription="@string/layer_route"
tools:src="@drawable/ic_action_remove_dark"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/snap_to_road_image_button"
android:layout_width="@dimen/map_button_size"
@ -116,6 +120,15 @@
tools:src="@drawable/ic_action_remove_dark"
android:contentDescription="@string/snap_to_road" />
<include
android:id="@+id/profile_with_config_btn"
android:layout_width="wrap_content"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="bottom"
layout="@layout/profile_with_config_btn_layout"
android:visibility="gone" />
</FrameLayout>
<LinearLayout
android:id="@+id/map_ruler_container"
android:layout_width="wrap_content"

View file

@ -0,0 +1,35 @@
<?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"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/btn_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp">
<ImageButton
android:id="@+id/profile"
android:layout_width="@dimen/map_route_buttons_height_land"
android:layout_height="@dimen/map_route_buttons_height_land"
app:srcCompat="@drawable/ic_action_car_dark"
android:background="@color/color_transparent"
android:contentDescription="@string/app_modes_choose"/>
<View
android:id="@+id/divider"
android:layout_width="1dp"
android:layout_height="24dp"
android:background="?attr/divider_color"
android:layout_gravity="center_vertical"/>
<ImageButton
android:id="@+id/profile_config"
android:layout_width="@dimen/map_route_buttons_height_land"
android:layout_height="@dimen/map_route_buttons_height_land"
app:srcCompat="@drawable/ic_action_settings"
android:background="@color/color_transparent"
android:contentDescription="@string/configure_profile" />
</LinearLayout>
</LinearLayout>

View file

@ -23,6 +23,7 @@
<attr name="btn_round" format="reference" />
<attr name="btn_round_border" format="reference" />
<attr name="btn_round_border_2" format="reference" />
<attr name="bg_round_btn" format="reference" />
<attr name="bg_card" format="reference" />
<attr name="context_menu_card" format="reference" />
<attr name="ctx_menu_card_btn" format="reference" />

View file

@ -96,6 +96,7 @@
<item name="btn_round">@drawable/btn_round_light</item>
<item name="btn_round_border">@drawable/btn_round_border_light</item>
<item name="btn_round_border_2">@drawable/btn_round_border_light_2</item>
<item name="bg_round_btn">@drawable/bg_round_btn_light</item>
<item name="bg_card">@drawable/bg_card_light</item>
<item name="context_menu_card">@drawable/context_menu_card_light</item>
<item name="bg_map_context_menu">@drawable/bg_map_context_menu_light</item>
@ -400,6 +401,7 @@
<item name="btn_round">@drawable/btn_round_dark</item>
<item name="btn_round_border">@drawable/btn_round_border_dark</item>
<item name="btn_round_border_2">@drawable/btn_round_border_dark_2</item>
<item name="bg_round_btn">@drawable/bg_round_btn_dark</item>
<item name="bg_card">@drawable/bg_card_dark</item>
<item name="context_menu_card">@drawable/context_menu_card_dark</item>
<item name="bg_map_context_menu">@drawable/bg_map_context_menu_dark</item>

View file

@ -22,6 +22,7 @@ import androidx.activity.OnBackPressedCallback;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.FragmentManager;
@ -68,6 +69,7 @@ import net.osmand.plus.measurementtool.command.MovePointCommand;
import net.osmand.plus.measurementtool.command.RemovePointCommand;
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
import net.osmand.plus.measurementtool.command.ReversePointsCommand;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
@ -230,7 +232,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return null;
}
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
OsmandApplication app = mapActivity.getMyApplication();
final OsmandApplication app = mapActivity.getMyApplication();
editingCtx.setApplication(mapActivity.getMyApplication());
editingCtx.setProgressListener(new SnapToRoadProgressListener() {
@ -432,7 +434,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onMeasure(float distance, float bearing) {
String distStr = OsmAndFormatter.getFormattedDistance(distance, mapActivity.getMyApplication());
String azimuthStr = OsmAndFormatter.getFormattedAzimuth(bearing, getMyApplication());
String azimuthStr = OsmAndFormatter.getFormattedAzimuth(bearing, app);
distanceToCenterTv.setText(String.format("%1$s • %2$s", distStr, azimuthStr));
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(
distanceToCenterTv, 14, 18, 2,
@ -496,7 +498,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
final GpxData gpxData = editingCtx.getGpxData();
ImageButton snapToRoadBtn = (ImageButton) mapActivity.findViewById(R.id.snap_to_road_image_button);
ImageButton snapToRoadBtn = mapActivity.findViewById(R.id.snap_to_road_image_button);
snapToRoadBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle);
snapToRoadBtn.setOnClickListener(new OnClickListener() {
@Override
@ -505,6 +507,31 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
});
snapToRoadBtn.setVisibility(View.VISIBLE);
LinearLayout profileWithConfig = mapActivity.findViewById(R.id.profile_with_config_btn);
View background = profileWithConfig.findViewById(R.id.btn_background);
AndroidUtils.setBackground(background, AppCompatResources.getDrawable(view.getContext(),
AndroidUtils.resolveAttribute(view.getContext(), R.attr.bg_round_btn)));
View divider = profileWithConfig.findViewById(R.id.divider);
divider.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), R.attr.divider_color));
ImageButton profileBtn = profileWithConfig.findViewById(R.id.profile);
profileBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night_no_shadow : R.drawable.btn_circle_no_shadow);
profileBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
startSnapToRoad(false);
}
});
ImageButton configBtn = profileWithConfig.findViewById(R.id.profile_config);
configBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night_no_shadow : R.drawable.btn_circle_no_shadow);
configBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_settings));
configBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RouteOptionsBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
editingCtx.getAppMode().getStringKey());
}
});
initMeasurementMode(gpxData, savedInstanceState == null);
@ -1251,17 +1278,24 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
final ApplicationMode appMode = editingCtx.getAppMode();
if (mapActivity != null) {
Drawable icon;
ImageButton snapToRoadBtn = mapActivity.findViewById(R.id.snap_to_road_image_button);
LinearLayout profileWithConfig = mapActivity.findViewById(R.id.profile_with_config_btn);
ImageButton configBtn = profileWithConfig.findViewById(R.id.profile);
if (isTrackReadyToCalculate()) {
if (appMode == MeasurementEditingContext.DEFAULT_APP_MODE) {
icon = getActiveIcon(R.drawable.ic_action_split_interval);
snapToRoadBtn.setVisibility(View.VISIBLE);
profileWithConfig.setVisibility(View.GONE);
} else {
icon = getIcon(appMode.getIconRes(), appMode.getIconColorInfo().getColor(nightMode));
snapToRoadBtn.setVisibility(View.GONE);
profileWithConfig.setVisibility(View.VISIBLE);
}
} else {
icon = getContentIcon(R.drawable.ic_action_help);
}
ImageButton snapToRoadBtn = (ImageButton) mapActivity.findViewById(R.id.snap_to_road_image_button);
snapToRoadBtn.setImageDrawable(icon);
configBtn.setImageDrawable(icon);
mapActivity.refreshMap();
}
}
@ -1274,6 +1308,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
mapActivity.findViewById(R.id.profile_with_config_btn).setVisibility(View.GONE);
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.routepreparationmenu;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
@ -12,11 +13,14 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener;
import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication;
@ -31,6 +35,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerStartItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DividerItem;
@ -53,18 +58,25 @@ import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static net.osmand.plus.measurementtool.RouteBetweenPointsBottomSheetDialogFragment.RouteBetweenPointsDialogMode.ALL;
import static net.osmand.plus.measurementtool.RouteBetweenPointsBottomSheetDialogFragment.RouteBetweenPointsDialogType.WHOLE_ROUTE_CALCULATION;
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
import static net.osmand.plus.settings.fragments.RouteParametersFragment.RELIEF_SMOOTHNESS_FACTOR;
import static net.osmand.router.GeneralRouter.USE_HEIGHT_OBSTACLES;
public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = "RouteOptionsBottomSheet";
public static final String TAG = RouteOptionsBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(RouteOptionsBottomSheet.class);
public static final String APP_MODE_KEY = "APP_MODE_KEY";
public static final String PLANE_ROUTE = "PLANE_ROUTE";
private OsmandApplication app;
private OsmandSettings settings;
@ -79,16 +91,27 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
private CommonPreference<Boolean> useHeightPref;
private StateChangedListener<Boolean> voiceMuteChangeListener;
private StateChangedListener<Boolean> useHeightChangeListener;
private boolean planeRouteMode;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if (args != null) {
String appMode = args.getString(APP_MODE_KEY, null);
if (appMode != null) {
applicationMode = ApplicationMode.valueOfStringKey(appMode, null);
planeRouteMode = true;
}
}
app = requiredMyApplication();
settings = app.getSettings();
routingHelper = app.getRoutingHelper();
routingOptionsHelper = app.getRoutingOptionsHelper();
mapActivity = getMapActivity();
if (applicationMode == null) {
applicationMode = routingHelper.getAppMode();
}
selectedModeColorId = applicationMode.getIconColorInfo().getColor(nightMode);
voiceMuteChangeListener = new StateChangedListener<Boolean>() {
@Override
@ -115,17 +138,29 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
if (optionsItem instanceof DividerItem) {
items.add(new DividerStartItem(app));
} else if (optionsItem instanceof MuteSoundRoutingParameter) {
if (!planeRouteMode) {
items.add(createMuteSoundItem(optionsItem));
} else {
continue;
}
} else if (optionsItem instanceof ShowAlongTheRouteItem) {
items.add(createShowAlongTheRouteItem(optionsItem));
} else if (optionsItem instanceof RouteSimulationItem) {
if (!planeRouteMode) {
items.add(createRouteSimulationItem(optionsItem));
} else {
continue;
}
} else if (optionsItem instanceof AvoidPTTypesRoutingParameter) {
items.add(createAvoidPTTypesItem(optionsItem));
} else if (optionsItem instanceof AvoidRoadsRoutingParameter) {
items.add(createAvoidRoadsItem(optionsItem));
} else if (optionsItem instanceof GpxLocalRoutingParameter) {
if (!planeRouteMode) {
items.add(createGpxRoutingItem(optionsItem));
} else {
continue;
}
} else if (optionsItem instanceof TimeConditionalRoutingItem) {
items.add(createTimeConditionalRoutingItem(optionsItem));
} else if (optionsItem instanceof OtherSettingsRoutingParameter) {
@ -415,8 +450,10 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
@Override
public void onClick(View view) {
dismiss();
Bundle args = new Bundle();
args.putBoolean(PLANE_ROUTE, true);
BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.NAVIGATION,
mapActivity.getRoutingHelper().getAppMode());
applicationMode, args);
}
})
.create();
@ -515,6 +552,21 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
if (mapActivity != null) {
mapActivity.getMapRouteInfoMenu().updateMenu();
}
}
@Override
public void onDismiss(@NonNull DialogInterface dialog) {
super.onDismiss(dialog);
updatePlanRoute();
}
private void updatePlanRoute() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MeasurementToolFragment.TAG);
((MeasurementToolFragment) fragment).onChangeApplicationMode(applicationMode, WHOLE_ROUTE_CALCULATION, ALL);
}
}
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode applicationMode) {
@ -549,8 +601,21 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
}
public static void showInstance(FragmentManager fragmentManager) {
RouteOptionsBottomSheet f = new RouteOptionsBottomSheet();
f.show(fragmentManager, RouteOptionsBottomSheet.TAG);
showInstance(fragmentManager, null);
}
public static void showInstance(FragmentManager fm, String appModeKey) {
try {
if (!fm.isStateSaved()) {
RouteOptionsBottomSheet fragment = new RouteOptionsBottomSheet();
Bundle args = new Bundle();
args.putString(APP_MODE_KEY, appModeKey);
fragment.setArguments(args);
fragment.show(fm, TAG);
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
public void updateParameters() {

View file

@ -3,9 +3,11 @@ package net.osmand.plus.settings.fragments;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.activity.OnBackPressedCallback;
import androidx.preference.Preference;
import androidx.preference.SwitchPreferenceCompat;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -33,6 +35,7 @@ import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
import static net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.PLANE_ROUTE;
public class NavigationFragment extends BaseSettingsFragment {
@ -48,6 +51,18 @@ public class NavigationFragment extends BaseSettingsFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
routingProfileDataObjects = getRoutingProfiles(app);
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
public void handleOnBackPressed() {
Bundle args = getArguments();
if (args != null && args.getBoolean(PLANE_ROUTE, false)) {
RouteOptionsBottomSheet.showInstance(getMapActivity().getSupportFragmentManager(),
getSelectedAppMode().getStringKey());
dismiss();
} else {
getActivity().onBackPressed();
}
}
});
}
@Override