Refactoring.

This commit is contained in:
Dima-1 2020-03-17 17:28:35 +02:00
parent 889ac143d3
commit 05c174afae
4 changed files with 25 additions and 16 deletions

View file

@ -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

View file

@ -415,6 +415,11 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
return backgroundType;
}
@Override
public int getIconId() {
return iconId;
}
private int getColor() {
return color;
}

View file

@ -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<String> getCategories();
String getNameTextValue() {

View file

@ -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);