fixes p.2
This commit is contained in:
parent
b972dfb748
commit
e9cd09681e
3 changed files with 29 additions and 53 deletions
|
@ -59,8 +59,8 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
private static final String RELIEF_SMOOTHNESS_FACTOR = "relief_smoothness_factor";
|
||||
private static final String ROUTING_RECALC_DISTANCE= "routing_recalc_distance";
|
||||
|
||||
private static final float ROUTE_RECALC_DISTANCE_DISABLE = -1.0f;
|
||||
private static final float ROUTE_RECALC_DISTANCE_DEFAULT = 0.0f;
|
||||
public static final float DISABLE_MODE = -1.0f;
|
||||
public static final float DEFAULT_MODE = 0.0f;
|
||||
|
||||
private List<RoutingParameter> avoidParameters = new ArrayList<RoutingParameter>();
|
||||
private List<RoutingParameter> preferParameters = new ArrayList<RoutingParameter>();
|
||||
|
@ -70,7 +70,6 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
|
||||
private StateChangedListener<Boolean> booleanRoutingPrefListener;
|
||||
private StateChangedListener<String> customRoutingPrefListener;
|
||||
private StateChangedListener<Float> routeRecalculationDistanceListener;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -88,12 +87,6 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
recalculateRoute();
|
||||
}
|
||||
};
|
||||
routeRecalculationDistanceListener = new StateChangedListener<Float>() {
|
||||
@Override
|
||||
public void stateChanged(Float value) {
|
||||
updateRouteRecalcDistanceView();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -346,17 +339,17 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
R.string.route_recalculation_dist_title, R.layout.preference_with_descr_dialog_and_switch);
|
||||
switchPref.setIcon(getRoutingPrefIcon(ROUTING_RECALC_DISTANCE));
|
||||
screen.addPreference(switchPref);
|
||||
updateRouteRecalcDistanceView();
|
||||
updateRouteRecalcDistancePref();
|
||||
}
|
||||
|
||||
private void updateRouteRecalcDistanceView() {
|
||||
private void updateRouteRecalcDistancePref() {
|
||||
SwitchPreferenceEx switchPref = (SwitchPreferenceEx) findPreference(ROUTING_RECALC_DISTANCE);
|
||||
if (switchPref == null) {
|
||||
return;
|
||||
}
|
||||
ApplicationMode appMode = getSelectedAppMode();
|
||||
float allowedValue = settings.ROUTE_RECALCULATION_DISTANCE.getModeValue(appMode);
|
||||
boolean enabled = allowedValue != ROUTE_RECALC_DISTANCE_DISABLE;
|
||||
boolean enabled = allowedValue != DISABLE_MODE;
|
||||
if (allowedValue <= 0) {
|
||||
allowedValue = RoutingHelper.getDefaultAllowedDeviation(settings, appMode, RoutingHelper.getPosTolerance(0));
|
||||
}
|
||||
|
@ -389,7 +382,6 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
private void addRoutingPrefListeners() {
|
||||
settings.FAST_ROUTE_MODE.addListener(booleanRoutingPrefListener);
|
||||
settings.ENABLE_TIME_CONDITIONAL_ROUTING.addListener(booleanRoutingPrefListener);
|
||||
settings.ROUTE_RECALCULATION_DISTANCE.addListener(routeRecalculationDistanceListener);
|
||||
|
||||
for (RoutingParameter parameter : otherRoutingParameters) {
|
||||
if (parameter.getType() == RoutingParameterType.BOOLEAN) {
|
||||
|
@ -405,7 +397,6 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
private void removeRoutingPrefListeners() {
|
||||
settings.FAST_ROUTE_MODE.removeListener(booleanRoutingPrefListener);
|
||||
settings.ENABLE_TIME_CONDITIONAL_ROUTING.removeListener(booleanRoutingPrefListener);
|
||||
settings.ROUTE_RECALCULATION_DISTANCE.removeListener(routeRecalculationDistanceListener);
|
||||
|
||||
for (RoutingParameter parameter : otherRoutingParameters) {
|
||||
if (parameter.getType() == RoutingParameterType.BOOLEAN) {
|
||||
|
@ -437,9 +428,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
} else if (ROUTING_RECALC_DISTANCE.equals(key) && newValue instanceof Boolean) {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
settings.ROUTE_RECALCULATION_DISTANCE.setModeValue(getSelectedAppMode(),
|
||||
enabled ? ROUTE_RECALC_DISTANCE_DEFAULT : ROUTE_RECALC_DISTANCE_DISABLE);
|
||||
enabled ? DEFAULT_MODE : DISABLE_MODE);
|
||||
settings.DISABLE_OFFROUTE_RECALC.setModeValue(getSelectedAppMode(), !enabled);
|
||||
updateRouteRecalcDistanceView();
|
||||
updateRouteRecalcDistancePref();
|
||||
}
|
||||
|
||||
return super.onPreferenceChange(preference, newValue);
|
||||
|
@ -449,6 +440,8 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
public void onPreferenceChanged(String prefId) {
|
||||
if (AVOID_ROUTING_PARAMETER_PREFIX.equals(prefId) || PREFER_ROUTING_PARAMETER_PREFIX.equals(prefId)) {
|
||||
recalculateRoute();
|
||||
} else if (ROUTING_RECALC_DISTANCE.equals(prefId)) {
|
||||
updateRouteRecalcDistancePref();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,14 +109,14 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
|||
return R.string.shared_string_cancel;
|
||||
}
|
||||
|
||||
private View getCustomButtonView(boolean checked) {
|
||||
protected View getCustomButtonView(boolean checked) {
|
||||
View customView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_preference_switch, null);
|
||||
updateCustomButtonView(customView, checked);
|
||||
|
||||
return customView;
|
||||
}
|
||||
|
||||
private void updateCustomButtonView(View customView, boolean checked) {
|
||||
protected void updateCustomButtonView(View customView, boolean checked) {
|
||||
OsmandApplication app = requiredMyApplication();
|
||||
View buttonView = customView.findViewById(R.id.button_container);
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package net.osmand.plus.settings.bottomsheets;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
@ -32,12 +29,14 @@ import net.osmand.plus.routing.RoutingHelper;
|
|||
import net.osmand.plus.settings.OnPreferenceChanged;
|
||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||
|
||||
public class RecalculateRouteInDeviationBottomSheet extends BasePreferenceBottomSheet {
|
||||
import static net.osmand.plus.settings.RouteParametersFragment.DEFAULT_MODE;
|
||||
import static net.osmand.plus.settings.RouteParametersFragment.DISABLE_MODE;
|
||||
|
||||
public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBottomSheet {
|
||||
|
||||
public static final String TAG = RecalculateRouteInDeviationBottomSheet.class.getSimpleName();
|
||||
|
||||
private static final float DISABLE_MODE = -1.0f;
|
||||
private static final float DEFAULT_MODE = 0.0f;
|
||||
private static final String CURRENT_VALUE = "current_value";
|
||||
|
||||
private OsmandApplication app;
|
||||
private OsmandSettings settings;
|
||||
|
@ -66,6 +65,10 @@ public class RecalculateRouteInDeviationBottomSheet extends BasePreferenceBottom
|
|||
return;
|
||||
}
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_VALUE)) {
|
||||
currentValue = savedInstanceState.getFloat(CURRENT_VALUE);
|
||||
}
|
||||
|
||||
int contentPaddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||
int dialogContentMargin = app.getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
|
||||
|
||||
|
@ -101,7 +104,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BasePreferenceBottom
|
|||
.setCompoundButtonColorId(appModeColor)
|
||||
.setTitle(enabled ? on : off)
|
||||
.setTitleColorId(enabled ? activeColor : disabledColor)
|
||||
.setCustomView(getCustomCompoundButtonView(enabled))
|
||||
.setCustomView(getCustomButtonView(enabled))
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -151,6 +154,10 @@ public class RecalculateRouteInDeviationBottomSheet extends BasePreferenceBottom
|
|||
if (enabled && sliderPositionChanged) {
|
||||
preference.setModeValue(getAppMode(), currentValue);
|
||||
}
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof OnPreferenceChanged) {
|
||||
((OnPreferenceChanged) target).onPreferenceChanged(preference.getId());
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
@ -159,34 +166,10 @@ public class RecalculateRouteInDeviationBottomSheet extends BasePreferenceBottom
|
|||
return R.string.shared_string_apply;
|
||||
}
|
||||
|
||||
private View getCustomCompoundButtonView(boolean checked) {
|
||||
View customView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_item_preference_switch, null);
|
||||
updateCustomButtonView(customView, checked);
|
||||
|
||||
return customView;
|
||||
}
|
||||
|
||||
private void updateCustomButtonView(View customView, boolean checked) {
|
||||
View buttonView = customView.findViewById(R.id.button_container);
|
||||
|
||||
int colorRes = appMode.getIconColorInfo().getColor(nightMode);
|
||||
int color = checked ? getResolvedColor(colorRes) : AndroidUtils.getColorFromAttr(app, R.attr.divider_color_basic);
|
||||
int bgColor = UiUtilities.getColorWithAlpha(color, checked ? 0.1f : 0.5f);
|
||||
int selectedColor = UiUtilities.getColorWithAlpha(color, checked ? 0.3f : 0.5f);
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
int bgResId = R.drawable.rectangle_rounded_right;
|
||||
int selectableResId = R.drawable.ripple_rectangle_rounded_right;
|
||||
|
||||
Drawable bgDrawable = app.getUIUtilities().getPaintedIcon(bgResId, bgColor);
|
||||
Drawable selectable = app.getUIUtilities().getPaintedIcon(selectableResId, selectedColor);
|
||||
Drawable[] layers = {bgDrawable, selectable};
|
||||
AndroidUtils.setBackground(buttonView, new LayerDrawable(layers));
|
||||
} else {
|
||||
int bgResId = R.drawable.rectangle_rounded_right;
|
||||
Drawable bgDrawable = app.getUIUtilities().getPaintedIcon(bgResId, bgColor);
|
||||
AndroidUtils.setBackground(buttonView, bgDrawable);
|
||||
}
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putFloat(CURRENT_VALUE, currentValue);
|
||||
}
|
||||
|
||||
private void updateSliderView() {
|
||||
|
|
Loading…
Reference in a new issue