Fix logic
This commit is contained in:
parent
a3d499b8d1
commit
1da3c93e5c
5 changed files with 50 additions and 36 deletions
|
@ -17,6 +17,7 @@ public class RouteLineDrawInfo {
|
||||||
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 APP_MODE_KEY = "app_mode_key";
|
||||||
|
|
||||||
// parameters to save
|
// parameters to save
|
||||||
@ColorInt
|
@ColorInt
|
||||||
|
@ -30,6 +31,7 @@ public class RouteLineDrawInfo {
|
||||||
private int centerX;
|
private int centerX;
|
||||||
private int centerY;
|
private int centerY;
|
||||||
private int screenHeight;
|
private int screenHeight;
|
||||||
|
private String appModeKey;
|
||||||
|
|
||||||
public RouteLineDrawInfo(@Nullable @ColorInt Integer color,
|
public RouteLineDrawInfo(@Nullable @ColorInt Integer color,
|
||||||
@Nullable String width) {
|
@Nullable String width) {
|
||||||
|
@ -49,16 +51,7 @@ public class RouteLineDrawInfo {
|
||||||
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.appModeKey = existed.appModeKey;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Integer getColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(@Nullable Integer color) {
|
public void setColor(@Nullable Integer color) {
|
||||||
|
@ -89,6 +82,20 @@ public class RouteLineDrawInfo {
|
||||||
this.screenHeight = screenHeight;
|
this.screenHeight = screenHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAppModeKey(@Nullable String appModeKey) {
|
||||||
|
this.appModeKey = appModeKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Integer getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
public int getIconId() {
|
public int getIconId() {
|
||||||
return iconId;
|
return iconId;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +117,11 @@ public class RouteLineDrawInfo {
|
||||||
return screenHeight;
|
return screenHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getAppModeKey() {
|
||||||
|
return appModeKey;
|
||||||
|
}
|
||||||
|
|
||||||
private void readBundle(@NonNull Bundle bundle) {
|
private void readBundle(@NonNull Bundle bundle) {
|
||||||
color = bundle.getInt(LINE_COLOR);
|
color = bundle.getInt(LINE_COLOR);
|
||||||
width = bundle.getString(LINE_WIDTH);
|
width = bundle.getString(LINE_WIDTH);
|
||||||
|
@ -118,6 +130,7 @@ 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);
|
||||||
|
appModeKey = bundle.getString(APP_MODE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveToBundle(@NonNull Bundle bundle) {
|
public void saveToBundle(@NonNull Bundle bundle) {
|
||||||
|
@ -132,6 +145,7 @@ public class RouteLineDrawInfo {
|
||||||
bundle.putInt(CENTER_X, (int) centerX);
|
bundle.putInt(CENTER_X, (int) centerX);
|
||||||
bundle.putInt(CENTER_Y, (int) centerY);
|
bundle.putInt(CENTER_Y, (int) centerY);
|
||||||
bundle.putInt(SCREEN_HEIGHT, screenHeight);
|
bundle.putInt(SCREEN_HEIGHT, screenHeight);
|
||||||
|
bundle.putString(APP_MODE_KEY, appModeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -47,7 +47,6 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
|
||||||
private static final int NIGHT_TITLE_ID = R.string.night;
|
private static final int NIGHT_TITLE_ID = R.string.night;
|
||||||
|
|
||||||
private final Fragment targetFragment;
|
private final Fragment targetFragment;
|
||||||
private ApplicationMode appMode;
|
|
||||||
|
|
||||||
private ColorsCard colorsCard;
|
private ColorsCard colorsCard;
|
||||||
private ColorTypeAdapter colorAdapter;
|
private ColorTypeAdapter colorAdapter;
|
||||||
|
@ -78,13 +77,11 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
|
||||||
public RouteLineColorCard(@NonNull MapActivity mapActivity,
|
public RouteLineColorCard(@NonNull MapActivity mapActivity,
|
||||||
@NonNull Fragment targetFragment,
|
@NonNull Fragment targetFragment,
|
||||||
@NonNull RouteLineDrawInfo routeLineDrawInfo,
|
@NonNull RouteLineDrawInfo routeLineDrawInfo,
|
||||||
@NonNull ApplicationMode appMode,
|
|
||||||
@NonNull DayNightMode initMapTheme,
|
@NonNull DayNightMode initMapTheme,
|
||||||
@NonNull DayNightMode selectedMapTheme) {
|
@NonNull DayNightMode selectedMapTheme) {
|
||||||
super(mapActivity);
|
super(mapActivity);
|
||||||
this.targetFragment = targetFragment;
|
this.targetFragment = targetFragment;
|
||||||
this.routeLineDrawInfo = routeLineDrawInfo;
|
this.routeLineDrawInfo = routeLineDrawInfo;
|
||||||
this.appMode = appMode;
|
|
||||||
this.initMapTheme = initMapTheme;
|
this.initMapTheme = initMapTheme;
|
||||||
this.selectedMapTheme = selectedMapTheme;
|
this.selectedMapTheme = selectedMapTheme;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +176,7 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
|
||||||
selectedColor = colors.get(0);
|
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, appMode);
|
colorsCard = new ColorsCard(mapActivity, selectedColor, targetFragment, colors, preference, null);
|
||||||
colorsCard.setListener(this);
|
colorsCard.setListener(this);
|
||||||
container.addView(colorsCard.build(mapActivity));
|
container.addView(colorsCard.build(mapActivity));
|
||||||
}
|
}
|
||||||
|
|
|
@ -730,7 +730,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
|
||||||
private void updateRouteLinePreference() {
|
private void updateRouteLinePreference() {
|
||||||
Preference preference = findPreference(CUSTOMIZE_ROUTE_LINE);
|
Preference preference = findPreference(CUSTOMIZE_ROUTE_LINE);
|
||||||
if (preference != null) {
|
if (preference != null) {
|
||||||
boolean isDefaultProfile = getSelectedAppMode().equals(ApplicationMode.DEFAULT);
|
boolean isDefaultProfile = getSelectedAppMode().equals(ApplicationMode.DEFAULT) && !isNewProfile;
|
||||||
boolean isPublicTransport = PUBLIC_TRANSPORT_KEY.equals(changedProfile.routingProfile);
|
boolean isPublicTransport = PUBLIC_TRANSPORT_KEY.equals(changedProfile.routingProfile);
|
||||||
preference.setVisible(!isDefaultProfile && !isPublicTransport);
|
preference.setVisible(!isDefaultProfile && !isPublicTransport);
|
||||||
preference.setIcon(getIcon(R.drawable.ic_action_route_distance, getActiveColorRes()));
|
preference.setIcon(getIcon(R.drawable.ic_action_route_distance, getActiveColorRes()));
|
||||||
|
@ -995,12 +995,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
|
||||||
String prefId = preference.getKey();
|
String prefId = preference.getKey();
|
||||||
if (CUSTOMIZE_ROUTE_LINE.equals(prefId)) {
|
if (CUSTOMIZE_ROUTE_LINE.equals(prefId)) {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
ApplicationMode appMode = getSelectedAppMode();
|
if (mapActivity != null) {
|
||||||
if (mapActivity != null && appMode != null) {
|
|
||||||
RouteLineDrawInfo drawInfo = changedProfile.routeLineDrawInfo;
|
RouteLineDrawInfo drawInfo = changedProfile.routeLineDrawInfo;
|
||||||
drawInfo.setIconId(changedProfile.navigationIcon.getIconId());
|
drawInfo.setIconId(changedProfile.navigationIcon.getIconId());
|
||||||
drawInfo.setIconColor(changedProfile.getActualColor());
|
drawInfo.setIconColor(changedProfile.getActualColor());
|
||||||
RouteLineAppearanceFragment.showInstance(mapActivity, drawInfo, appMode, this);
|
drawInfo.setAppModeKey(profile.stringKey);
|
||||||
|
RouteLineAppearanceFragment.showInstance(mapActivity, drawInfo, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onPreferenceClick(preference);
|
return super.onPreferenceClick(preference);
|
||||||
|
|
|
@ -43,8 +43,6 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
|
||||||
private static final String INIT_MAP_THEME = "init_map_theme";
|
private static final String INIT_MAP_THEME = "init_map_theme";
|
||||||
private static final String SELECTED_MAP_THEME = "selected_map_theme";
|
private static final String SELECTED_MAP_THEME = "selected_map_theme";
|
||||||
|
|
||||||
private ApplicationMode appMode;
|
|
||||||
|
|
||||||
private RouteLineDrawInfo routeLineDrawInfo;
|
private RouteLineDrawInfo routeLineDrawInfo;
|
||||||
|
|
||||||
private int toolbarHeightPx;
|
private int toolbarHeightPx;
|
||||||
|
@ -164,7 +162,7 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
|
||||||
MapActivity mapActivity = requireMapActivity();
|
MapActivity mapActivity = requireMapActivity();
|
||||||
ViewGroup cardsContainer = getCardsContainer();
|
ViewGroup cardsContainer = getCardsContainer();
|
||||||
|
|
||||||
colorCard = new RouteLineColorCard(mapActivity, this, routeLineDrawInfo, appMode, initMapTheme, selectedMapTheme);
|
colorCard = new RouteLineColorCard(mapActivity, this, routeLineDrawInfo, initMapTheme, selectedMapTheme);
|
||||||
cardsContainer.addView(colorCard.build(mapActivity));
|
cardsContainer.addView(colorCard.build(mapActivity));
|
||||||
|
|
||||||
widthCard = new RouteLineWidthCard(mapActivity, routeLineDrawInfo, createScrollListener());
|
widthCard = new RouteLineWidthCard(mapActivity, routeLineDrawInfo, createScrollListener());
|
||||||
|
@ -392,14 +390,12 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
|
||||||
|
|
||||||
public static boolean showInstance(@NonNull MapActivity mapActivity,
|
public static boolean showInstance(@NonNull MapActivity mapActivity,
|
||||||
@NonNull RouteLineDrawInfo drawInfo,
|
@NonNull RouteLineDrawInfo drawInfo,
|
||||||
@NonNull ApplicationMode appMode,
|
|
||||||
@NonNull Fragment target) {
|
@NonNull Fragment target) {
|
||||||
try {
|
try {
|
||||||
RouteLineAppearanceFragment fragment = new RouteLineAppearanceFragment();
|
RouteLineAppearanceFragment fragment = new RouteLineAppearanceFragment();
|
||||||
fragment.setRetainInstance(true);
|
fragment.setRetainInstance(true);
|
||||||
fragment.setTargetFragment(target, 0);
|
fragment.setTargetFragment(target, 0);
|
||||||
fragment.routeLineDrawInfo = new RouteLineDrawInfo(drawInfo);
|
fragment.routeLineDrawInfo = new RouteLineDrawInfo(drawInfo);
|
||||||
fragment.appMode = appMode;
|
|
||||||
|
|
||||||
mapActivity.getSupportFragmentManager()
|
mapActivity.getSupportFragmentManager()
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
|
|
|
@ -276,7 +276,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
||||||
|
|
||||||
private void updateRouteLineAppearance(RotatedTileBox tileBox, boolean defaultPaintUpdated, boolean night) {
|
private void updateRouteLineAppearance(RotatedTileBox tileBox, boolean defaultPaintUpdated, boolean night) {
|
||||||
OsmandSettings settings = view.getApplication().getSettings();
|
OsmandSettings settings = view.getApplication().getSettings();
|
||||||
ApplicationMode appMode = settings.getApplicationMode();
|
ApplicationMode appMode = getApplicationMode();
|
||||||
|
|
||||||
int color = getRouteLineColor(settings, appMode, defaultPaintUpdated);
|
int color = getRouteLineColor(settings, appMode, defaultPaintUpdated);
|
||||||
attrs.paint.setColor(color);
|
attrs.paint.setColor(color);
|
||||||
|
@ -293,15 +293,12 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
||||||
defaultRouteLineColor = attrs.paint.getColor();
|
defaultRouteLineColor = attrs.paint.getColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
int storedValue = settings.ROUTE_LINE_COLOR.getModeValue(appMode);
|
Integer color;
|
||||||
Integer fromSettings = storedValue != 0 ? storedValue : null;
|
|
||||||
|
|
||||||
Integer color = null;
|
|
||||||
if (routeLineDrawInfo != null) {
|
if (routeLineDrawInfo != null) {
|
||||||
color = routeLineDrawInfo.getColor();
|
color = routeLineDrawInfo.getColor();
|
||||||
}
|
} else {
|
||||||
if (color == null) {
|
int storedValue = settings.ROUTE_LINE_COLOR.getModeValue(appMode);
|
||||||
color = fromSettings;
|
color = storedValue != 0 ? storedValue : null;
|
||||||
}
|
}
|
||||||
return color != null ? color : defaultRouteLineColor;
|
return color != null ? color : defaultRouteLineColor;
|
||||||
}
|
}
|
||||||
|
@ -314,13 +311,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
||||||
defaultRouteLineWidth = attrs.paint.getStrokeWidth();
|
defaultRouteLineWidth = attrs.paint.getStrokeWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
String fromSettings = settings.ROUTE_LINE_WIDTH.getModeValue(appMode);
|
String widthKey;
|
||||||
String widthKey = null;
|
|
||||||
if (routeLineDrawInfo != null) {
|
if (routeLineDrawInfo != null) {
|
||||||
widthKey = routeLineDrawInfo.getWidth();
|
widthKey = routeLineDrawInfo.getWidth();
|
||||||
}
|
} else {
|
||||||
if (widthKey == null) {
|
widthKey = settings.ROUTE_LINE_WIDTH.getModeValue(appMode);
|
||||||
widthKey = fromSettings;
|
|
||||||
}
|
}
|
||||||
return widthKey != null ? getWidthByKey(tileBox, widthKey) : defaultRouteLineWidth;
|
return widthKey != null ? getWidthByKey(tileBox, widthKey) : defaultRouteLineWidth;
|
||||||
}
|
}
|
||||||
|
@ -352,6 +347,18 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
|
||||||
return DEFAULT_WIDTH_MULTIPLIER * view.getDensity();
|
return DEFAULT_WIDTH_MULTIPLIER * view.getDensity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private ApplicationMode getApplicationMode() {
|
||||||
|
ApplicationMode appMode = null;
|
||||||
|
if (routeLineDrawInfo != null) {
|
||||||
|
String modeKey = routeLineDrawInfo.getAppModeKey();
|
||||||
|
if (modeKey != null) {
|
||||||
|
appMode = ApplicationMode.valueOfStringKey(modeKey, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return appMode != null ? appMode : helper.getAppMode();
|
||||||
|
}
|
||||||
|
|
||||||
private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
|
private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
|
||||||
QuadRect latLonBounds = tileBox.getLatLonBounds();
|
QuadRect latLonBounds = tileBox.getLatLonBounds();
|
||||||
List<LatLon> xAxisPoints = trackChartPoints.getXAxisPoints();
|
List<LatLon> xAxisPoints = trackChartPoints.getXAxisPoints();
|
||||||
|
|
Loading…
Reference in a new issue