Merge pull request #10348 from osmandapp/plan_route_config_profile

Plan route config profile
This commit is contained in:
Vitaliy 2020-12-07 09:47:51 +00:00 committed by GitHub
commit 7636630f6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 251 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

@ -110,16 +110,31 @@
android:layout_marginStart="@dimen/map_button_spacing_land"
android:background="@drawable/btn_round"
android:contentDescription="@string/layer_route"
tools:src="@drawable/ic_action_remove_dark"/>
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"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="bottom"
android:background="@drawable/btn_circle"
android:visibility="gone"
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>
<ImageButton
android:id="@+id/snap_to_road_image_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="bottom"
android:background="@drawable/btn_circle"
android:visibility="gone"
tools:src="@drawable/ic_action_remove_dark"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>

View file

@ -106,15 +106,28 @@
android:contentDescription="@string/layer_route"
tools:src="@drawable/ic_action_remove_dark"/>
<ImageButton
android:id="@+id/snap_to_road_image_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="bottom"
android:background="@drawable/btn_circle"
android:visibility="gone"
tools:src="@drawable/ic_action_remove_dark"
android:contentDescription="@string/snap_to_road" />
<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"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="bottom"
android:background="@drawable/btn_circle"
android:visibility="gone"
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"

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;
@ -69,6 +70,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.measurementtool.command.SplitPointsCommand;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.settings.backend.ApplicationMode;
@ -232,7 +234,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() {
@ -435,7 +437,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,
@ -499,7 +501,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
@ -508,6 +510,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);
@ -1292,17 +1319,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();
}
}
@ -1315,6 +1349,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,12 +13,15 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
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;
@ -32,6 +36,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;
@ -54,12 +59,16 @@ 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.ArrayList;
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.plus.settings.fragments.RouteParametersFragment.getRoutingParameterTitle;
@ -68,7 +77,10 @@ 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;
@ -83,17 +95,28 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
private CommonPreference<Boolean> useHeightPref;
private StateChangedListener<Boolean> voiceMuteChangeListener;
private StateChangedListener<Boolean> useHeightChangeListener;
private boolean planRouteMode;
private List<RoutingParameter> reliefParameters = new ArrayList<>();
@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);
planRouteMode = true;
}
}
app = requiredMyApplication();
settings = app.getSettings();
routingHelper = app.getRoutingHelper();
routingOptionsHelper = app.getRoutingOptionsHelper();
mapActivity = getMapActivity();
applicationMode = routingHelper.getAppMode();
if (applicationMode == null) {
applicationMode = routingHelper.getAppMode();
}
selectedModeColorId = applicationMode.getIconColorInfo().getColor(nightMode);
voiceMuteChangeListener = new StateChangedListener<Boolean>() {
@Override
@ -121,17 +144,23 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
if (optionsItem instanceof DividerItem) {
items.add(new DividerStartItem(app));
} else if (optionsItem instanceof MuteSoundRoutingParameter) {
items.add(createMuteSoundItem(optionsItem));
if (!planRouteMode) {
items.add(createMuteSoundItem(optionsItem));
}
} else if (optionsItem instanceof ShowAlongTheRouteItem) {
items.add(createShowAlongTheRouteItem(optionsItem));
} else if (optionsItem instanceof RouteSimulationItem) {
items.add(createRouteSimulationItem(optionsItem));
if (!planRouteMode) {
items.add(createRouteSimulationItem(optionsItem));
}
} else if (optionsItem instanceof AvoidPTTypesRoutingParameter) {
items.add(createAvoidPTTypesItem(optionsItem));
} else if (optionsItem instanceof AvoidRoadsRoutingParameter) {
items.add(createAvoidRoadsItem(optionsItem));
} else if (optionsItem instanceof GpxLocalRoutingParameter) {
items.add(createGpxRoutingItem(optionsItem));
if (!planRouteMode) {
items.add(createGpxRoutingItem(optionsItem));
}
} else if (optionsItem instanceof TimeConditionalRoutingItem) {
items.add(createTimeConditionalRoutingItem(optionsItem));
} else if (optionsItem instanceof OtherSettingsRoutingParameter) {
@ -478,8 +507,10 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
@Override
public void onClick(View view) {
dismiss();
Bundle args = new Bundle();
args.putBoolean(PLANE_ROUTE, planRouteMode);
BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.NAVIGATION,
mapActivity.getRoutingHelper().getAppMode());
applicationMode, args);
}
})
.create();
@ -576,6 +607,23 @@ 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);
if (fragment != null) {
((MeasurementToolFragment) fragment).onChangeApplicationMode(applicationMode, WHOLE_ROUTE_CALCULATION, ALL);
}
}
}
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode applicationMode) {
@ -610,8 +658,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,16 @@ 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();
}
});
}
@Override