Merge pull request #10284 from osmandapp/Combine-use-elevation-data
Combine "Use elevation data" and "Elevation fluctuation" into one dialog
This commit is contained in:
commit
8f6bbf1f4c
10 changed files with 374 additions and 68 deletions
|
@ -11,6 +11,7 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="elevation_data">You can use Elevation data for consideration of Ascent / Descent for your trip</string>
|
||||||
<string name="ltr_or_rtl_combine_via_star">%1$s * %2$s</string>
|
<string name="ltr_or_rtl_combine_via_star">%1$s * %2$s</string>
|
||||||
<string name="add_photos_descr">OsmAnd shows photos from several sources:\nOpenPlaceReviews - POI photos;\nMapillary - street-level imagery;\nWeb / Wikimedia - POI photos specified in OpenStreetMap data.</string>
|
<string name="add_photos_descr">OsmAnd shows photos from several sources:\nOpenPlaceReviews - POI photos;\nMapillary - street-level imagery;\nWeb / Wikimedia - POI photos specified in OpenStreetMap data.</string>
|
||||||
<string name="use_dev_url">Use dev.openstreetmap.org</string>
|
<string name="use_dev_url">Use dev.openstreetmap.org</string>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
|
@ -319,6 +320,20 @@ public class AndroidUtils {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ColorStateList createColorStateList(Context ctx, boolean night) {
|
||||||
|
return new ColorStateList(
|
||||||
|
new int[][] {
|
||||||
|
new int[] {-android.R.attr.state_enabled}, // disabled
|
||||||
|
new int[] {android.R.attr.state_checked},
|
||||||
|
new int[] {}
|
||||||
|
},
|
||||||
|
new int[] {
|
||||||
|
Color.GRAY,
|
||||||
|
ContextCompat.getColor(ctx, night? R.color.active_color_primary_dark : R.color.active_color_primary_light),
|
||||||
|
Color.GRAY}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static StateListDrawable createCheckedStateListDrawable(Drawable normal, Drawable checked) {
|
public static StateListDrawable createCheckedStateListDrawable(Drawable normal, Drawable checked) {
|
||||||
return createStateListDrawable(normal, checked, android.R.attr.state_checked);
|
return createStateListDrawable(normal, checked, android.R.attr.state_checked);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,16 +45,22 @@ import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.TimeConditional
|
||||||
import net.osmand.plus.routing.RouteProvider;
|
import net.osmand.plus.routing.RouteProvider;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
import net.osmand.plus.settings.backend.CommonPreference;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.ElevationDateBottomSheet;
|
||||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||||
import net.osmand.router.GeneralRouter;
|
import net.osmand.router.GeneralRouter;
|
||||||
|
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
|
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 class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
|
@ -68,13 +74,16 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
@ColorRes
|
@ColorRes
|
||||||
private int selectedModeColorId;
|
private int selectedModeColorId;
|
||||||
private boolean currentMuteState;
|
private boolean currentMuteState;
|
||||||
|
private boolean currentUseHeightState;
|
||||||
private MapActivity mapActivity;
|
private MapActivity mapActivity;
|
||||||
StateChangedListener<Boolean> voiceMuteChangeListener;
|
private CommonPreference<Boolean> useHeightPref;
|
||||||
|
private StateChangedListener<Boolean> voiceMuteChangeListener;
|
||||||
|
private StateChangedListener<Boolean> useHeightChangeListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
app = getMyApplication();
|
app = requiredMyApplication();
|
||||||
settings = app.getSettings();
|
settings = app.getSettings();
|
||||||
routingHelper = app.getRoutingHelper();
|
routingHelper = app.getRoutingHelper();
|
||||||
routingOptionsHelper = app.getRoutingOptionsHelper();
|
routingOptionsHelper = app.getRoutingOptionsHelper();
|
||||||
|
@ -87,16 +96,13 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
updateWhenMuteChanged();
|
updateWhenMuteChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
useHeightChangeListener = new StateChangedListener<Boolean>() {
|
||||||
|
@Override
|
||||||
public void updateWhenMuteChanged() {
|
public void stateChanged(Boolean change) {
|
||||||
if (app != null) {
|
updateWhenUseHeightChanged();
|
||||||
boolean changedState = app.getSettings().VOICE_MUTE.getModeValue(applicationMode);
|
|
||||||
if (changedState != currentMuteState) {
|
|
||||||
currentMuteState = changedState;
|
|
||||||
updateParameters();
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
useHeightPref = settings.getCustomRoutingBooleanProperty(USE_HEIGHT_OBSTACLES, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,12 +145,17 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
itemWithCompoundButton.setChecked(itemWithCompoundButton.isChecked());
|
itemWithCompoundButton.setChecked(itemWithCompoundButton.isChecked());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
currentUseHeightState = useHeightPref.getModeValue(applicationMode);
|
||||||
|
currentMuteState = app.getSettings().VOICE_MUTE.getModeValue(applicationMode);
|
||||||
|
|
||||||
|
useHeightPref.addListener(useHeightChangeListener);
|
||||||
app.getSettings().VOICE_MUTE.addListener(voiceMuteChangeListener);
|
app.getSettings().VOICE_MUTE.addListener(voiceMuteChangeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
useHeightPref.removeListener(useHeightChangeListener);
|
||||||
app.getSettings().VOICE_MUTE.removeListener(voiceMuteChangeListener);
|
app.getSettings().VOICE_MUTE.removeListener(voiceMuteChangeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +178,24 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateWhenMuteChanged() {
|
||||||
|
boolean changedState = app.getSettings().VOICE_MUTE.getModeValue(applicationMode);
|
||||||
|
if (changedState != currentMuteState) {
|
||||||
|
currentMuteState = changedState;
|
||||||
|
updateParameters();
|
||||||
|
updateMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateWhenUseHeightChanged() {
|
||||||
|
boolean changedState = useHeightPref.getModeValue(applicationMode);
|
||||||
|
if (changedState != currentUseHeightState) {
|
||||||
|
currentUseHeightState = changedState;
|
||||||
|
updateParameters();
|
||||||
|
updateMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private BaseBottomSheetItem createMuteSoundItem(final LocalRoutingParameter optionsItem) {
|
private BaseBottomSheetItem createMuteSoundItem(final LocalRoutingParameter optionsItem) {
|
||||||
boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode);
|
boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode);
|
||||||
int selectedModeColor = ContextCompat.getColor(app, selectedModeColorId);
|
int selectedModeColor = ContextCompat.getColor(app, selectedModeColorId);
|
||||||
|
@ -432,22 +461,21 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
builder.setLayoutId(R.layout.bottom_sheet_item_with_switch_56dp);
|
builder.setLayoutId(R.layout.bottom_sheet_item_with_switch_56dp);
|
||||||
if (parameter.routingParameter != null && parameter.routingParameter.getId().equals(GeneralRouter.USE_SHORTEST_WAY)) {
|
if (parameter.routingParameter != null && parameter.routingParameter.getId().equals(GeneralRouter.USE_SHORTEST_WAY)) {
|
||||||
// if short route settings - it should be inverse of fast_route_mode
|
// if short route settings - it should be inverse of fast_route_mode
|
||||||
builder.setChecked(!settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode()));
|
builder.setChecked(!settings.FAST_ROUTE_MODE.getModeValue(applicationMode));
|
||||||
} else {
|
} else {
|
||||||
builder.setChecked(parameter.isSelected(settings));
|
builder.setChecked(parameter.isSelected(settings));
|
||||||
}
|
}
|
||||||
builder.setOnClickListener(new View.OnClickListener() {
|
builder.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
routingOptionsHelper.addNewRouteMenuParameter(applicationMode, parameter);
|
if (USE_HEIGHT_OBSTACLES.equals(parameter.getKey()) && hasReliefParameters()) {
|
||||||
boolean selected = !parameter.isSelected(settings);
|
FragmentManager fm = getFragmentManager();
|
||||||
routingOptionsHelper.applyRoutingParameter(parameter, selected);
|
if (fm != null) {
|
||||||
item[0].setChecked(selected);
|
ElevationDateBottomSheet.showInstance(fm, applicationMode, RouteOptionsBottomSheet.this, false);
|
||||||
int iconId = selected ? parameter.getActiveIconId() : parameter.getDisabledIconId();
|
}
|
||||||
if (iconId != -1) {
|
} else {
|
||||||
item[0].setIcon(getContentIcon(iconId));
|
applyParameter(item[0], parameter);
|
||||||
}
|
}
|
||||||
updateMenu();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -459,6 +487,29 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasReliefParameters() {
|
||||||
|
Map<String, RoutingParameter> parameters = app.getRouter(applicationMode).getParameters();
|
||||||
|
for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
|
||||||
|
RoutingParameter routingParameter = e.getValue();
|
||||||
|
if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyParameter(BottomSheetItemWithCompoundButton bottomSheetItem, LocalRoutingParameter parameter) {
|
||||||
|
routingOptionsHelper.addNewRouteMenuParameter(applicationMode, parameter);
|
||||||
|
boolean selected = !parameter.isSelected(settings);
|
||||||
|
routingOptionsHelper.applyRoutingParameter(parameter, selected);
|
||||||
|
bottomSheetItem.setChecked(selected);
|
||||||
|
int iconId = selected ? parameter.getActiveIconId() : parameter.getDisabledIconId();
|
||||||
|
if (iconId != -1) {
|
||||||
|
bottomSheetItem.setIcon(getContentIcon(iconId));
|
||||||
|
}
|
||||||
|
updateMenu();
|
||||||
|
}
|
||||||
|
|
||||||
private void updateMenu() {
|
private void updateMenu() {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
|
|
|
@ -542,8 +542,8 @@ public class RoutingOptionsHelper {
|
||||||
rp.disabledIconId = R.drawable.ic_action_fuel;
|
rp.disabledIconId = R.drawable.ic_action_fuel;
|
||||||
break;
|
break;
|
||||||
case GeneralRouter.USE_HEIGHT_OBSTACLES:
|
case GeneralRouter.USE_HEIGHT_OBSTACLES:
|
||||||
rp.activeIconId = R.drawable.ic_action_elevation;
|
rp.activeIconId = R.drawable.ic_action_altitude_average;
|
||||||
rp.disabledIconId = R.drawable.ic_action_elevation;
|
rp.disabledIconId = R.drawable.ic_action_altitude_average;
|
||||||
break;
|
break;
|
||||||
case GeneralRouter.AVOID_FERRIES:
|
case GeneralRouter.AVOID_FERRIES:
|
||||||
rp.activeIconId = R.drawable.ic_action_fuel;
|
rp.activeIconId = R.drawable.ic_action_fuel;
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class OsmandSettings {
|
||||||
private static String CUSTOM_SHARED_PREFERENCES_NAME;
|
private static String CUSTOM_SHARED_PREFERENCES_NAME;
|
||||||
|
|
||||||
private static final String RENDERER_PREFERENCE_PREFIX = "nrenderer_";
|
private static final String RENDERER_PREFERENCE_PREFIX = "nrenderer_";
|
||||||
private static final String ROUTING_PREFERENCE_PREFIX = "prouting_";
|
public static final String ROUTING_PREFERENCE_PREFIX = "prouting_";
|
||||||
|
|
||||||
/// Settings variables
|
/// Settings variables
|
||||||
private final OsmandApplication ctx;
|
private final OsmandApplication ctx;
|
||||||
|
|
|
@ -9,21 +9,22 @@ import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.settings.backend.BooleanPreference;
|
|
||||||
import net.osmand.plus.settings.backend.OsmandPreference;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
import net.osmand.plus.settings.backend.BooleanPreference;
|
||||||
|
import net.osmand.plus.settings.backend.OsmandPreference;
|
||||||
import net.osmand.plus.settings.fragments.ApplyQueryType;
|
import net.osmand.plus.settings.fragments.ApplyQueryType;
|
||||||
import net.osmand.plus.settings.fragments.OnConfirmPreferenceChange;
|
import net.osmand.plus.settings.fragments.OnConfirmPreferenceChange;
|
||||||
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
|
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
|
||||||
|
@ -39,7 +40,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
if (app == null) {
|
if (app == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
.setChecked(checked)
|
.setChecked(checked)
|
||||||
.setTitle(checked ? on : off)
|
.setTitle(checked ? on : off)
|
||||||
.setTitleColorId(checked ? activeColor : disabledColor)
|
.setTitleColorId(checked ? activeColor : disabledColor)
|
||||||
.setCustomView(getCustomButtonView(checked))
|
.setCustomView(getCustomButtonView(app, getAppMode(), checked, nightMode))
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -91,7 +92,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
preferenceBtn[0].setTitle(newValue ? on : off);
|
preferenceBtn[0].setTitle(newValue ? on : off);
|
||||||
preferenceBtn[0].setChecked(newValue);
|
preferenceBtn[0].setChecked(newValue);
|
||||||
preferenceBtn[0].setTitleColorId(newValue ? activeColor : disabledColor);
|
preferenceBtn[0].setTitleColorId(newValue ? activeColor : disabledColor);
|
||||||
updateCustomButtonView(v, newValue);
|
updateCustomButtonView(app, getAppMode(), v, newValue, nightMode);
|
||||||
|
|
||||||
if (targetFragment instanceof OnPreferenceChanged) {
|
if (targetFragment instanceof OnPreferenceChanged) {
|
||||||
((OnPreferenceChanged) targetFragment).onPreferenceChanged(switchPreference.getKey());
|
((OnPreferenceChanged) targetFragment).onPreferenceChanged(switchPreference.getKey());
|
||||||
|
@ -121,25 +122,24 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
return R.string.shared_string_cancel;
|
return R.string.shared_string_cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected View getCustomButtonView(boolean checked) {
|
protected static View getCustomButtonView(OsmandApplication app, ApplicationMode mode, boolean checked, boolean nightMode) {
|
||||||
View customView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_preference_switch, null);
|
View customView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_item_preference_switch, null);
|
||||||
updateCustomButtonView(customView, checked);
|
updateCustomButtonView(app, mode, customView, checked, nightMode);
|
||||||
|
|
||||||
return customView;
|
return customView;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateCustomButtonView(View customView, boolean checked) {
|
protected static void updateCustomButtonView(OsmandApplication app, ApplicationMode mode, View customView, boolean checked, boolean nightMode) {
|
||||||
OsmandApplication app = requiredMyApplication();
|
|
||||||
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
|
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
|
||||||
View buttonView = customView.findViewById(R.id.button_container);
|
View buttonView = customView.findViewById(R.id.button_container);
|
||||||
|
|
||||||
int colorRes = getAppMode().getIconColorInfo().getColor(nightMode);
|
int colorRes = mode.getIconColorInfo().getColor(nightMode);
|
||||||
int color = checked ? getResolvedColor(colorRes) : AndroidUtils.getColorFromAttr(themedCtx, R.attr.divider_color_basic);
|
int color = checked ? ContextCompat.getColor(themedCtx, colorRes) : AndroidUtils.getColorFromAttr(themedCtx, R.attr.divider_color_basic);
|
||||||
int bgColor = UiUtilities.getColorWithAlpha(color, checked ? 0.1f : 0.5f);
|
int bgColor = UiUtilities.getColorWithAlpha(color, checked ? 0.1f : 0.5f);
|
||||||
int selectedColor = UiUtilities.getColorWithAlpha(color, checked ? 0.3f : 0.5f);
|
int selectedColor = UiUtilities.getColorWithAlpha(color, checked ? 0.3f : 0.5f);
|
||||||
|
|
||||||
|
int bgResId = R.drawable.rectangle_rounded_right;
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||||
int bgResId = R.drawable.rectangle_rounded_right;
|
|
||||||
int selectableResId = R.drawable.ripple_rectangle_rounded_right;
|
int selectableResId = R.drawable.ripple_rectangle_rounded_right;
|
||||||
|
|
||||||
Drawable bgDrawable = app.getUIUtilities().getPaintedIcon(bgResId, bgColor);
|
Drawable bgDrawable = app.getUIUtilities().getPaintedIcon(bgResId, bgColor);
|
||||||
|
@ -147,7 +147,6 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
Drawable[] layers = {bgDrawable, selectable};
|
Drawable[] layers = {bgDrawable, selectable};
|
||||||
AndroidUtils.setBackground(buttonView, new LayerDrawable(layers));
|
AndroidUtils.setBackground(buttonView, new LayerDrawable(layers));
|
||||||
} else {
|
} else {
|
||||||
int bgResId = R.drawable.rectangle_rounded_right;
|
|
||||||
Drawable bgDrawable = app.getUIUtilities().getPaintedIcon(bgResId, bgColor);
|
Drawable bgDrawable = app.getUIUtilities().getPaintedIcon(bgResId, bgColor);
|
||||||
AndroidUtils.setBackground(buttonView, bgDrawable);
|
AndroidUtils.setBackground(buttonView, bgDrawable);
|
||||||
}
|
}
|
||||||
|
@ -158,8 +157,8 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target, boolean usedOnMap,
|
public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target, boolean usedOnMap,
|
||||||
@Nullable ApplicationMode appMode, ApplyQueryType applyQueryType,
|
@Nullable ApplicationMode appMode, ApplyQueryType applyQueryType,
|
||||||
boolean profileDependent) {
|
boolean profileDependent) {
|
||||||
try {
|
try {
|
||||||
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
|
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
|
@ -0,0 +1,234 @@
|
||||||
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
|
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.simpleitems.DividerSpaceItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
import net.osmand.plus.settings.backend.CommonPreference;
|
||||||
|
import net.osmand.plus.settings.fragments.ApplyQueryType;
|
||||||
|
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||||
|
import net.osmand.plus.settings.fragments.OnConfirmPreferenceChange;
|
||||||
|
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static net.osmand.AndroidUtils.createColorStateList;
|
||||||
|
import static net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.getCustomButtonView;
|
||||||
|
import static net.osmand.plus.settings.bottomsheets.BooleanPreferenceBottomSheet.updateCustomButtonView;
|
||||||
|
import static net.osmand.plus.settings.fragments.BaseSettingsFragment.APP_MODE_KEY;
|
||||||
|
import static net.osmand.plus.settings.fragments.RouteParametersFragment.RELIEF_SMOOTHNESS_FACTOR;
|
||||||
|
import static net.osmand.plus.settings.fragments.RouteParametersFragment.getRoutingParameterTitle;
|
||||||
|
import static net.osmand.plus.settings.fragments.RouteParametersFragment.isRoutingParameterSelected;
|
||||||
|
import static net.osmand.plus.settings.fragments.RouteParametersFragment.updateSelectedParameters;
|
||||||
|
import static net.osmand.router.GeneralRouter.USE_HEIGHT_OBSTACLES;
|
||||||
|
|
||||||
|
public class ElevationDateBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
|
public static final String TAG = ElevationDateBottomSheet.class.getSimpleName();
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(ElevationDateBottomSheet.class);
|
||||||
|
|
||||||
|
private OsmandApplication app;
|
||||||
|
private ApplicationMode appMode;
|
||||||
|
private List<RoutingParameter> parameters;
|
||||||
|
private CommonPreference<Boolean> useHeightPref;
|
||||||
|
|
||||||
|
private BottomSheetItemWithCompoundButton useHeightButton;
|
||||||
|
private List<BottomSheetItemWithCompoundButton> reliefFactorButtons = new ArrayList<>();
|
||||||
|
|
||||||
|
private int selectedEntryIndex = -1;
|
||||||
|
|
||||||
|
private String on;
|
||||||
|
private String off;
|
||||||
|
private int activeColor;
|
||||||
|
private int disabledColor;
|
||||||
|
private int appModeColor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
app = requiredMyApplication();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
|
||||||
|
}
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
Map<String, RoutingParameter> routingParameterMap = app.getRouter(appMode).getParameters();
|
||||||
|
RoutingParameter parameter = routingParameterMap.get(USE_HEIGHT_OBSTACLES);
|
||||||
|
if (parameter != null) {
|
||||||
|
useHeightPref = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
|
||||||
|
} else {
|
||||||
|
useHeightPref = app.getSettings().getCustomRoutingBooleanProperty(USE_HEIGHT_OBSTACLES, false);
|
||||||
|
}
|
||||||
|
parameters = getReliefParametersForMode(routingParameterMap);
|
||||||
|
for (int i = 0; i < parameters.size(); i++) {
|
||||||
|
if (isRoutingParameterSelected(app.getSettings(), appMode, parameters.get(i))) {
|
||||||
|
selectedEntryIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
Context themedCtx = UiUtilities.getThemedContext(requireContext(), nightMode);
|
||||||
|
|
||||||
|
on = getString(R.string.shared_string_enable);
|
||||||
|
off = getString(R.string.shared_string_disable);
|
||||||
|
appModeColor = appMode.getIconColorInfo().getColor(nightMode);
|
||||||
|
activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
|
||||||
|
disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
|
||||||
|
|
||||||
|
items.add(new TitleItem(getString(R.string.routing_attr_height_obstacles_name)));
|
||||||
|
|
||||||
|
createUseHeightButton(themedCtx);
|
||||||
|
|
||||||
|
int contentPaddingSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||||
|
items.add(new DividerSpaceItem(app, contentPaddingSmall));
|
||||||
|
items.add(new LongDescriptionItem(getString(R.string.elevation_data)));
|
||||||
|
items.add(new DividerSpaceItem(app, contentPaddingSmall));
|
||||||
|
|
||||||
|
createReliefFactorButtons(themedCtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUseHeightButton(Context context) {
|
||||||
|
boolean checked = useHeightPref.getModeValue(appMode);
|
||||||
|
useHeightButton = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
|
||||||
|
.setCompoundButtonColorId(appModeColor)
|
||||||
|
.setChecked(checked)
|
||||||
|
.setTitle(checked ? on : off)
|
||||||
|
.setTitleColorId(checked ? activeColor : disabledColor)
|
||||||
|
.setCustomView(getCustomButtonView(app, appMode, checked, nightMode))
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean newValue = !useHeightPref.getModeValue(appMode);
|
||||||
|
Fragment target = getTargetFragment();
|
||||||
|
if (target instanceof OnConfirmPreferenceChange) {
|
||||||
|
OnConfirmPreferenceChange confirmInterface = (OnConfirmPreferenceChange) target;
|
||||||
|
if (confirmInterface.onConfirmPreferenceChange(useHeightPref.getId(), newValue, ApplyQueryType.NONE)) {
|
||||||
|
updateUseHeightButton(useHeightButton, newValue);
|
||||||
|
|
||||||
|
if (target instanceof BaseSettingsFragment) {
|
||||||
|
((BaseSettingsFragment) target).updateSetting(useHeightPref.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
useHeightPref.setModeValue(appMode, newValue);
|
||||||
|
updateUseHeightButton(useHeightButton, newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).create();
|
||||||
|
items.add(useHeightButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateUseHeightButton(BottomSheetItemWithCompoundButton button, boolean newValue) {
|
||||||
|
enableDisableReliefButtons(newValue);
|
||||||
|
button.setTitle(newValue ? on : off);
|
||||||
|
button.setChecked(newValue);
|
||||||
|
button.setTitleColorId(newValue ? activeColor : disabledColor);
|
||||||
|
updateCustomButtonView(app, appMode, button.getView(), newValue, nightMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createReliefFactorButtons(Context context) {
|
||||||
|
for (int i = 0; i < parameters.size(); i++) {
|
||||||
|
RoutingParameter parameter = parameters.get(i);
|
||||||
|
final BottomSheetItemWithCompoundButton[] preferenceItem = new BottomSheetItemWithCompoundButton[1];
|
||||||
|
preferenceItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
|
||||||
|
.setChecked(i == selectedEntryIndex)
|
||||||
|
.setButtonTintList(createColorStateList(context, nightMode))
|
||||||
|
.setTitle(getRoutingParameterTitle(app, parameter))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_with_radio_btn_left)
|
||||||
|
.setTag(i)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
selectedEntryIndex = (int) preferenceItem[0].getTag();
|
||||||
|
if (selectedEntryIndex >= 0) {
|
||||||
|
RoutingParameter parameter = parameters.get(selectedEntryIndex);
|
||||||
|
updateSelectedParameters(app, appMode, parameters, parameter.getId());
|
||||||
|
}
|
||||||
|
updateReliefButtons();
|
||||||
|
}
|
||||||
|
}).create();
|
||||||
|
items.add(preferenceItem[0]);
|
||||||
|
reliefFactorButtons.add(preferenceItem[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putString(APP_MODE_KEY, appMode.getStringKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
updateReliefButtons();
|
||||||
|
enableDisableReliefButtons(useHeightButton.isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isNightMode(@NonNull OsmandApplication app) {
|
||||||
|
if (usedOnMap) {
|
||||||
|
return app.getDaynightHelper().isNightModeForMapControlsForProfile(appMode);
|
||||||
|
} else {
|
||||||
|
return !app.getSettings().isLightContentForMode(appMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<RoutingParameter> getReliefParametersForMode(Map<String, RoutingParameter> parameters) {
|
||||||
|
List<RoutingParameter> reliefParameters = new ArrayList<>();
|
||||||
|
for (RoutingParameter routingParameter : parameters.values()) {
|
||||||
|
if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) {
|
||||||
|
reliefParameters.add(routingParameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reliefParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateReliefButtons() {
|
||||||
|
for (BottomSheetItemWithCompoundButton item : reliefFactorButtons) {
|
||||||
|
item.setChecked(item.getTag().equals(selectedEntryIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableDisableReliefButtons(boolean enable) {
|
||||||
|
for (BaseBottomSheetItem item : reliefFactorButtons) {
|
||||||
|
item.getView().setEnabled(enable);
|
||||||
|
item.getView().findViewById(R.id.compound_button).setEnabled(enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(FragmentManager fm, ApplicationMode appMode, Fragment target, boolean usedOnMap) {
|
||||||
|
try {
|
||||||
|
if (!fm.isStateSaved() && fm.findFragmentByTag(ElevationDateBottomSheet.TAG) == null) {
|
||||||
|
ElevationDateBottomSheet fragment = new ElevationDateBottomSheet();
|
||||||
|
fragment.appMode = appMode;
|
||||||
|
fragment.setUsedOnMap(usedOnMap);
|
||||||
|
fragment.setTargetFragment(target, 0);
|
||||||
|
fragment.show(fm, ScreenTimeoutBottomSheet.TAG);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
LOG.error("showInstance", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -111,7 +111,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
|
||||||
.setCompoundButtonColorId(appModeColorId)
|
.setCompoundButtonColorId(appModeColorId)
|
||||||
.setTitle(enabled ? on : off)
|
.setTitle(enabled ? on : off)
|
||||||
.setTitleColorId(enabled ? activeColor : disabledColor)
|
.setTitleColorId(enabled ? activeColor : disabledColor)
|
||||||
.setCustomView(getCustomButtonView(enabled))
|
.setCustomView(getCustomButtonView(app, getAppMode(), enabled, nightMode))
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -123,7 +123,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
|
||||||
preferenceBtn[0].setChecked(enabled);
|
preferenceBtn[0].setChecked(enabled);
|
||||||
getDefaultValue();
|
getDefaultValue();
|
||||||
updateSliderView();
|
updateSliderView();
|
||||||
updateCustomButtonView(v, enabled);
|
updateCustomButtonView(app, getAppMode(), v, enabled, nightMode);
|
||||||
Fragment target = getTargetFragment();
|
Fragment target = getTargetFragment();
|
||||||
float newValue = enabled ? DEFAULT_MODE : DISABLE_MODE;
|
float newValue = enabled ? DEFAULT_MODE : DISABLE_MODE;
|
||||||
if (target instanceof OnConfirmPreferenceChange) {
|
if (target instanceof OnConfirmPreferenceChange) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet
|
||||||
|
|
||||||
public static final String TAG = SingleSelectPreferenceBottomSheet.class.getSimpleName();
|
public static final String TAG = SingleSelectPreferenceBottomSheet.class.getSimpleName();
|
||||||
|
|
||||||
private static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key";
|
public static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key";
|
||||||
private static final String USE_COLLAPSIBLE_DESCRIPTION = "use_collapsible_description";
|
private static final String USE_COLLAPSIBLE_DESCRIPTION = "use_collapsible_description";
|
||||||
private static final int COLLAPSED_DESCRIPTION_LINES = 4;
|
private static final int COLLAPSED_DESCRIPTION_LINES = 4;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ import net.osmand.plus.settings.backend.BooleanPreference;
|
||||||
import net.osmand.plus.settings.backend.CommonPreference;
|
import net.osmand.plus.settings.backend.CommonPreference;
|
||||||
import net.osmand.plus.settings.backend.OsmandPreference;
|
import net.osmand.plus.settings.backend.OsmandPreference;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
|
import net.osmand.plus.settings.bottomsheets.ElevationDateBottomSheet;
|
||||||
import net.osmand.plus.settings.bottomsheets.RecalculateRouteInDeviationBottomSheet;
|
import net.osmand.plus.settings.bottomsheets.RecalculateRouteInDeviationBottomSheet;
|
||||||
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
||||||
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
|
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
|
||||||
|
@ -54,6 +55,8 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
|
import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE;
|
||||||
|
import static net.osmand.plus.settings.backend.OsmandSettings.ROUTING_PREFERENCE_PREFIX;
|
||||||
|
import static net.osmand.router.GeneralRouter.USE_HEIGHT_OBSTACLES;
|
||||||
|
|
||||||
public class RouteParametersFragment extends BaseSettingsFragment implements OnPreferenceChanged {
|
public class RouteParametersFragment extends BaseSettingsFragment implements OnPreferenceChanged {
|
||||||
|
|
||||||
|
@ -63,7 +66,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
private static final String PREFER_ROUTING_PARAMETER_PREFIX = "prefer_";
|
private static final String PREFER_ROUTING_PARAMETER_PREFIX = "prefer_";
|
||||||
private static final String ROUTE_PARAMETERS_INFO = "route_parameters_info";
|
private static final String ROUTE_PARAMETERS_INFO = "route_parameters_info";
|
||||||
private static final String ROUTE_PARAMETERS_IMAGE = "route_parameters_image";
|
private static final String ROUTE_PARAMETERS_IMAGE = "route_parameters_image";
|
||||||
private static final String RELIEF_SMOOTHNESS_FACTOR = "relief_smoothness_factor";
|
public static final String RELIEF_SMOOTHNESS_FACTOR = "relief_smoothness_factor";
|
||||||
private static final String ROUTING_SHORT_WAY = "prouting_short_way";
|
private static final String ROUTING_SHORT_WAY = "prouting_short_way";
|
||||||
private static final String ROUTING_RECALC_DISTANCE = "routing_recalc_distance";
|
private static final String ROUTING_RECALC_DISTANCE = "routing_recalc_distance";
|
||||||
private static final String ROUTING_RECALC_WRONG_DIRECTION = "disable_wrong_direction_recalc";
|
private static final String ROUTING_RECALC_WRONG_DIRECTION = "disable_wrong_direction_recalc";
|
||||||
|
@ -87,13 +90,13 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
booleanRoutingPrefListener = new StateChangedListener<Boolean>() {
|
booleanRoutingPrefListener = new StateChangedListener<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(Boolean change) {
|
public void stateChanged(Boolean change) {
|
||||||
recalculateRoute();
|
recalculateRoute(app, getSelectedAppMode());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
customRoutingPrefListener = new StateChangedListener<String>() {
|
customRoutingPrefListener = new StateChangedListener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(String change) {
|
public void stateChanged(String change) {
|
||||||
recalculateRoute();
|
recalculateRoute(app, getSelectedAppMode());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -275,12 +278,6 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
MultiSelectBooleanPreference preferRouting = createRoutingBooleanMultiSelectPref(PREFER_ROUTING_PARAMETER_PREFIX, title, "", preferParameters);
|
MultiSelectBooleanPreference preferRouting = createRoutingBooleanMultiSelectPref(PREFER_ROUTING_PARAMETER_PREFIX, title, "", preferParameters);
|
||||||
screen.addPreference(preferRouting);
|
screen.addPreference(preferRouting);
|
||||||
}
|
}
|
||||||
if (reliefFactorParameters.size() > 0) {
|
|
||||||
ListPreferenceEx reliefFactorRouting = createRoutingBooleanListPreference(RELIEF_SMOOTHNESS_FACTOR, reliefFactorParameters);
|
|
||||||
reliefFactorRouting.setDescription(R.string.relief_smoothness_factor_descr);
|
|
||||||
|
|
||||||
screen.addPreference(reliefFactorRouting);
|
|
||||||
}
|
|
||||||
for (RoutingParameter p : otherRoutingParameters) {
|
for (RoutingParameter p : otherRoutingParameters) {
|
||||||
String title = AndroidUtils.getRoutingStringPropertyName(app, p.getId(), p.getName());
|
String title = AndroidUtils.getRoutingStringPropertyName(app, p.getId(), p.getName());
|
||||||
String description = AndroidUtils.getRoutingStringPropertyDescription(app, p.getId(), p.getDescription());
|
String description = AndroidUtils.getRoutingStringPropertyDescription(app, p.getId(), p.getDescription());
|
||||||
|
@ -390,6 +387,12 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
if (fragmentManager != null) {
|
if (fragmentManager != null) {
|
||||||
RecalculateRouteInDeviationBottomSheet.showInstance(getFragmentManager(), preference.getKey(), this, false, getSelectedAppMode());
|
RecalculateRouteInDeviationBottomSheet.showInstance(getFragmentManager(), preference.getKey(), this, false, getSelectedAppMode());
|
||||||
}
|
}
|
||||||
|
} else if (!reliefFactorParameters.isEmpty() && preference.getKey().equals(ROUTING_PREFERENCE_PREFIX + USE_HEIGHT_OBSTACLES)) {
|
||||||
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
|
if (fragmentManager != null) {
|
||||||
|
ApplicationMode appMode = getSelectedAppMode();
|
||||||
|
ElevationDateBottomSheet.showInstance(fragmentManager, appMode, this, false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
super.onDisplayPreferenceDialog(preference);
|
super.onDisplayPreferenceDialog(preference);
|
||||||
}
|
}
|
||||||
|
@ -531,14 +534,8 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
@Override
|
@Override
|
||||||
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
|
||||||
if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) {
|
if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) {
|
||||||
ApplicationMode appMode = getSelectedAppMode();
|
|
||||||
String selectedParameterId = (String) newValue;
|
|
||||||
List<RoutingParameter> routingParameters = DRIVING_STYLE.equals(prefId) ? drivingStyleParameters : reliefFactorParameters;
|
List<RoutingParameter> routingParameters = DRIVING_STYLE.equals(prefId) ? drivingStyleParameters : reliefFactorParameters;
|
||||||
for (RoutingParameter p : routingParameters) {
|
updateSelectedParameters(app, getSelectedAppMode(), routingParameters, (String) newValue);
|
||||||
String parameterId = p.getId();
|
|
||||||
setRoutingParameterSelected(settings, appMode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
|
|
||||||
}
|
|
||||||
recalculateRoute();
|
|
||||||
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
|
} else if (ROUTING_SHORT_WAY.equals(prefId) && newValue instanceof Boolean) {
|
||||||
applyPreference(ROUTING_SHORT_WAY, applyToAllProfiles, newValue);
|
applyPreference(ROUTING_SHORT_WAY, applyToAllProfiles, newValue);
|
||||||
applyPreference(settings.FAST_ROUTE_MODE.getId(), applyToAllProfiles, !(Boolean) newValue);
|
applyPreference(settings.FAST_ROUTE_MODE.getId(), applyToAllProfiles, !(Boolean) newValue);
|
||||||
|
@ -565,7 +562,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
@Override
|
@Override
|
||||||
public void onPreferenceChanged(String prefId) {
|
public void onPreferenceChanged(String prefId) {
|
||||||
if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) {
|
if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) {
|
||||||
recalculateRoute();
|
recalculateRoute(app, getSelectedAppMode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -629,9 +626,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
return multiSelectPref;
|
return multiSelectPref;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recalculateRoute() {
|
private static void recalculateRoute(OsmandApplication app, ApplicationMode mode) {
|
||||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
RoutingHelper routingHelper = app.getRoutingHelper();
|
||||||
if (getSelectedAppMode().equals(routingHelper.getAppMode())
|
if (mode.equals(routingHelper.getAppMode())
|
||||||
&& (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) {
|
&& (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())) {
|
||||||
routingHelper.recalculateRouteDueToSettingsChange();
|
routingHelper.recalculateRouteDueToSettingsChange();
|
||||||
}
|
}
|
||||||
|
@ -645,11 +642,11 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
otherRoutingParameters.clear();
|
otherRoutingParameters.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRoutingParameterTitle(Context context, RoutingParameter parameter) {
|
public static String getRoutingParameterTitle(Context context, RoutingParameter parameter) {
|
||||||
return AndroidUtils.getRoutingStringPropertyName(context, parameter.getId(), parameter.getName());
|
return AndroidUtils.getRoutingStringPropertyName(context, parameter.getId(), parameter.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode mode, RoutingParameter parameter) {
|
public static boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode mode, RoutingParameter parameter) {
|
||||||
CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
|
CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
|
||||||
if (mode != null) {
|
if (mode != null) {
|
||||||
return property.getModeValue(mode);
|
return property.getModeValue(mode);
|
||||||
|
@ -658,8 +655,17 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode mode,
|
public static void updateSelectedParameters(OsmandApplication app, ApplicationMode mode,
|
||||||
String parameterId, boolean defaultBoolean, boolean isChecked) {
|
List<RoutingParameter> parameters, String selectedParameterId) {
|
||||||
|
for (RoutingParameter p : parameters) {
|
||||||
|
String parameterId = p.getId();
|
||||||
|
setRoutingParameterSelected(app.getSettings(), mode, parameterId, p.getDefaultBoolean(), parameterId.equals(selectedParameterId));
|
||||||
|
}
|
||||||
|
recalculateRoute(app, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode mode,
|
||||||
|
String parameterId, boolean defaultBoolean, boolean isChecked) {
|
||||||
CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(parameterId, defaultBoolean);
|
CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(parameterId, defaultBoolean);
|
||||||
if (mode != null) {
|
if (mode != null) {
|
||||||
property.setModeValue(mode, isChecked);
|
property.setModeValue(mode, isChecked);
|
||||||
|
@ -678,9 +684,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
Drawable disabled = getContentIcon(R.drawable.ic_action_avoid_motorways);
|
Drawable disabled = getContentIcon(R.drawable.ic_action_avoid_motorways);
|
||||||
Drawable enabled = getActiveIcon(R.drawable.ic_action_motorways);
|
Drawable enabled = getActiveIcon(R.drawable.ic_action_motorways);
|
||||||
return getPersistentPrefIcon(enabled, disabled);
|
return getPersistentPrefIcon(enabled, disabled);
|
||||||
case GeneralRouter.USE_HEIGHT_OBSTACLES:
|
case USE_HEIGHT_OBSTACLES:
|
||||||
case RELIEF_SMOOTHNESS_FACTOR:
|
case RELIEF_SMOOTHNESS_FACTOR:
|
||||||
return getPersistentPrefIcon(R.drawable.ic_action_elevation);
|
return getPersistentPrefIcon(R.drawable.ic_action_altitude_average);
|
||||||
case AVOID_ROUTING_PARAMETER_PREFIX:
|
case AVOID_ROUTING_PARAMETER_PREFIX:
|
||||||
return getPersistentPrefIcon(R.drawable.ic_action_alert);
|
return getPersistentPrefIcon(R.drawable.ic_action_alert);
|
||||||
case DRIVING_STYLE:
|
case DRIVING_STYLE:
|
||||||
|
|
Loading…
Reference in a new issue