Merge pull request #11254 from osmandapp/RouteLine
Use different colors for route line appearance in day and night map themes
This commit is contained in:
commit
de386f5286
8 changed files with 138 additions and 54 deletions
|
@ -10,17 +10,20 @@ import net.osmand.util.Algorithms;
|
|||
|
||||
public class RouteLineDrawInfo {
|
||||
|
||||
private static final String LINE_COLOR = "line_color";
|
||||
private static final String LINE_COLOR_DAY = "line_color_day";
|
||||
private static final String LINE_COLOR_NIGHT = "line_color_night";
|
||||
private static final String LINE_WIDTH = "line_width";
|
||||
private static final String NAVIGATION_ICON_ID = "navigation_icon_id";
|
||||
private static final String NAVIGATION_ICON_COLOR = "navigation_icon_color";
|
||||
private static final String CENTER_X = "center_x";
|
||||
private static final String CENTER_Y = "center_y";
|
||||
private static final String SCREEN_HEIGHT = "screen_height";
|
||||
private static final String USE_DEFAULT_COLOR = "use_default_color";
|
||||
|
||||
// parameters to save
|
||||
@ColorInt
|
||||
private Integer color;
|
||||
private Integer colorDay;
|
||||
private Integer colorNight;
|
||||
private String width;
|
||||
|
||||
// temporally parameters to show in preview
|
||||
|
@ -30,10 +33,13 @@ public class RouteLineDrawInfo {
|
|||
private int centerX;
|
||||
private int centerY;
|
||||
private int screenHeight;
|
||||
private boolean useDefaultColor;
|
||||
|
||||
public RouteLineDrawInfo(@Nullable @ColorInt Integer color,
|
||||
public RouteLineDrawInfo(@Nullable @ColorInt Integer colorDay,
|
||||
@Nullable @ColorInt Integer colorNight,
|
||||
@Nullable String width) {
|
||||
this.color = color;
|
||||
this.colorDay = colorDay;
|
||||
this.colorNight = colorNight;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
|
@ -42,17 +48,27 @@ public class RouteLineDrawInfo {
|
|||
}
|
||||
|
||||
public RouteLineDrawInfo(@NonNull RouteLineDrawInfo existed) {
|
||||
this.color = existed.color;
|
||||
this.colorDay = existed.colorDay;
|
||||
this.colorNight = existed.colorNight;
|
||||
this.width = existed.width;
|
||||
this.iconId = existed.iconId;
|
||||
this.iconColor = existed.iconColor;
|
||||
this.centerX = existed.centerX;
|
||||
this.centerY = existed.centerY;
|
||||
this.screenHeight = existed.screenHeight;
|
||||
this.useDefaultColor = existed.useDefaultColor;
|
||||
}
|
||||
|
||||
public void setColor(@Nullable Integer color) {
|
||||
this.color = color;
|
||||
public void setColor(@ColorInt int color, boolean nightMode) {
|
||||
if (nightMode) {
|
||||
colorNight = color;
|
||||
} else {
|
||||
colorDay = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void setUseDefaultColor(boolean useDefaultColor) {
|
||||
this.useDefaultColor = useDefaultColor;
|
||||
}
|
||||
|
||||
public void setWidth(@Nullable String width) {
|
||||
|
@ -80,8 +96,16 @@ public class RouteLineDrawInfo {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getColor() {
|
||||
return color;
|
||||
public Integer getColor(boolean nightMode) {
|
||||
if (!useDefaultColor) {
|
||||
return getColorIgnoreDefault(nightMode);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getColorIgnoreDefault(boolean nightMode) {
|
||||
return nightMode ? colorNight : colorDay;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -111,8 +135,11 @@ public class RouteLineDrawInfo {
|
|||
}
|
||||
|
||||
private void readBundle(@NonNull Bundle bundle) {
|
||||
if (bundle.containsKey(LINE_COLOR)) {
|
||||
color = bundle.getInt(LINE_COLOR);
|
||||
if (bundle.containsKey(LINE_COLOR_DAY)) {
|
||||
colorDay = bundle.getInt(LINE_COLOR_DAY);
|
||||
}
|
||||
if (bundle.containsKey(LINE_COLOR_NIGHT)) {
|
||||
colorNight = bundle.getInt(LINE_COLOR_NIGHT);
|
||||
}
|
||||
width = bundle.getString(LINE_WIDTH);
|
||||
iconId = bundle.getInt(NAVIGATION_ICON_ID);
|
||||
|
@ -120,11 +147,15 @@ public class RouteLineDrawInfo {
|
|||
centerX = bundle.getInt(CENTER_X);
|
||||
centerY = bundle.getInt(CENTER_Y);
|
||||
screenHeight = bundle.getInt(SCREEN_HEIGHT);
|
||||
useDefaultColor = bundle.getBoolean(USE_DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
public void saveToBundle(@NonNull Bundle bundle) {
|
||||
if (color != null) {
|
||||
bundle.putInt(LINE_COLOR, color);
|
||||
if (colorDay != null) {
|
||||
bundle.putInt(LINE_COLOR_DAY, colorDay);
|
||||
}
|
||||
if (colorNight != null) {
|
||||
bundle.putInt(LINE_COLOR_NIGHT, colorNight);
|
||||
}
|
||||
if (width != null) {
|
||||
bundle.putString(LINE_WIDTH, width);
|
||||
|
@ -134,6 +165,7 @@ public class RouteLineDrawInfo {
|
|||
bundle.putInt(CENTER_X, centerX);
|
||||
bundle.putInt(CENTER_Y, centerY);
|
||||
bundle.putInt(SCREEN_HEIGHT, screenHeight);
|
||||
bundle.putBoolean(USE_DEFAULT_COLOR, useDefaultColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,13 +175,15 @@ public class RouteLineDrawInfo {
|
|||
|
||||
RouteLineDrawInfo that = (RouteLineDrawInfo) o;
|
||||
|
||||
if (!Algorithms.objectEquals(getColor(), that.getColor())) return false;
|
||||
return Algorithms.objectEquals(getWidth(), that.getWidth());
|
||||
if (!Algorithms.objectEquals(colorDay, that.colorDay)) return false;
|
||||
if (!Algorithms.objectEquals(colorNight, that.colorNight)) return false;
|
||||
return Algorithms.objectEquals(width, that.width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = color != null ? color.hashCode() : 0;
|
||||
int result = colorDay != null ? colorDay.hashCode() : 0;
|
||||
result = 31 * result + (colorNight != null ? colorNight.hashCode() : 0);
|
||||
result = 31 * result + (width != null ? width.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
@ -22,7 +23,6 @@ import net.osmand.plus.UiUtilities;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.helpers.enums.DayNightMode;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
|
||||
import net.osmand.plus.routing.RouteLineDrawInfo;
|
||||
|
@ -110,7 +110,7 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
|
|||
}
|
||||
|
||||
private void initSelectedMode() {
|
||||
selectedMode = routeLineDrawInfo.getColor() == null ? ColorMode.DEFAULT : ColorMode.CUSTOM;
|
||||
selectedMode = getRouteLineColor() == null ? ColorMode.DEFAULT : ColorMode.CUSTOM;
|
||||
modeChanged();
|
||||
}
|
||||
|
||||
|
@ -118,13 +118,15 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
|
|||
if (selectedMode == ColorMode.DEFAULT) {
|
||||
themeToggleContainer.setVisibility(View.GONE);
|
||||
cardsContainer.setVisibility(View.GONE);
|
||||
routeLineDrawInfo.setUseDefaultColor(true);
|
||||
changeMapTheme(initMapTheme);
|
||||
} else {
|
||||
themeToggleContainer.setVisibility(View.VISIBLE);
|
||||
cardsContainer.setVisibility(View.VISIBLE);
|
||||
routeLineDrawInfo.setUseDefaultColor(false);
|
||||
changeMapTheme(isNightMap() ? DayNightMode.NIGHT : DayNightMode.DAY);
|
||||
}
|
||||
updateSelectedColor();
|
||||
updateColorItems();
|
||||
updateDescription();
|
||||
}
|
||||
|
||||
|
@ -156,6 +158,12 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
|
|||
if (targetFragment instanceof OnMapThemeUpdateListener) {
|
||||
((OnMapThemeUpdateListener) targetFragment).onMapThemeUpdated(mapTheme);
|
||||
}
|
||||
if (selectedMode == ColorMode.CUSTOM) {
|
||||
Integer color = getRouteLineColor();
|
||||
if (color != null) {
|
||||
colorsCard.setSelectedColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createColorSelector(ViewGroup container) {
|
||||
|
@ -165,14 +173,9 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
|
|||
for (int color : ColorDialogs.pallette) {
|
||||
colors.add(color);
|
||||
}
|
||||
Integer selectedColor = routeLineDrawInfo.getColor();
|
||||
if (selectedColor != null) {
|
||||
if (!ColorDialogs.isPaletteColor(selectedColor)) {
|
||||
colors.add(selectedColor);
|
||||
}
|
||||
} else {
|
||||
selectedColor = colors.get(0);
|
||||
}
|
||||
int selectedColorDay = getSelectedColorForTheme(colors, false);
|
||||
int selectedColorNight = getSelectedColorForTheme(colors, true);
|
||||
int selectedColor = isNightMap() ? selectedColorNight : selectedColorDay;
|
||||
ListStringPreference preference = app.getSettings().CUSTOM_ROUTE_LINE_COLORS;
|
||||
colorsCard = new ColorsCard(mapActivity, selectedColor, targetFragment, colors, preference, null);
|
||||
colorsCard.setListener(this);
|
||||
|
@ -180,26 +183,49 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
|
|||
}
|
||||
}
|
||||
|
||||
private int getSelectedColorForTheme(List<Integer> colors, boolean nightMode) {
|
||||
Integer color = routeLineDrawInfo.getColorIgnoreDefault(nightMode);
|
||||
if (color != null) {
|
||||
if (!ColorDialogs.isPaletteColor(color)) {
|
||||
colors.add(color);
|
||||
}
|
||||
} else {
|
||||
color = colors.get(0);
|
||||
routeLineDrawInfo.setUseDefaultColor(true);
|
||||
routeLineDrawInfo.setColor(color, nightMode);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorSelected(Integer prevColor, int newColor) {
|
||||
colorsCard.onColorSelected(prevColor, newColor);
|
||||
updateSelectedColor();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Integer getRouteLineColor() {
|
||||
return routeLineDrawInfo.getColor(isNightMap());
|
||||
}
|
||||
|
||||
private void updateSelectedColor() {
|
||||
Integer color = selectedMode == ColorMode.CUSTOM ? colorsCard.getSelectedColor() : null;
|
||||
routeLineDrawInfo.setColor(color);
|
||||
updateColorName();
|
||||
int selectedColor = colorsCard.getSelectedColor();
|
||||
routeLineDrawInfo.setColor(selectedColor, isNightMap());
|
||||
updateColorItems();
|
||||
}
|
||||
|
||||
private void updateColorItems() {
|
||||
if (targetFragment instanceof OnSelectedColorChangeListener) {
|
||||
((OnSelectedColorChangeListener) targetFragment).onSelectedColorChanged();
|
||||
}
|
||||
updateColorName();
|
||||
}
|
||||
|
||||
private void updateColorName() {
|
||||
if (selectedMode == ColorMode.DEFAULT) {
|
||||
tvColorName.setText(app.getString(R.string.map_widget_renderer));
|
||||
} else if (routeLineDrawInfo.getColor() != null) {
|
||||
int colorNameId = ColorDialogs.getColorName(routeLineDrawInfo.getColor());
|
||||
} else if (getRouteLineColor() != null) {
|
||||
int colorNameId = ColorDialogs.getColorName(getRouteLineColor());
|
||||
tvColorName.setText(app.getString(colorNameId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.plus.routing.RouteLineDrawInfo;
|
||||
import net.osmand.plus.track.AppearanceViewHolder;
|
||||
|
@ -201,6 +200,10 @@ public class RouteLineWidthCard extends BaseCard {
|
|||
return WidthMode.DEFAULT;
|
||||
}
|
||||
|
||||
private boolean isNightMode() {
|
||||
return app.getDaynightHelper().isNightModeForMapControls();
|
||||
}
|
||||
|
||||
private class WidthAdapter extends RecyclerView.Adapter<AppearanceViewHolder> {
|
||||
|
||||
private final List<WidthMode> items = Arrays.asList(WidthMode.values());
|
||||
|
@ -268,13 +271,9 @@ public class RouteLineWidthCard extends BaseCard {
|
|||
}
|
||||
|
||||
private int getIconColor(@NonNull WidthMode mode, @ColorInt int defaultColor) {
|
||||
return mode.widthKey != null ? getRouteLineColor() : defaultColor;
|
||||
}
|
||||
|
||||
private int getRouteLineColor() {
|
||||
Integer color = routeLineDrawInfo.getColor();
|
||||
return color != null ? color :
|
||||
mapActivity.getMapLayers().getRouteLayer().getRouteLineColor(nightMode);
|
||||
return mode.widthKey != null ?
|
||||
mapActivity.getMapLayers().getRouteLayer().getRouteLineColor(isNightMode()) :
|
||||
defaultColor;
|
||||
}
|
||||
|
||||
private void updateButtonBg(AppearanceViewHolder holder, WidthMode item) {
|
||||
|
|
|
@ -2691,8 +2691,10 @@ public class OsmandSettings {
|
|||
|
||||
public final CommonPreference<Float> ROUTE_RECALCULATION_DISTANCE = new FloatPreference(this, "routing_recalc_distance", 0.f).makeProfile();
|
||||
public final CommonPreference<Float> ROUTE_STRAIGHT_ANGLE = new FloatPreference(this, "routing_straight_angle", 30.f).makeProfile();
|
||||
|
||||
public final ListStringPreference CUSTOM_ROUTE_LINE_COLORS = (ListStringPreference) new ListStringPreference(this, "custom_route_line_colors", null, ",").makeShared().makeGlobal();
|
||||
public final CommonPreference<Integer> ROUTE_LINE_COLOR = new IntPreference(this, "route_line_color", 0).makeProfile();
|
||||
public final CommonPreference<Integer> ROUTE_LINE_COLOR_DAY = new IntPreference(this, "route_line_color", 0).cache().makeProfile();
|
||||
public final CommonPreference<Integer> ROUTE_LINE_COLOR_NIGHT = new IntPreference(this, "route_line_color_night", 0).cache().makeProfile();
|
||||
public final CommonPreference<String> ROUTE_LINE_WIDTH = new StringPreference(this, "route_line_width", null).makeProfile();
|
||||
|
||||
public final OsmandPreference<Boolean> USE_OSM_LIVE_FOR_ROUTING = new BooleanPreference(this, "enable_osmc_routing", true).makeProfile();
|
||||
|
|
|
@ -1019,23 +1019,35 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
|
|||
}
|
||||
|
||||
private RouteLineDrawInfo createRouteLineDrawInfo(@NonNull ApplicationMode appMode) {
|
||||
int storedValue = settings.ROUTE_LINE_COLOR.getModeValue(appMode);
|
||||
Integer color = storedValue != 0 ? storedValue : null;
|
||||
Integer colorDay = getRouteLineColor(appMode, settings.ROUTE_LINE_COLOR_DAY);
|
||||
Integer colorNight = getRouteLineColor(appMode, settings.ROUTE_LINE_COLOR_NIGHT);
|
||||
String widthKey = settings.ROUTE_LINE_WIDTH.getModeValue(appMode);
|
||||
return new RouteLineDrawInfo(color, widthKey);
|
||||
return new RouteLineDrawInfo(colorDay, colorNight, widthKey);
|
||||
}
|
||||
|
||||
private Integer getRouteLineColor(@NonNull ApplicationMode appMode,
|
||||
@NonNull CommonPreference<Integer> preference) {
|
||||
int storedValue = preference.getModeValue(appMode);
|
||||
return storedValue != 0 ? storedValue : null;
|
||||
}
|
||||
|
||||
private void saveRouteLineAppearance(@NonNull ApplicationMode appMode,
|
||||
@NonNull RouteLineDrawInfo drawInfo) {
|
||||
Integer color = drawInfo.getColor();
|
||||
if (color != null) {
|
||||
settings.ROUTE_LINE_COLOR.setModeValue(appMode, color);
|
||||
} else {
|
||||
settings.ROUTE_LINE_COLOR.resetModeToDefault(appMode);
|
||||
}
|
||||
saveRouteLineColor(appMode, settings.ROUTE_LINE_COLOR_DAY, drawInfo.getColor(false));
|
||||
saveRouteLineColor(appMode, settings.ROUTE_LINE_COLOR_NIGHT, drawInfo.getColor(true));
|
||||
settings.ROUTE_LINE_WIDTH.setModeValue(appMode, drawInfo.getWidth());
|
||||
}
|
||||
|
||||
private void saveRouteLineColor(@NonNull ApplicationMode appMode,
|
||||
@NonNull CommonPreference<Integer> preference,
|
||||
@Nullable @ColorInt Integer color) {
|
||||
if (color != null) {
|
||||
preference.setModeValue(appMode, color);
|
||||
} else {
|
||||
preference.resetModeToDefault(appMode);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable String appMode, boolean imported) {
|
||||
try {
|
||||
Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName);
|
||||
|
|
|
@ -385,6 +385,10 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
|
|||
|
||||
@Override
|
||||
public void onSelectedColorChanged() {
|
||||
updateColorItems();
|
||||
}
|
||||
|
||||
private void updateColorItems() {
|
||||
if (widthCard != null) {
|
||||
widthCard.updateItems();
|
||||
}
|
||||
|
@ -415,6 +419,7 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
|
|||
@Override
|
||||
public void onMapThemeUpdated(@NonNull DayNightMode mapTheme) {
|
||||
changeMapTheme(mapTheme);
|
||||
updateColorItems();
|
||||
}
|
||||
|
||||
private void changeMapTheme(@NonNull DayNightMode mapTheme) {
|
||||
|
|
|
@ -72,6 +72,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
|
|||
|
||||
public void setSelectedColor(int selectedColor) {
|
||||
this.selectedColor = selectedColor;
|
||||
updateContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -42,6 +42,7 @@ import net.osmand.plus.routing.RouteLineDrawInfo;
|
|||
import net.osmand.plus.routing.RouteService;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.routing.TransportRoutingHelper;
|
||||
import net.osmand.plus.settings.backend.CommonPreference;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.layers.geometry.PublicTransportGeometryWay;
|
||||
|
@ -315,14 +316,16 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
|||
QuadPoint c = tileBox.getCenterPixelPoint();
|
||||
|
||||
canvas.rotate(-angle, c.x, c.y);
|
||||
drawRouteLinePreview(canvas, tileBox, routeLineDrawInfo);
|
||||
drawRouteLinePreview(canvas, tileBox, settings, routeLineDrawInfo);
|
||||
canvas.rotate(angle, c.x, c.y);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawRouteLinePreview(Canvas canvas,
|
||||
RotatedTileBox tileBox,
|
||||
DrawSettings settings,
|
||||
RouteLineDrawInfo drawInfo) {
|
||||
updateAttrs(settings, tileBox);
|
||||
paintRouteLinePreview.setColor(getRouteLineColor(nightMode));
|
||||
paintRouteLinePreview.setStrokeWidth(getRouteLineWidth(tileBox));
|
||||
|
||||
|
@ -417,12 +420,14 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
|||
public int getRouteLineColor(boolean night) {
|
||||
Integer color;
|
||||
if (routeLineDrawInfo != null) {
|
||||
color = routeLineDrawInfo.getColor();
|
||||
color = routeLineDrawInfo.getColor(night);
|
||||
} else {
|
||||
int storedValue = view.getSettings().ROUTE_LINE_COLOR.getModeValue(helper.getAppMode());
|
||||
CommonPreference<Integer> colorPreference = night ?
|
||||
view.getSettings().ROUTE_LINE_COLOR_NIGHT :
|
||||
view.getSettings().ROUTE_LINE_COLOR_DAY;
|
||||
int storedValue = colorPreference.getModeValue(helper.getAppMode());
|
||||
color = storedValue != 0 ? storedValue : null;
|
||||
}
|
||||
|
||||
if (color == null) {
|
||||
updateAttrs(new DrawSettings(night), view.getCurrentRotatedTileBox());
|
||||
color = attrs.paint.getColor();
|
||||
|
|
Loading…
Reference in a new issue