Merge pull request #9331 from osmandapp/Shape_OSM_Notes
BackgroundType offset refactor
This commit is contained in:
commit
34292104dd
6 changed files with 52 additions and 49 deletions
|
@ -84,6 +84,7 @@
|
||||||
<dimen name="favorites_select_group_button_width">142dp</dimen>
|
<dimen name="favorites_select_group_button_width">142dp</dimen>
|
||||||
<dimen name="favorites_icon_top_margin">13dp</dimen>
|
<dimen name="favorites_icon_top_margin">13dp</dimen>
|
||||||
<dimen name="favorites_select_icon_button_right_padding">9dp</dimen>
|
<dimen name="favorites_select_icon_button_right_padding">9dp</dimen>
|
||||||
|
<dimen name="point_background_comment_offset_y">14dp</dimen>
|
||||||
|
|
||||||
<dimen name="local_index_check_right_margin">10dp</dimen>
|
<dimen name="local_index_check_right_margin">10dp</dimen>
|
||||||
<dimen name="dialog_elements_vertical_margin">16dp</dimen>
|
<dimen name="dialog_elements_vertical_margin">16dp</dimen>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package net.osmand.data;
|
package net.osmand.data;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -311,7 +314,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
CIRCLE("circle", R.string.shared_string_circle, R.drawable.bg_point_circle),
|
CIRCLE("circle", R.string.shared_string_circle, R.drawable.bg_point_circle),
|
||||||
OCTAGON("octagon", R.string.shared_string_octagon, R.drawable.bg_point_octagon),
|
OCTAGON("octagon", R.string.shared_string_octagon, R.drawable.bg_point_octagon),
|
||||||
SQUARE("square", R.string.shared_string_square, R.drawable.bg_point_square),
|
SQUARE("square", R.string.shared_string_square, R.drawable.bg_point_square),
|
||||||
COMMENT("comment", -1, R.drawable.bg_point_comment);
|
COMMENT("comment", R.string.poi_dialog_comment, R.drawable.bg_point_comment);
|
||||||
private String typeName;
|
private String typeName;
|
||||||
@StringRes
|
@StringRes
|
||||||
private int nameId;
|
private int nameId;
|
||||||
|
@ -344,6 +347,27 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSelected() {
|
||||||
|
return this != COMMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOffsetY(Context ctx, float textScale) {
|
||||||
|
return this == COMMENT ? Math.round(ctx.getResources()
|
||||||
|
.getDimensionPixelSize(R.dimen.point_background_comment_offset_y) * textScale) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getTouchBackground(Context ctx, boolean isSmall) {
|
||||||
|
return getMapBackgroundIconId(ctx, "center", isSmall);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getMapBackgroundIconId(Context ctx, String layer, boolean isSmall) {
|
||||||
|
Resources res = ctx.getResources();
|
||||||
|
String iconName = res.getResourceEntryName(getIconId());
|
||||||
|
String suffix = isSmall ? "_small" : "";
|
||||||
|
return BitmapFactory.decodeResource(res, res.getIdentifier("ic_" + iconName + "_" + layer + suffix,
|
||||||
|
"drawable", ctx.getPackageName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FavouritePoint fromWpt(@NonNull WptPt pt, @NonNull Context ctx) {
|
public static FavouritePoint fromWpt(@NonNull WptPt pt, @NonNull Context ctx) {
|
||||||
|
|
|
@ -65,28 +65,24 @@ public class PointImageDrawable extends Drawable {
|
||||||
private PointImageDrawable(PointInfo pointInfo) {
|
private PointImageDrawable(PointInfo pointInfo) {
|
||||||
this.withShadow = pointInfo.withShadow;
|
this.withShadow = pointInfo.withShadow;
|
||||||
this.synced = pointInfo.synced;
|
this.synced = pointInfo.synced;
|
||||||
Resources res = pointInfo.ctx.getResources();
|
Context ctx = pointInfo.ctx;
|
||||||
UiUtilities uiUtilities = ((OsmandApplication) pointInfo.ctx.getApplicationContext()).getUIUtilities();
|
Resources res = ctx.getResources();
|
||||||
|
UiUtilities uiUtilities = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities();
|
||||||
int overlayIconId = pointInfo.overlayIconId;
|
int overlayIconId = pointInfo.overlayIconId;
|
||||||
int uiIconId;
|
int uiIconId;
|
||||||
mapIcon = uiUtilities.getIcon(getMapIconId(pointInfo.ctx, overlayIconId), R.color.color_white);
|
mapIcon = uiUtilities.getIcon(getMapIconId(ctx, overlayIconId), R.color.color_white);
|
||||||
uiIconId = overlayIconId;
|
uiIconId = overlayIconId;
|
||||||
int col = pointInfo.color == 0 ? res.getColor(R.color.color_favorite) : pointInfo.color;
|
int col = pointInfo.color == 0 ? res.getColor(R.color.color_favorite) : pointInfo.color;
|
||||||
uiListIcon = uiUtilities.getIcon(uiIconId, R.color.color_white);
|
uiListIcon = uiUtilities.getIcon(uiIconId, R.color.color_white);
|
||||||
int uiBackgroundIconId = pointInfo.backgroundType.getIconId();
|
BackgroundType backgroundType = pointInfo.backgroundType;
|
||||||
|
int uiBackgroundIconId = backgroundType.getIconId();
|
||||||
uiBackgroundIcon = uiUtilities.getPaintedIcon(uiBackgroundIconId, col);
|
uiBackgroundIcon = uiUtilities.getPaintedIcon(uiBackgroundIconId, col);
|
||||||
int mapBackgroundIconIdTop = getMapBackgroundIconId(pointInfo, "top", false);
|
mapIconBackgroundTop = backgroundType.getMapBackgroundIconId(ctx, "top", false);
|
||||||
int mapBackgroundIconIdCenter = getMapBackgroundIconId(pointInfo, "center", false);
|
mapIconBackgroundCenter = backgroundType.getMapBackgroundIconId(ctx, "center", false);
|
||||||
int mapBackgroundIconIdBottom = getMapBackgroundIconId(pointInfo, "bottom", false);
|
mapIconBackgroundBottom = backgroundType.getMapBackgroundIconId(ctx, "bottom", false);
|
||||||
mapIconBackgroundTop = BitmapFactory.decodeResource(res, mapBackgroundIconIdTop);
|
mapIconBackgroundTopSmall = backgroundType.getMapBackgroundIconId(ctx, "top", true);
|
||||||
mapIconBackgroundCenter = BitmapFactory.decodeResource(res, mapBackgroundIconIdCenter);
|
mapIconBackgroundCenterSmall = backgroundType.getMapBackgroundIconId(ctx, "center", true);
|
||||||
mapIconBackgroundBottom = BitmapFactory.decodeResource(res, mapBackgroundIconIdBottom);
|
mapIconBackgroundBottomSmall = backgroundType.getMapBackgroundIconId(ctx, "bottom", true);
|
||||||
int mapBackgroundIconIdTopSmall = getMapBackgroundIconId(pointInfo, "top", true);
|
|
||||||
int mapBackgroundIconIdCenterSmall = getMapBackgroundIconId(pointInfo, "center", true);
|
|
||||||
int mapBackgroundIconIdBottomSmall = getMapBackgroundIconId(pointInfo, "bottom", true);
|
|
||||||
mapIconBackgroundTopSmall = BitmapFactory.decodeResource(res, mapBackgroundIconIdTopSmall);
|
|
||||||
mapIconBackgroundCenterSmall = BitmapFactory.decodeResource(res, mapBackgroundIconIdCenterSmall);
|
|
||||||
mapIconBackgroundBottomSmall = BitmapFactory.decodeResource(res, mapBackgroundIconIdBottomSmall);
|
|
||||||
syncedStroke = BitmapFactory.decodeResource(res, R.drawable.ic_shield_marker_point_stroke);
|
syncedStroke = BitmapFactory.decodeResource(res, R.drawable.ic_shield_marker_point_stroke);
|
||||||
syncedColor = BitmapFactory.decodeResource(res, R.drawable.ic_shield_marker_point_color);
|
syncedColor = BitmapFactory.decodeResource(res, R.drawable.ic_shield_marker_point_color);
|
||||||
syncedShadow = BitmapFactory.decodeResource(res, R.drawable.ic_shield_marker_point_shadow);
|
syncedShadow = BitmapFactory.decodeResource(res, R.drawable.ic_shield_marker_point_shadow);
|
||||||
|
@ -102,15 +98,6 @@ public class PointImageDrawable extends Drawable {
|
||||||
.replaceFirst("mx_", "mm_"), "drawable", ctx.getPackageName());
|
.replaceFirst("mx_", "mm_"), "drawable", ctx.getPackageName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMapBackgroundIconId(PointInfo pointInfo, String layer, boolean isSmall) {
|
|
||||||
Context ctx = pointInfo.ctx;
|
|
||||||
int iconId = pointInfo.backgroundType.getIconId();
|
|
||||||
String iconName = ctx.getResources().getResourceEntryName(iconId);
|
|
||||||
String suffix = isSmall ? "_small" : "";
|
|
||||||
return ctx.getResources().getIdentifier("ic_" + iconName + "_" + layer + suffix,
|
|
||||||
"drawable", ctx.getPackageName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBoundsChange(Rect bounds) {
|
protected void onBoundsChange(Rect bounds) {
|
||||||
super.onBoundsChange(bounds);
|
super.onBoundsChange(bounds);
|
||||||
|
|
|
@ -380,7 +380,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
||||||
private void createShapeSelector() {
|
private void createShapeSelector() {
|
||||||
FlowLayout selectShape = view.findViewById(R.id.select_shape);
|
FlowLayout selectShape = view.findViewById(R.id.select_shape);
|
||||||
for (BackgroundType backgroundType : BackgroundType.values()) {
|
for (BackgroundType backgroundType : BackgroundType.values()) {
|
||||||
if (backgroundType.getNameId() != -1) {
|
if (backgroundType.isSelected()) {
|
||||||
selectShape.addView(createShapeItemView(backgroundType, selectShape),
|
selectShape.addView(createShapeItemView(backgroundType, selectShape),
|
||||||
new FlowLayout.LayoutParams(0, 0));
|
new FlowLayout.LayoutParams(0, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,10 +155,11 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
|
||||||
iconId = R.drawable.mx_special_symbol_check_mark;
|
iconId = R.drawable.mx_special_symbol_check_mark;
|
||||||
backgroundColorRes = R.color.osm_bug_resolved_icon_color;
|
backgroundColorRes = R.color.osm_bug_resolved_icon_color;
|
||||||
}
|
}
|
||||||
|
BackgroundType backgroundType = BackgroundType.COMMENT;
|
||||||
PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(activity,
|
PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(activity,
|
||||||
ContextCompat.getColor(activity, backgroundColorRes), true, false, iconId,
|
ContextCompat.getColor(activity, backgroundColorRes), true, false, iconId,
|
||||||
BackgroundType.COMMENT);
|
backgroundType);
|
||||||
int offsetY = pointImageDrawable.getIntrinsicHeight() / 2;
|
int offsetY = backgroundType.getOffsetY(activity, textScale);
|
||||||
pointImageDrawable.drawPoint(canvas, x, y - offsetY, textScale, false);
|
pointImageDrawable.drawPoint(canvas, x, y - offsetY, textScale, false);
|
||||||
}
|
}
|
||||||
this.fullObjectsLatLon = fullObjectsLatLon;
|
this.fullObjectsLatLon = fullObjectsLatLon;
|
||||||
|
|
|
@ -2,9 +2,7 @@ package net.osmand.plus.views;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
|
@ -225,16 +223,17 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float scale = 1f;
|
float textScale = 1f;
|
||||||
if (!pressedLatLonSmall.isEmpty() || !pressedLatLonFull.isEmpty()) {
|
if (!pressedLatLonSmall.isEmpty() || !pressedLatLonFull.isEmpty()) {
|
||||||
scale = activity.getMyApplication().getSettings().TEXT_SCALE.get();
|
textScale = activity.getMyApplication().getSettings().TEXT_SCALE.get();
|
||||||
}
|
}
|
||||||
for (LatLon latLon : pressedLatLonSmall.keySet()) {
|
for (LatLon latLon : pressedLatLonSmall.keySet()) {
|
||||||
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||||
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||||
Bitmap pressedBitmapSmall = getBackground(pressedLatLonSmall.get(latLon), true);
|
BackgroundType background = pressedLatLonSmall.get(latLon);
|
||||||
|
Bitmap pressedBitmapSmall = background.getTouchBackground(activity, true);
|
||||||
Rect destRect = getIconDestinationRect(
|
Rect destRect = getIconDestinationRect(
|
||||||
x, y, pressedBitmapSmall.getWidth(), pressedBitmapSmall.getHeight(), scale);
|
x, y, pressedBitmapSmall.getWidth(), pressedBitmapSmall.getHeight(), textScale);
|
||||||
canvas.drawBitmap(pressedBitmapSmall, null, destRect, paint);
|
canvas.drawBitmap(pressedBitmapSmall, null, destRect, paint);
|
||||||
}
|
}
|
||||||
for (LatLon latLon : pressedLatLonFull.keySet()) {
|
for (LatLon latLon : pressedLatLonFull.keySet()) {
|
||||||
|
@ -242,10 +241,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||||
|
|
||||||
BackgroundType background = pressedLatLonFull.get(latLon);
|
BackgroundType background = pressedLatLonFull.get(latLon);
|
||||||
Bitmap pressedBitmap = getBackground(background, false);
|
Bitmap pressedBitmap = background.getTouchBackground(activity, false);
|
||||||
int offsetY = BackgroundType.COMMENT.equals(background) ? pressedBitmap.getHeight() / 2 : 0;
|
int offsetY = background.getOffsetY(activity, textScale);
|
||||||
Rect destRect = getIconDestinationRect(
|
Rect destRect = getIconDestinationRect(
|
||||||
x, y - offsetY, pressedBitmap.getWidth(), pressedBitmap.getHeight(), scale);
|
x, y - offsetY, pressedBitmap.getWidth(), pressedBitmap.getHeight(), textScale);
|
||||||
canvas.drawBitmap(pressedBitmap, null, destRect, paint);
|
canvas.drawBitmap(pressedBitmap, null, destRect, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,15 +270,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap getBackground(BackgroundType backgroundType, boolean isSmall) {
|
|
||||||
Context ctx = view.getContext();
|
|
||||||
Resources res = view.getResources();
|
|
||||||
String iconName = res.getResourceEntryName(backgroundType.getIconId());
|
|
||||||
String suffix = isSmall ? "_small" : "";
|
|
||||||
return BitmapFactory.decodeResource(res, res.getIdentifier("ic_" + iconName + "_center" + suffix,
|
|
||||||
"drawable", ctx.getPackageName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectOnMap(CallbackWithObject<LatLon> selectOnMap) {
|
public void setSelectOnMap(CallbackWithObject<LatLon> selectOnMap) {
|
||||||
this.selectOnMap = selectOnMap;
|
this.selectOnMap = selectOnMap;
|
||||||
}
|
}
|
||||||
|
@ -927,9 +917,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
backgroundType = BackgroundType.getByTypeName(
|
backgroundType = BackgroundType.getByTypeName(
|
||||||
((GPXUtilities.WptPt) o).getBackgroundType(), DEFAULT_BACKGROUND_TYPE);
|
((GPXUtilities.WptPt) o).getBackgroundType(), DEFAULT_BACKGROUND_TYPE);
|
||||||
}
|
}
|
||||||
if (lt.isPresentInFullObjects(latLon) && !pressedLatLonFull.keySet().contains(latLon)) {
|
if (lt.isPresentInFullObjects(latLon) && !pressedLatLonFull.containsKey(latLon)) {
|
||||||
pressedLatLonFull.put(latLon, backgroundType);
|
pressedLatLonFull.put(latLon, backgroundType);
|
||||||
} else if (lt.isPresentInSmallObjects(latLon) && !pressedLatLonSmall.keySet().contains(latLon)) {
|
} else if (lt.isPresentInSmallObjects(latLon) && !pressedLatLonSmall.containsKey(latLon)) {
|
||||||
pressedLatLonSmall.put(latLon, backgroundType);
|
pressedLatLonSmall.put(latLon, backgroundType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue