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