From ee6e283d03ea0f8d5261ee1b4e9eb386ac6707a2 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 1 Sep 2020 12:38:53 +0300 Subject: [PATCH] Track appearance UI fixes second part --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 8 +++++-- .../plus/track/CustomColorBottomSheet.java | 8 +++++-- .../plus/track/TrackAppearanceFragment.java | 22 +++++++++++++++++-- .../osmand/plus/track/TrackColoringCard.java | 15 +++++++++++-- .../osmand/plus/views/layers/GPXLayer.java | 12 ++++++---- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 24ffd9c6f7..8dc59eccc9 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -230,8 +230,12 @@ public class UiUtilities { } @ColorInt - public static int mixTwoColors(@ColorInt int color1, @ColorInt int color2, float amount ) - { + public static int removeAlpha(@ColorInt int color) { + return Color.rgb(Color.red(color), Color.green(color), Color.blue(color)); + } + + @ColorInt + public static int mixTwoColors(@ColorInt int color1, @ColorInt int color2, float amount) { final byte ALPHA_CHANNEL = 24; final byte RED_CHANNEL = 16; final byte GREEN_CHANNEL = 8; diff --git a/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java index a5db15c147..dad9831f9c 100644 --- a/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java @@ -58,8 +58,12 @@ public class CustomColorBottomSheet extends MenuBottomSheetDialogFragment implem } else { Bundle args = getArguments(); if (args != null) { - prevColor = args.getInt(PREV_SELECTED_COLOR); - newColor = prevColor != -1 ? prevColor : Color.RED; + if (args.containsKey(PREV_SELECTED_COLOR)) { + prevColor = args.getInt(PREV_SELECTED_COLOR); + } else { + prevColor = Color.RED; + } + newColor = prevColor; } } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index aa8a1ac395..c0d6b42741 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -390,13 +390,21 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement int strokeColor = UiUtilities.getColorWithAlpha(Color.BLACK, 0.7f); Drawable strokeIcon = app.getUIUtilities().getPaintedIcon(strokeIconId, strokeColor); + Drawable transparencyIcon = getTransparencyIcon(app, widthAttr, color); if (showArrows) { int arrowsIconId = getArrowsIconId(widthAttr); int contrastColor = UiUtilities.getContrastColor(app, color, false); Drawable arrows = app.getUIUtilities().getPaintedIcon(arrowsIconId, contrastColor); - return UiUtilities.getLayeredIcon(widthIcon, strokeIcon, arrows); + return UiUtilities.getLayeredIcon(transparencyIcon, widthIcon, strokeIcon, arrows); } - return UiUtilities.getLayeredIcon(widthIcon, strokeIcon); + return UiUtilities.getLayeredIcon(transparencyIcon, widthIcon, strokeIcon); + } + + private Drawable getTransparencyIcon(OsmandApplication app, String widthAttr, @ColorInt int color) { + int transparencyIconId = getTransparencyIconId(widthAttr); + int colorWithoutAlpha = UiUtilities.removeAlpha(color); + int transparencyColor = UiUtilities.getColorWithAlpha(colorWithoutAlpha, 0.8f); + return app.getUIUtilities().getPaintedIcon(transparencyIconId, transparencyColor); } private void updateCardsLayout() { @@ -638,6 +646,16 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement } } + public static int getTransparencyIconId(String widthAttr) { + if (TRACK_WIDTH_BOLD.equals(widthAttr)) { + return R.drawable.ic_action_track_line_bold_transparency; + } else if (TRACK_WIDTH_MEDIUM.equals(widthAttr)) { + return R.drawable.ic_action_track_line_medium_transparency; + } else { + return R.drawable.ic_action_track_line_thin_transparency; + } + } + public static int getWidthIconId(String widthAttr) { if (TRACK_WIDTH_BOLD.equals(widthAttr)) { return R.drawable.ic_action_track_line_bold_color; diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java index 79a7107ca8..5883c0dd73 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -26,6 +26,7 @@ import net.osmand.PlatformUtil; import net.osmand.plus.GPXDatabase; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -143,7 +144,11 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { private View createColorItemView(@ColorInt final int color, final FlowLayout rootView, boolean customColor) { View colorItemView = createCircleView(rootView); ImageView backgroundCircle = colorItemView.findViewById(R.id.background); - backgroundCircle.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, R.drawable.bg_point_circle), color)); + + Drawable transparencyIcon = getTransparencyIcon(app, color); + Drawable colorIcon = app.getUIUtilities().getPaintedIcon(R.drawable.bg_point_circle, color); + Drawable layeredIcon = UiUtilities.getLayeredIcon(transparencyIcon, colorIcon); + backgroundCircle.setImageDrawable(layeredIcon); backgroundCircle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -173,6 +178,12 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { return colorItemView; } + private Drawable getTransparencyIcon(OsmandApplication app, @ColorInt int color) { + int colorWithoutAlpha = UiUtilities.removeAlpha(color); + int transparencyColor = UiUtilities.getColorWithAlpha(colorWithoutAlpha, 0.8f); + return app.getUIUtilities().getPaintedIcon(R.drawable.ic_bg_transparency, transparencyColor); + } + private View createAddCustomColorItemView(FlowLayout rootView) { View colorItemView = createCircleView(rootView); ImageView backgroundCircle = colorItemView.findViewById(R.id.background); @@ -183,7 +194,7 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { ImageView icon = colorItemView.findViewById(R.id.icon); icon.setVisibility(View.VISIBLE); int activeColorResId = nightMode ? R.color.icon_color_active_dark : R.color.icon_color_active_light; - icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_add, activeColorResId)); + icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_plus, activeColorResId)); backgroundCircle.setImageDrawable(backgroundIcon); backgroundCircle.setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index 59a249000a..1b5052f800 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -456,12 +456,16 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM int endX = (int) tileBox.getPixXFromLatLon(end.lat, end.lon); int endY = (int) tileBox.getPixYFromLatLon(end.lat, end.lon); - QuadRect startRect = calculateRect(startX, startY, startPointIcon.getIntrinsicWidth(), startPointIcon.getIntrinsicHeight()); - QuadRect endRect = calculateRect(endX, endY, finishPointIcon.getIntrinsicWidth(), finishPointIcon.getIntrinsicHeight()); + int iconSize = AndroidUtils.dpToPx(view.getContext(), 14); + QuadRect startRectWithoutShadow = calculateRect(startX, startY, iconSize, iconSize); + QuadRect endRectWithoutShadow = calculateRect(endX, endY, iconSize, iconSize); - if (QuadRect.intersects(startRect, endRect)) { - drawPoint(canvas, startRect, startAndFinishIcon); + if (QuadRect.intersects(startRectWithoutShadow, endRectWithoutShadow)) { + QuadRect startAndFinishRect = calculateRect(startX, startY, startAndFinishIcon.getIntrinsicWidth(), startAndFinishIcon.getIntrinsicHeight()); + drawPoint(canvas, startAndFinishRect, startAndFinishIcon); } else { + QuadRect startRect = calculateRect(startX, startY, startPointIcon.getIntrinsicWidth(), startPointIcon.getIntrinsicHeight()); + QuadRect endRect = calculateRect(endX, endY, finishPointIcon.getIntrinsicWidth(), finishPointIcon.getIntrinsicHeight()); drawPoint(canvas, startRect, startPointIcon); drawPoint(canvas, endRect, finishPointIcon); }