From 05c174afae5397cf2a1a67b0cb996fdf6495b116 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 17 Mar 2020 17:28:35 +0200 Subject: [PATCH] Refactoring. --- .../osmand/plus/base/FavoriteImageDrawable.java | 17 ++++++++--------- .../editors/FavoritePointEditorFragmentNew.java | 5 +++++ .../editors/PointEditorFragmentNew.java | 15 ++++++++++----- .../net/osmand/plus/views/FavouritesLayer.java | 4 ++-- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 6b663708b4..05676f04da 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -20,6 +20,7 @@ import net.osmand.GPXUtilities; import net.osmand.data.FavouritePoint; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import java.util.TreeMap; @@ -47,22 +48,20 @@ public class FavoriteImageDrawable extends Drawable { this.withShadow = withShadow; this.synced = synced; Resources res = ctx.getResources(); + UiUtilities uiUtilities = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities(); int overlayIconId = point != null ? point.getOverlayIconId() : 0; int uiIconId; if (overlayIconId != 0) { - favIcon = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() - .getIcon(getMapIconId(ctx, overlayIconId), R.color.color_white); + favIcon = uiUtilities.getIcon(getMapIconId(ctx, overlayIconId), R.color.color_white); uiIconId = overlayIconId; } else { favIcon = res.getDrawable(R.drawable.mm_special_star); uiIconId = R.drawable.mx_special_star; } int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color; - uiListIcon = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() - .getIcon(uiIconId, R.color.color_white); + uiListIcon = uiUtilities.getIcon(uiIconId, R.color.color_white); int uiBackgroundIconId = point != null ? point.getBackgroundType().getIconId() : R.drawable.bg_point_circle; - uiBackgroundIcon = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() - .getPaintedIcon(uiBackgroundIconId, col); + uiBackgroundIcon = uiUtilities.getPaintedIcon(uiBackgroundIconId, col); int mapBackgroundIconIdTop = getMapBackgroundIconId(ctx, point, "top"); int mapBackgroundIconIdCenter = getMapBackgroundIconId(ctx, point, "center"); int mapBackgroundIconIdBottom = getMapBackgroundIconId(ctx, point, "bottom"); @@ -127,9 +126,9 @@ public class FavoriteImageDrawable extends Drawable { drawBitmap(canvas, bs, syncedStroke, paintBackground); drawBitmap(canvas, bs, syncedIcon, paintIcon); } else if (withShadow) { - drawBitmap(canvas, bs, favBackgroundBottom, new Paint()); + drawBitmap(canvas, bs, favBackgroundBottom, null); drawBitmap(canvas, bs, favBackgroundCenter, paintBackground); - drawBitmap(canvas, bs, favBackgroundTop, new Paint()); + drawBitmap(canvas, bs, favBackgroundTop, null); favIcon.draw(canvas); } else { uiBackgroundIcon.draw(canvas); @@ -153,7 +152,7 @@ public class FavoriteImageDrawable extends Drawable { @Override public int getOpacity() { - return PixelFormat.UNKNOWN; + return 0; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index 20babe18cd..a2a084a5a8 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -415,6 +415,11 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { return backgroundType; } + @Override + public int getIconId() { + return iconId; + } + private int getColor() { return color; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index 265562b305..95e3a9a6b6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -92,7 +92,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { selectedColor = 0xb4FFFFFF & getPointColor(); selectedShape = getBackgroundType(); - selectedIcon = R.drawable.mx_special_star; + selectedIcon = getIconId(); Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); toolbar.setTitle(getToolbarTitle()); @@ -405,19 +405,22 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { private void updateIconSelector(int iconRes, View rootView) { View oldIcon = rootView.findViewWithTag(selectedIcon); + OsmandApplication app = requireMyApplication(); if (oldIcon != null) { oldIcon.findViewById(R.id.outline).setVisibility(View.INVISIBLE); ImageView background = oldIcon.findViewById(R.id.background); AndroidUtils.setBackground(background, - UiUtilities.tintDrawable(ContextCompat.getDrawable(requireMyApplication(), R.drawable.bg_point_circle), - ContextCompat.getColor(requireMyApplication(), R.color.divider_color_light))); + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.bg_point_circle), + ContextCompat.getColor(app, R.color.divider_color_light))); +// ImageView icon = oldIcon.findViewById(R.id.icon); +// icon.setImageDrawable(app.getUIUtilities().getIcon(selectedIcon, R.color.icon_color_default_light)); } View icon = rootView.findViewWithTag(iconRes); if (icon != null) { - ImageView iconImage = icon.findViewById(R.id.icon); +// ImageView iconImage = icon.findViewById(R.id.icon); icon.findViewById(R.id.outline).setVisibility(View.VISIBLE); - iconImage.setImageDrawable(UiUtilities.tintDrawable(iconImage.getDrawable(), R.color.white_50_transparent)); +// iconImage.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.color_white)); ImageView backgroundCircle = icon.findViewById(R.id.background); AndroidUtils.setBackground(backgroundCircle, UiUtilities.tintDrawable(ContextCompat.getDrawable(view.getContext(), R.drawable.bg_point_circle), selectedColor)); @@ -629,6 +632,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { public abstract FavouritePoint.BackgroundType getBackgroundType(); + public abstract int getIconId(); + public abstract Set getCategories(); String getNameTextValue() { diff --git a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java index 0b0e9ecf06..396354a8c8 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java @@ -152,8 +152,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. Bitmap pointSmallTop = getBitmap(o, "top"); Bitmap pointSmallCenter = getBitmap(o, "center"); Bitmap pointSmallBottom = getBitmap(o, "bottom"); - float left = x - (pointSmallTop.getWidth() >> 1); - float top = y - (pointSmallTop.getHeight() >> 1); + float left = x - pointSmallTop.getWidth() / 2f; + float top = y - pointSmallTop.getHeight() / 2f; canvas.drawBitmap(pointSmallBottom, left, top, null); canvas.drawBitmap(pointSmallCenter, left, top, paintIcon); canvas.drawBitmap(pointSmallTop, left, top, null);