After code review fixes 3

This commit is contained in:
nazar-kutz 2021-03-24 01:35:29 +02:00
parent de93f862a7
commit 90ee2ba501
9 changed files with 69 additions and 108 deletions

View file

@ -289,9 +289,8 @@ public class RendererRegistry {
return renderers;
}
public static String getMapStyleName(@NonNull OsmandApplication app) {
RendererRegistry rr = app.getRendererRegistry();
RenderingRulesStorage storage = rr.getCurrentSelectedRenderer();
public String getSelectedRendererName() {
RenderingRulesStorage storage = getCurrentSelectedRenderer();
if (storage == null) {
return "";
}

View file

@ -17,7 +17,6 @@ public class RouteLineDrawInfo {
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 APP_MODE_KEY = "app_mode_key";
// parameters to save
@ColorInt
@ -31,7 +30,6 @@ public class RouteLineDrawInfo {
private int centerX;
private int centerY;
private int screenHeight;
private String appModeKey;
public RouteLineDrawInfo(@Nullable @ColorInt Integer color,
@Nullable String width) {
@ -44,14 +42,13 @@ public class RouteLineDrawInfo {
}
public RouteLineDrawInfo(@NonNull RouteLineDrawInfo existed) {
this.color = existed.getColor();
this.width = existed.getWidth();
this.color = existed.color;
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.appModeKey = existed.appModeKey;
}
public void setColor(@Nullable Integer color) {
@ -82,10 +79,6 @@ public class RouteLineDrawInfo {
this.screenHeight = screenHeight;
}
public void setAppModeKey(@Nullable String appModeKey) {
this.appModeKey = appModeKey;
}
@Nullable
public Integer getColor() {
return color;
@ -117,20 +110,16 @@ public class RouteLineDrawInfo {
return screenHeight;
}
@Nullable
public String getAppModeKey() {
return appModeKey;
}
private void readBundle(@NonNull Bundle bundle) {
color = bundle.getInt(LINE_COLOR);
if (bundle.containsKey(LINE_COLOR)) {
color = bundle.getInt(LINE_COLOR);
}
width = bundle.getString(LINE_WIDTH);
iconId = bundle.getInt(NAVIGATION_ICON_ID);
iconColor = bundle.getInt(NAVIGATION_ICON_COLOR);
centerX = bundle.getInt(CENTER_X);
centerY = bundle.getInt(CENTER_Y);
screenHeight = bundle.getInt(SCREEN_HEIGHT);
appModeKey = bundle.getString(APP_MODE_KEY);
}
public void saveToBundle(@NonNull Bundle bundle) {
@ -142,10 +131,9 @@ public class RouteLineDrawInfo {
}
bundle.putInt(NAVIGATION_ICON_ID, iconId);
bundle.putInt(NAVIGATION_ICON_COLOR, iconColor);
bundle.putInt(CENTER_X, (int) centerX);
bundle.putInt(CENTER_Y, (int) centerY);
bundle.putInt(CENTER_X, centerX);
bundle.putInt(CENTER_Y, centerY);
bundle.putInt(SCREEN_HEIGHT, screenHeight);
bundle.putString(APP_MODE_KEY, appModeKey);
}
@Override

View file

@ -26,7 +26,6 @@ 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;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.ListStringPreference;
import net.osmand.plus.track.AppearanceViewHolder;
import net.osmand.plus.track.ColorsCard;
@ -34,7 +33,6 @@ import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener;
import net.osmand.plus.widgets.MultiStateToggleButton;
import net.osmand.plus.widgets.MultiStateToggleButton.OnRadioItemClickListener;
import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
import net.osmand.render.RenderingRulesStorage;
import java.util.ArrayList;
import java.util.Arrays;
@ -211,7 +209,7 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
if (selectedMode == ColorMode.DEFAULT) {
String pattern = app.getString(R.string.route_line_use_map_style_appearance);
String color = app.getString(R.string.shared_string_color).toLowerCase();
description = String.format(pattern, color, RendererRegistry.getMapStyleName(app));
description = String.format(pattern, color, app.getRendererRegistry().getSelectedRendererName());
} else {
String pattern = app.getString(R.string.specify_color_for_map_mode);
String mapModeTitle = app.getString(isNightMap() ? NIGHT_TITLE_ID : DAY_TITLE_ID);

View file

@ -131,7 +131,7 @@ public class RouteLineWidthCard extends BaseCard {
if (selectedMode == WidthMode.DEFAULT) {
String pattern = app.getString(R.string.route_line_use_map_style_appearance);
String width = app.getString(R.string.shared_string_color).toLowerCase();
String description = String.format(pattern, width, RendererRegistry.getMapStyleName(app));
String description = String.format(pattern, width, app.getRendererRegistry().getSelectedRendererName());
tvDescription.setText(description);
tvDescription.setVisibility(View.VISIBLE);
} else {

View file

@ -729,12 +729,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
private void updateRouteLinePreference() {
Preference preference = findPreference(CUSTOMIZE_ROUTE_LINE);
if (preference != null) {
boolean isDefaultProfile = getSelectedAppMode().equals(ApplicationMode.DEFAULT) && !isNewProfile;
boolean isPublicTransport = PUBLIC_TRANSPORT_KEY.equals(changedProfile.routingProfile);
preference.setVisible(!isDefaultProfile && !isPublicTransport);
preference.setIcon(getIcon(R.drawable.ic_action_route_distance, getActiveColorRes()));
}
boolean isDefaultProfile = getSelectedAppMode().equals(ApplicationMode.DEFAULT) && !isNewProfile;
boolean isPublicTransport = PUBLIC_TRANSPORT_KEY.equals(changedProfile.routingProfile);
preference.setVisible(!isDefaultProfile && !isPublicTransport);
preference.setIcon(getIcon(R.drawable.ic_action_route_distance, getActiveColorRes()));
}
private boolean checkProfileName() {
@ -999,7 +997,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
RouteLineDrawInfo drawInfo = changedProfile.routeLineDrawInfo;
drawInfo.setIconId(changedProfile.navigationIcon.getIconId());
drawInfo.setIconColor(changedProfile.getActualColor());
drawInfo.setAppModeKey(profile.stringKey);
RouteLineAppearanceFragment.showInstance(mapActivity, drawInfo, this);
}
}
@ -1031,7 +1028,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
private void saveRouteLineAppearance(@NonNull ApplicationMode appMode,
@NonNull RouteLineDrawInfo drawInfo) {
Integer color = drawInfo.getColor();
if (drawInfo.getColor() != null) {
if (color != null) {
settings.ROUTE_LINE_COLOR.setModeValue(appMode, color);
} else {
settings.ROUTE_LINE_COLOR.resetModeToDefault(appMode);

View file

@ -161,6 +161,7 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
private void setupCards() {
MapActivity mapActivity = requireMapActivity();
ViewGroup cardsContainer = getCardsContainer();
cardsContainer.removeAllViews();
colorCard = new RouteLineColorCard(mapActivity, this, routeLineDrawInfo, initMapTheme, selectedMapTheme);
cardsContainer.addView(colorCard.build(mapActivity));
@ -285,17 +286,21 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
int screenHeight = AndroidUtils.getScreenHeight(ctx);
int screenWidth = AndroidUtils.getScreenWidth(ctx);
int statusBarHeight = AndroidUtils.getStatusBarHeight(ctx);
int x;
int y;
if (AndroidUiHelper.isOrientationPortrait(ctx)) {
x = screenWidth / 2;
y = (getViewY() + toolbarContainer.getHeight() + statusBarHeight) / 2;
int centerX;
int centerY;
if (isPortrait()) {
centerX = screenWidth / 2;
centerY = (getViewY() + toolbarContainer.getHeight() + statusBarHeight) / 2;
} else {
x = (int) (AndroidUtils.isLayoutRtl(ctx) ? screenWidth/4 : screenWidth * 0.75);
y = (screenHeight + statusBarHeight) / 2 ;
boolean isRtl = AndroidUtils.isLayoutRtl(ctx);
int dialogWidth = getLandscapeNoShadowWidth();
int left = isRtl ? 0 : dialogWidth;
int right = isRtl ? screenWidth - dialogWidth : screenWidth;
centerX = (left + right) / 2;
centerY = (screenHeight + statusBarHeight) / 2 ;
}
routeLineDrawInfo.setCenterX(x);
routeLineDrawInfo.setCenterY(y);
routeLineDrawInfo.setCenterX(centerX);
routeLineDrawInfo.setCenterY(centerY);
routeLineDrawInfo.setScreenHeight(screenHeight);
}
@ -393,7 +398,6 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
@NonNull Fragment target) {
try {
RouteLineAppearanceFragment fragment = new RouteLineAppearanceFragment();
fragment.setRetainInstance(true);
fragment.setTargetFragment(target, 0);
fragment.routeLineDrawInfo = new RouteLineDrawInfo(drawInfo);

View file

@ -873,7 +873,7 @@ public class MapControlsLayer extends OsmandMapLayer {
&& !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode()
&& !isInPlanRouteMode() && !shouldHideTopControls && !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode() && !isInFollowTrackMode() && !isInTrackAppearanceMode()
&& !isInRouteLineCustomizationMode();
&& !isInRouteLineAppearanceMode();
routePlanningBtn.updateVisibility(showBottomMenuButtons);
menuControl.updateVisibility(showBottomMenuButtons);
@ -881,7 +881,7 @@ public class MapControlsLayer extends OsmandMapLayer {
&& !isInTrackAppearanceMode()
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInRouteLineCustomizationMode();
&& !isInRouteLineAppearanceMode();
boolean showZoomButtons = !routeDialogOpened && !shouldHideTopControls
&& !isInFollowTrackMode()
&& (additionalDialogsHide || !portrait);
@ -891,7 +891,7 @@ public class MapControlsLayer extends OsmandMapLayer {
boolean forceHideCompass = routeDialogOpened || trackDialogOpened || isInMeasurementToolMode()
|| isInPlanRouteMode() || shouldHideTopControls || isInChoosingRoutesMode()
|| isInTrackAppearanceMode() || isInWaypointsChoosingMode() || isInFollowTrackMode()
|| isInRouteLineCustomizationMode();
|| isInRouteLineAppearanceMode();
compassHud.forceHideCompass = forceHideCompass;
compassHud.updateVisibility(!forceHideCompass && shouldShowCompass());
@ -903,7 +903,7 @@ public class MapControlsLayer extends OsmandMapLayer {
boolean showTopButtons = !routeDialogOpened && !trackDialogOpened && !shouldHideTopControls
&& !isInMeasurementToolMode() && !isInPlanRouteMode() && !isInChoosingRoutesMode()
&& !isInTrackAppearanceMode() && !isInWaypointsChoosingMode() && !isInFollowTrackMode()
&& !isInRouteLineCustomizationMode();
&& !isInRouteLineAppearanceMode();
layersHud.updateVisibility(showTopButtons);
quickSearchHud.updateVisibility(showTopButtons);
@ -1034,7 +1034,7 @@ public class MapControlsLayer extends OsmandMapLayer {
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInFollowTrackMode()
&& !isInRouteLineCustomizationMode();
&& !isInRouteLineAppearanceMode();
backToLocationControl.updateVisibility(visible && !dialogOpened && !isInPlanRouteMode()
&& (additionalDialogsHide || !isPotrait()));
}
@ -1402,7 +1402,7 @@ public class MapControlsLayer extends OsmandMapLayer {
return MapRouteInfoMenu.waypointsVisible;
}
private boolean isInRouteLineCustomizationMode() {
private boolean isInRouteLineAppearanceMode() {
return mapActivity.getMapLayers().getRouteLayer().isInRouteLineAppearanceMode();
}

View file

@ -11,6 +11,7 @@ import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import androidx.annotation.ColorInt;
@ -41,8 +42,6 @@ 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.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.geometry.PublicTransportGeometryWay;
@ -103,6 +102,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
private PublicTransportGeometryWay publicTransportRouteGeometry;
private LayerDrawable projectionIcon;
private LayerDrawable previewIcon;
public RouteLayer(RoutingHelper helper) {
this.helper = helper;
@ -246,8 +246,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
return routeLineDrawInfo != null;
}
public void setRouteLineDrawInfo(RouteLineDrawInfo routeLineDrawInfo) {
this.routeLineDrawInfo = routeLineDrawInfo;
public void setRouteLineDrawInfo(RouteLineDrawInfo drawInfo) {
this.routeLineDrawInfo = drawInfo;
if (drawInfo == null) {
previewIcon = null;
}
}
private MapActivity getMapActivity() {
@ -312,41 +315,30 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
QuadPoint c = tileBox.getCenterPixelPoint();
canvas.rotate(-angle, c.x, c.y);
drawRouteLinePreview(canvas, tileBox, settings, routeLineDrawInfo);
drawRouteLinePreview(canvas, tileBox, routeLineDrawInfo);
canvas.rotate(angle, c.x, c.y);
}
}
private void drawRouteLinePreview(Canvas canvas,
RotatedTileBox tileBox,
DrawSettings settings,
RouteLineDrawInfo drawInfo) {
MapActivity mapActivity = getMapActivity();
updateAttrs(settings, tileBox);
paintRouteLinePreview.setColor(getRouteLineColor(nightMode));
paintRouteLinePreview.setStrokeWidth(getRouteLineWidth(tileBox));
int x = drawInfo.getCenterX();
int y = drawInfo.getCenterY();
int centerX = drawInfo.getCenterX();
int centerY = drawInfo.getCenterY();
int screenHeight = drawInfo.getScreenHeight();
// draw line
canvas.drawLine(x, 0, x, screenHeight, paintRouteLinePreview);
canvas.drawLine(centerX, 0, centerX, screenHeight, paintRouteLinePreview);
// draw image
LayerDrawable navigationIcon = (LayerDrawable) AppCompatResources.getDrawable(mapActivity, drawInfo.getIconId());
if (navigationIcon != null) {
DrawableCompat.setTint(navigationIcon.getDrawable(1), drawInfo.getIconColor());
if (previewIcon == null) {
previewIcon = (LayerDrawable) AppCompatResources.getDrawable(view.getContext(), drawInfo.getIconId());
DrawableCompat.setTint(previewIcon.getDrawable(1), drawInfo.getIconColor());
}
int left = x - navigationIcon.getIntrinsicWidth() / 2;
int right = x + navigationIcon.getIntrinsicWidth() / 2;
int top = y - navigationIcon.getIntrinsicHeight() / 2;
int bottom = y + navigationIcon.getIntrinsicHeight() / 2;
navigationIcon.setBounds(left, top, right, bottom);
canvas.rotate(-90, x, y);
navigationIcon.draw(canvas);
canvas.save();
canvas.restore();
canvas.rotate(-90, centerX, centerY);
drawIcon(canvas, previewIcon, centerX, centerY);
canvas.rotate(90, centerX, centerY);
}
private void drawAction(RotatedTileBox tb, Canvas canvas, List<Location> actionPoints) {
@ -410,25 +402,24 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
}
int locationX = (int) projectionXY[0];
int locationY = (int) projectionXY[1];
drawIcon(canvas, projectionIcon, locationX, locationY);
}
projectionIcon.setBounds(locationX - projectionIcon.getIntrinsicWidth() / 2,
locationY - projectionIcon.getIntrinsicHeight() / 2,
locationX + projectionIcon.getIntrinsicWidth() / 2,
locationY + projectionIcon.getIntrinsicHeight() / 2);
projectionIcon.draw(canvas);
private static void drawIcon(Canvas canvas, Drawable drawable, int locationX, int locationY) {
drawable.setBounds(locationX - drawable.getIntrinsicWidth() / 2,
locationY - drawable.getIntrinsicHeight() / 2,
locationX + drawable.getIntrinsicWidth() / 2,
locationY + drawable.getIntrinsicHeight() / 2);
drawable.draw(canvas);
}
@ColorInt
public int getRouteLineColor(boolean night) {
OsmandSettings settings = view.getSettings();
ApplicationMode appMode = getApplicationMode();
Integer color;
if (routeLineDrawInfo != null) {
color = routeLineDrawInfo.getColor();
} else {
int storedValue = settings.ROUTE_LINE_COLOR.getModeValue(appMode);
int storedValue = view.getSettings().ROUTE_LINE_COLOR.getModeValue(helper.getAppMode());
color = storedValue != 0 ? storedValue : null;
}
@ -440,14 +431,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
}
private float getRouteLineWidth(@NonNull RotatedTileBox tileBox) {
OsmandSettings settings = view.getSettings();
ApplicationMode appMode = getApplicationMode();
String widthKey;
if (routeLineDrawInfo != null) {
widthKey = routeLineDrawInfo.getWidth();
} else {
widthKey = settings.ROUTE_LINE_WIDTH.getModeValue(appMode);
widthKey = view.getSettings().ROUTE_LINE_WIDTH.getModeValue(helper.getAppMode());
}
return widthKey != null ? getWidthByKey(tileBox, widthKey) : attrs.paint.getStrokeWidth();
}
@ -470,9 +458,9 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode);
RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR);
req.setIntFilter(rrs.PROPS.R_MINZOOM, tileBox.getZoom());
req.setIntFilter(rrs.PROPS.R_MAXZOOM, tileBox.getZoom());
RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR);
if (ctWidth != null) {
req.setStringFilter(ctWidth, widthKey);
}
@ -486,18 +474,6 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
return resultValue;
}
@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();
}
public void drawLocations(RotatedTileBox tb, Canvas canvas, double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
if (helper.isPublicTransportMode()) {
int currentRoute = transportHelper.getCurrentRoute();

View file

@ -5,6 +5,7 @@ import android.graphics.Paint;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.Location;
import net.osmand.data.RotatedTileBox;
@ -18,6 +19,7 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Geome
private RoutingHelper helper;
private RouteCalculationResult route;
private Integer customColor;
private Float customWidth;
@ -26,8 +28,7 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Geome
this.helper = context.getApp().getRoutingHelper();
}
public void setRouteStyleParams(@ColorInt int color,
float width) {
public void setRouteStyleParams(@Nullable @ColorInt Integer color, @Nullable Float width) {
this.customColor = color;
this.customWidth = width;
}
@ -36,10 +37,8 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Geome
@Override
public GeometryWayStyle<RouteGeometryWayContext> getDefaultWayStyle() {
Paint paint = getContext().getAttrs().paint;
int paintColor = paint.getColor();
int color = customColor != null ? customColor : paintColor;
float paintWidth = paint.getStrokeWidth();
float width = customWidth != null ? customWidth : paintWidth;
int color = customColor != null ? customColor : paint.getColor();
float width = customWidth != null ? customWidth : paint.getStrokeWidth();
return new GeometrySolidWayStyle(getContext(), color, width);
}