From d4f3c1b597a89cd00511aa015b90c4319573cf3d Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 19 Feb 2020 19:12:59 +0200 Subject: [PATCH 001/113] Custom fav icon --- .../main/java/net/osmand/GPXUtilities.java | 14 +++++++ .../src/net/osmand/data/FavouritePoint.java | 37 ++++++++++++++++++- .../plus/base/FavoriteImageDrawable.java | 10 ++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index fe6d1336f1..e80d91ec9c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -44,6 +44,8 @@ public class GPXUtilities { public final static Log log = PlatformUtil.getLog(GPXUtilities.class); private static final String ICON_NAME_EXTENSION = "icon"; private static final String DEFAULT_ICON_NAME = "special_star"; + public static final String BACK_TYPE_EXTENSION = "background"; + private static final String DEFAULT_BACK_TYPE = "bg_point_circle"; private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$ private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$ @@ -271,6 +273,18 @@ public class GPXUtilities { getExtensionsToWrite().put(ICON_NAME_EXTENSION, iconName); } + public String getBackType() { + String backType = getExtensionsToRead().get(BACK_TYPE_EXTENSION); + if (backType == null) { + backType = DEFAULT_ICON_NAME; + } + return backType; + } + + public void setBackType(String backType) { + getExtensionsToWrite().put(BACK_TYPE_EXTENSION, backType); + } + @Override public int hashCode() { final int prime = 31; diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 4d70bd663b..0ce4dae2c7 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -12,7 +12,6 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.R; import net.osmand.util.Algorithms; - public class FavouritePoint implements Serializable, LocationPoint { private static final long serialVersionUID = 729654300829771466L; @@ -30,6 +29,7 @@ public class FavouritePoint implements Serializable, LocationPoint { private int color; private boolean visible = true; private SpecialPointType specialPointType = null; + private BackType backType = null; public FavouritePoint() { } @@ -56,6 +56,7 @@ public class FavouritePoint implements Serializable, LocationPoint { this.originObjectName = favouritePoint.originObjectName; this.address = favouritePoint.address; this.iconId = favouritePoint.iconId; + this.backType = favouritePoint.backType; initPersonalType(); } @@ -196,6 +197,17 @@ public class FavouritePoint implements Serializable, LocationPoint { this.description = description; } + private void setBackType(BackType backType) { + this.backType = backType; + } + + public BackType getBackType() { + if (backType == null) { + return BackType.CIRCLE; + } + return backType; + } + @NonNull @Override public String toString() { @@ -284,6 +296,25 @@ public class FavouritePoint implements Serializable, LocationPoint { } } + public enum BackType { + CIRCLE("CIRCLE", R.drawable.bg_point_circle), + RHOMB("RHOMB", R.drawable.bg_point_rhomb), + SQUARE("SQUARE", R.drawable.bg_point_square); + + private String typeName; + @StringRes + private int iconId; + + BackType(@NonNull String typeName, @DrawableRes int iconId){ + this.typeName = typeName; + this.iconId = iconId; + } + + public int getIconId() { + return iconId; + } + } + public static FavouritePoint fromWpt(@NonNull WptPt pt, @NonNull Context ctx) { String name = pt.name; String categoryName = pt.category != null ? pt.category : ""; @@ -303,6 +334,7 @@ public class FavouritePoint implements Serializable, LocationPoint { if (iconName != null) { fp.setIconIdFromName(ctx, iconName); } + fp.setBackType(BackType.valueOf((pt.getBackType()))); return fp; } @@ -319,6 +351,9 @@ public class FavouritePoint implements Serializable, LocationPoint { if (iconId != 0) { pt.setIconName(getIconEntryName(ctx).substring(3)); } + if(backType != null) { + pt.setBackType(backType.typeName); + } if (getColor() != 0) { pt.setColor(getColor()); } diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 75c5cecdf7..49baf3cddb 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -57,8 +57,10 @@ public class FavoriteImageDrawable extends Drawable { } listDrawable = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() .getIcon(uiIconId, R.color.color_white); + int backgroundIconId = point!=null ? getMapBackIconId(ctx,point.getBackType().getIconId()):R.drawable.map_white_favorite_shield; int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color; - favBackground = BitmapFactory.decodeResource(res, R.drawable.map_white_favorite_shield); + favBackground = BitmapFactory.decodeResource(res,backgroundIconId); +// favBackground = BitmapFactory.decodeResource(res, R.drawable.map_white_favorite_shield); syncedStroke = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_stroke); syncedColor = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_color); syncedShadow = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_shadow); @@ -75,6 +77,12 @@ public class FavoriteImageDrawable extends Drawable { .replaceFirst("mx_", "mm_"), "drawable", ctx.getPackageName()); } + private int getMapBackIconId(Context ctx, int iconId) { + String iconName = ctx.getResources().getResourceEntryName(iconId); + return ctx.getResources().getIdentifier("map_"+iconName + "_center" + , "drawable", ctx.getPackageName()); + } + private void initSimplePaint(Paint paint, int color) { paint.setAntiAlias(true); paint.setStyle(Style.FILL_AND_STROKE); From 7c050800b89f2a5cb5ebf7a6f283e6ab5642309b Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 20 Feb 2020 13:47:35 +0200 Subject: [PATCH 002/113] Add fav multilayer background --- .../main/java/net/osmand/GPXUtilities.java | 4 +- .../src/net/osmand/data/FavouritePoint.java | 10 ++--- .../plus/base/FavoriteImageDrawable.java | 38 ++++++++++++------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index e80d91ec9c..c1aff7a475 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -45,7 +45,7 @@ public class GPXUtilities { private static final String ICON_NAME_EXTENSION = "icon"; private static final String DEFAULT_ICON_NAME = "special_star"; public static final String BACK_TYPE_EXTENSION = "background"; - private static final String DEFAULT_BACK_TYPE = "bg_point_circle"; + private static final String DEFAULT_BACK_TYPE = "CIRCLE"; private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$ private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$ @@ -276,7 +276,7 @@ public class GPXUtilities { public String getBackType() { String backType = getExtensionsToRead().get(BACK_TYPE_EXTENSION); if (backType == null) { - backType = DEFAULT_ICON_NAME; + backType = DEFAULT_BACK_TYPE; } return backType; } diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 0ce4dae2c7..cdd7c249e7 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -197,10 +197,6 @@ public class FavouritePoint implements Serializable, LocationPoint { this.description = description; } - private void setBackType(BackType backType) { - this.backType = backType; - } - public BackType getBackType() { if (backType == null) { return BackType.CIRCLE; @@ -208,6 +204,10 @@ public class FavouritePoint implements Serializable, LocationPoint { return backType; } + private void setBackType(BackType backType) { + this.backType = backType; + } + @NonNull @Override public String toString() { @@ -305,7 +305,7 @@ public class FavouritePoint implements Serializable, LocationPoint { @StringRes private int iconId; - BackType(@NonNull String typeName, @DrawableRes int iconId){ + BackType(@NonNull String typeName, @DrawableRes int iconId) { this.typeName = typeName; this.iconId = iconId; } diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 49baf3cddb..8a9d1876c9 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -28,7 +28,9 @@ public class FavoriteImageDrawable extends Drawable { private boolean synced; private boolean history; private Drawable favIcon; - private Bitmap favBackground; + private Bitmap favBackgroundTop; + private Bitmap favBackgroundCenter; + private Bitmap favBackgroundBottom; private Bitmap syncedStroke; private Bitmap syncedColor; private Bitmap syncedShadow; @@ -57,17 +59,20 @@ public class FavoriteImageDrawable extends Drawable { } listDrawable = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() .getIcon(uiIconId, R.color.color_white); - int backgroundIconId = point!=null ? getMapBackIconId(ctx,point.getBackType().getIconId()):R.drawable.map_white_favorite_shield; + int backgroundTopIconId = getMapBackIconId(ctx, point, "top"); + int backgroundCenterIconId = getMapBackIconId(ctx, point, "center"); + int backgroundBottomIconId = getMapBackIconId(ctx, point, "bottom"); int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color; - favBackground = BitmapFactory.decodeResource(res,backgroundIconId); -// favBackground = BitmapFactory.decodeResource(res, R.drawable.map_white_favorite_shield); + favBackgroundTop = BitmapFactory.decodeResource(res, backgroundTopIconId); + favBackgroundCenter = BitmapFactory.decodeResource(res, backgroundCenterIconId); + favBackgroundBottom = BitmapFactory.decodeResource(res, backgroundBottomIconId); syncedStroke = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_stroke); syncedColor = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_color); syncedShadow = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_shadow); syncedIcon = BitmapFactory.decodeResource(res, R.drawable.map_marker_point_14dp); initSimplePaint(paintOuter, color == 0 || color == Color.BLACK ? 0x88555555 : color); initSimplePaint(paintInnerCircle, col); - colorFilter = new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY); + colorFilter = new PorterDuffColorFilter(col, PorterDuff.Mode.SRC_IN); grayFilter = new PorterDuffColorFilter(res.getColor(R.color.color_favorite_gray), PorterDuff.Mode.MULTIPLY); } @@ -77,10 +82,14 @@ public class FavoriteImageDrawable extends Drawable { .replaceFirst("mx_", "mm_"), "drawable", ctx.getPackageName()); } - private int getMapBackIconId(Context ctx, int iconId) { - String iconName = ctx.getResources().getResourceEntryName(iconId); - return ctx.getResources().getIdentifier("map_"+iconName + "_center" - , "drawable", ctx.getPackageName()); + private int getMapBackIconId(Context ctx, FavouritePoint point, String layer) { + if (point != null) { + int iconId = point.getBackType().getIconId(); + String iconName = ctx.getResources().getResourceEntryName(iconId); + return ctx.getResources().getIdentifier("map_" + iconName + "_" + layer + , "drawable", ctx.getPackageName()); + } + return R.drawable.map_white_favorite_shield; } private void initSimplePaint(Paint paint, int color) { @@ -94,22 +103,23 @@ public class FavoriteImageDrawable extends Drawable { super.onBoundsChange(bounds); Rect bs = new Rect(bounds); //bs.inset((int) (4 * density), (int) (4 * density)); - bs.inset(bs.width() / 4, bs.height() / 4); if (!withShadow && !synced) { + bs.inset(bs.width() / 4, bs.height() / 4); listDrawable.setBounds(bs); } else if (withShadow) { + bs.inset(bs.width() / 3, bs.height() / 3); favIcon.setBounds(bs); } } @Override public int getIntrinsicHeight() { - return synced ? syncedShadow.getHeight() : favBackground.getHeight(); + return synced ? syncedShadow.getHeight() : favBackgroundCenter.getHeight(); } @Override public int getIntrinsicWidth() { - return synced ? syncedShadow.getWidth() : favBackground.getWidth(); + return synced ? syncedShadow.getWidth() : favBackgroundCenter.getWidth(); } @Override @@ -122,7 +132,9 @@ public class FavoriteImageDrawable extends Drawable { canvas.drawBitmap(syncedStroke, bs.exactCenterX() - syncedStroke.getWidth() / 2f, bs.exactCenterY() - syncedStroke.getHeight() / 2f, paintBackground); canvas.drawBitmap(syncedIcon, bs.exactCenterX() - syncedIcon.getWidth() / 2f, bs.exactCenterY() - syncedIcon.getHeight() / 2f, paintIcon); } else if (withShadow) { - canvas.drawBitmap(favBackground, bs.exactCenterX() - favBackground.getWidth() / 2f, bs.exactCenterY() - favBackground.getHeight() / 2f, paintBackground); + canvas.drawBitmap(favBackgroundBottom, bs.exactCenterX() - favBackgroundBottom.getWidth() / 2f, bs.exactCenterY() - favBackgroundBottom.getHeight() / 2f, new Paint()); + canvas.drawBitmap(favBackgroundCenter, bs.exactCenterX() - favBackgroundCenter.getWidth() / 2f, bs.exactCenterY() - favBackgroundCenter.getHeight() / 2f, paintBackground); + canvas.drawBitmap(favBackgroundTop, bs.exactCenterX() - favBackgroundTop.getWidth() / 2f, bs.exactCenterY() - favBackgroundTop.getHeight() / 2f, new Paint()); favIcon.draw(canvas); } else { int min = Math.min(bs.width(), bs.height()); From dd1791a257f33b6117b97837fe311193e8684192 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 20 Feb 2020 18:59:18 +0200 Subject: [PATCH 003/113] Fix icon uniqueId --- OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 8a9d1876c9..960410e326 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -173,13 +173,14 @@ public class FavoriteImageDrawable extends Drawable { private static TreeMap cache = new TreeMap<>(); private static FavoriteImageDrawable getOrCreate(Context ctx, int color, boolean withShadow, boolean synced, FavouritePoint point) { - String iconName = ""; + String uniqueId = ""; if (point != null) { - iconName = point.getIconEntryName(ctx); + uniqueId = point.getIconEntryName(ctx); + uniqueId += point.getBackType().name(); } color = color | 0xff000000; int hash = (color << 4) + ((withShadow ? 1 : 0) << 2) + ((synced ? 3 : 0) << 2); - String uniqueId = hash + iconName; + uniqueId = hash + uniqueId; FavoriteImageDrawable drawable = cache.get(uniqueId); if (drawable == null) { drawable = new FavoriteImageDrawable(ctx, color, withShadow, synced, point); From a91fcad0f2662402e53b117c02f4227d4a38d21c Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 21 Feb 2020 13:53:40 +0200 Subject: [PATCH 004/113] Background type lowercase --- .../src/net/osmand/data/FavouritePoint.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index cdd7c249e7..4f517f4a5c 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -114,15 +114,15 @@ public class FavouritePoint implements Serializable, LocationPoint { public PointDescription getPointDescription(@NonNull Context ctx) { return new PointDescription(PointDescription.POINT_TYPE_FAVORITE, getDisplayName(ctx)); } - + public void setColor(int color) { this.color = color; } - + public boolean isVisible() { return visible; } - + public void setVisible(boolean visible) { this.visible = visible; } @@ -159,7 +159,7 @@ public class FavouritePoint implements Serializable, LocationPoint { public void setLongitude(double longitude) { this.longitude = longitude; } - + public String getCategory() { return category; } @@ -167,7 +167,7 @@ public class FavouritePoint implements Serializable, LocationPoint { public String getCategoryDisplayName(@NonNull Context ctx) { return FavouritesDbHelper.FavoriteGroup.getDisplayName(ctx, category); } - + public void setCategory(String category) { this.category = category; initPersonalType(); @@ -179,7 +179,7 @@ public class FavouritePoint implements Serializable, LocationPoint { } return name; } - + public String getName() { return name; } @@ -297,9 +297,9 @@ public class FavouritePoint implements Serializable, LocationPoint { } public enum BackType { - CIRCLE("CIRCLE", R.drawable.bg_point_circle), - RHOMB("RHOMB", R.drawable.bg_point_rhomb), - SQUARE("SQUARE", R.drawable.bg_point_square); + CIRCLE("circle", R.drawable.bg_point_circle), + RHOMB("rhomb", R.drawable.bg_point_rhomb), + SQUARE("sqare", R.drawable.bg_point_square); private String typeName; @StringRes @@ -334,7 +334,7 @@ public class FavouritePoint implements Serializable, LocationPoint { if (iconName != null) { fp.setIconIdFromName(ctx, iconName); } - fp.setBackType(BackType.valueOf((pt.getBackType()))); + fp.setBackType(BackType.valueOf((pt.getBackType().toUpperCase()))); return fp; } From d4b43304cdf345d75efa56df6d5eab2c94396b82 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 21 Feb 2020 17:28:49 +0200 Subject: [PATCH 005/113] Fix IU favorite icon size --- OsmAnd/res/layout/favorites_list_item.xml | 8 +-- OsmAnd/res/values/sizes.xml | 1 + .../plus/base/FavoriteImageDrawable.java | 69 +++++++++---------- .../MapContextMenuFragment.java | 2 +- 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/OsmAnd/res/layout/favorites_list_item.xml b/OsmAnd/res/layout/favorites_list_item.xml index 7b3588f435..1f09977516 100644 --- a/OsmAnd/res/layout/favorites_list_item.xml +++ b/OsmAnd/res/layout/favorites_list_item.xml @@ -28,7 +28,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:orientation="horizontal" - android:paddingLeft="@dimen/list_content_padding"> + android:paddingLeft="@dimen/list_header_padding"> + android:layout_marginRight="@dimen/list_header_padding" /> 8dp 24dp + 40dp 10dp 13dp 16dp diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 960410e326..13cbb4549c 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -8,7 +8,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; -import android.graphics.Paint.Style; +import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.Rect; @@ -35,11 +35,10 @@ public class FavoriteImageDrawable extends Drawable { private Bitmap syncedColor; private Bitmap syncedShadow; private Bitmap syncedIcon; - private Drawable listDrawable; + private Drawable uiListIcon; + private Drawable uiBackgroundIcon; private Paint paintIcon = new Paint(); private Paint paintBackground = new Paint(); - private Paint paintOuter = new Paint(); - private Paint paintInnerCircle = new Paint(); private ColorFilter colorFilter; private ColorFilter grayFilter; @@ -57,21 +56,22 @@ public class FavoriteImageDrawable extends Drawable { favIcon = res.getDrawable(R.drawable.mm_special_star); uiIconId = R.drawable.mx_special_star; } - listDrawable = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() - .getIcon(uiIconId, R.color.color_white); - int backgroundTopIconId = getMapBackIconId(ctx, point, "top"); - int backgroundCenterIconId = getMapBackIconId(ctx, point, "center"); - int backgroundBottomIconId = getMapBackIconId(ctx, point, "bottom"); int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color; - favBackgroundTop = BitmapFactory.decodeResource(res, backgroundTopIconId); - favBackgroundCenter = BitmapFactory.decodeResource(res, backgroundCenterIconId); - favBackgroundBottom = BitmapFactory.decodeResource(res, backgroundBottomIconId); + uiListIcon = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() + .getIcon(uiIconId, R.color.color_white); + int uiBackgroundIconId = point != null ? point.getBackType().getIconId() : R.drawable.bg_point_circle; + uiBackgroundIcon = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() + .getPaintedIcon(uiBackgroundIconId, col); + int mapBackgroundIconIdTop = getMapBackIconId(ctx, point, "top"); + int mapBackgroundIconIdCenter = getMapBackIconId(ctx, point, "center"); + int mapBackgroundIconIdBottom = getMapBackIconId(ctx, point, "bottom"); + favBackgroundTop = BitmapFactory.decodeResource(res, mapBackgroundIconIdTop); + favBackgroundCenter = BitmapFactory.decodeResource(res, mapBackgroundIconIdCenter); + favBackgroundBottom = BitmapFactory.decodeResource(res, mapBackgroundIconIdBottom); syncedStroke = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_stroke); syncedColor = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_color); syncedShadow = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_shadow); syncedIcon = BitmapFactory.decodeResource(res, R.drawable.map_marker_point_14dp); - initSimplePaint(paintOuter, color == 0 || color == Color.BLACK ? 0x88555555 : color); - initSimplePaint(paintInnerCircle, col); colorFilter = new PorterDuffColorFilter(col, PorterDuff.Mode.SRC_IN); grayFilter = new PorterDuffColorFilter(res.getColor(R.color.color_favorite_gray), PorterDuff.Mode.MULTIPLY); } @@ -92,20 +92,14 @@ public class FavoriteImageDrawable extends Drawable { return R.drawable.map_white_favorite_shield; } - private void initSimplePaint(Paint paint, int color) { - paint.setAntiAlias(true); - paint.setStyle(Style.FILL_AND_STROKE); - paint.setColor(color); - } - @Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); Rect bs = new Rect(bounds); - //bs.inset((int) (4 * density), (int) (4 * density)); if (!withShadow && !synced) { - bs.inset(bs.width() / 4, bs.height() / 4); - listDrawable.setBounds(bs); + uiBackgroundIcon.setBounds(bounds); + bs.inset(bs.width() / 5, bs.height() / 5); + uiListIcon.setBounds(bs); } else if (withShadow) { bs.inset(bs.width() / 3, bs.height() / 3); favIcon.setBounds(bs); @@ -127,25 +121,26 @@ public class FavoriteImageDrawable extends Drawable { paintBackground.setColorFilter(history ? grayFilter : colorFilter); Rect bs = getBounds(); if (synced) { - canvas.drawBitmap(syncedShadow, bs.exactCenterX() - syncedShadow.getWidth() / 2f, bs.exactCenterY() - syncedShadow.getHeight() / 2f, paintBackground); - canvas.drawBitmap(syncedColor, bs.exactCenterX() - syncedColor.getWidth() / 2f, bs.exactCenterY() - syncedColor.getHeight() / 2f, paintBackground); - canvas.drawBitmap(syncedStroke, bs.exactCenterX() - syncedStroke.getWidth() / 2f, bs.exactCenterY() - syncedStroke.getHeight() / 2f, paintBackground); - canvas.drawBitmap(syncedIcon, bs.exactCenterX() - syncedIcon.getWidth() / 2f, bs.exactCenterY() - syncedIcon.getHeight() / 2f, paintIcon); + drawBitmap(canvas, bs, syncedShadow, paintBackground); + drawBitmap(canvas, bs, syncedColor, paintBackground); + drawBitmap(canvas, bs, syncedStroke, paintBackground); + drawBitmap(canvas, bs, syncedIcon, paintIcon); } else if (withShadow) { - canvas.drawBitmap(favBackgroundBottom, bs.exactCenterX() - favBackgroundBottom.getWidth() / 2f, bs.exactCenterY() - favBackgroundBottom.getHeight() / 2f, new Paint()); - canvas.drawBitmap(favBackgroundCenter, bs.exactCenterX() - favBackgroundCenter.getWidth() / 2f, bs.exactCenterY() - favBackgroundCenter.getHeight() / 2f, paintBackground); - canvas.drawBitmap(favBackgroundTop, bs.exactCenterX() - favBackgroundTop.getWidth() / 2f, bs.exactCenterY() - favBackgroundTop.getHeight() / 2f, new Paint()); + drawBitmap(canvas, bs, favBackgroundBottom, new Paint()); + drawBitmap(canvas, bs, favBackgroundCenter, paintBackground); + drawBitmap(canvas, bs, favBackgroundTop, new Paint()); favIcon.draw(canvas); } else { - int min = Math.min(bs.width(), bs.height()); - int r = (min * 4 / 10); - int rs = (r - 1); - canvas.drawCircle(min / 2, min / 2, r, paintOuter); - canvas.drawCircle(min / 2, min / 2, rs, paintInnerCircle); - listDrawable.draw(canvas); + uiBackgroundIcon.draw(canvas); + uiListIcon.draw(canvas); } } + public void drawBitmap(@NonNull Canvas canvas, Rect bs, Bitmap syncedShadow, Paint paintBackground) { + canvas.drawBitmap(syncedShadow, bs.exactCenterX() - syncedShadow.getWidth() / 2f, + bs.exactCenterY() - syncedShadow.getHeight() / 2f, paintBackground); + } + public void drawBitmapInCenter(Canvas canvas, float x, float y, boolean history) { this.history = history; float dx = x - getIntrinsicWidth() / 2f; @@ -157,7 +152,7 @@ public class FavoriteImageDrawable extends Drawable { @Override public int getOpacity() { - return 0; + return PixelFormat.UNKNOWN; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 9d8bd58b2d..e9d35620c6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -1282,7 +1282,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo int iconId = menu.getRightIconId(); int sizeId = menu.isBigRightIcon() ? R.dimen.context_menu_big_icon_size : R.dimen.map_widget_icon; if (menu.getPointDescription().isFavorite() || menu.getPointDescription().isWpt()) { - sizeId = R.dimen.dialog_button_height; + sizeId = R.dimen.favorites_icon_size; } int iconViewSize = getResources().getDimensionPixelSize(sizeId); ViewGroup.LayoutParams params = iconView.getLayoutParams(); From fe14dcee9136024b405dda93dda8f744b89a9081 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 3 Mar 2020 15:33:34 +0200 Subject: [PATCH 006/113] Add low zoom level icons --- .../osmand/plus/views/FavouritesLayer.java | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java index e6ad889b5f..393e95179b 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java @@ -31,6 +31,7 @@ import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback; import net.osmand.plus.views.MapTextLayer.MapTextProvider; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, @@ -39,22 +40,19 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. protected int startZoom = 6; protected OsmandMapTileView view; - private Paint paint; private FavouritesDbHelper favorites; private MapMarkersHelper mapMarkersHelper; protected List cache = new ArrayList<>(); private MapTextLayer textLayer; private Paint paintIcon; + private HashMap smallIconCache = new HashMap<>(); private Bitmap pointSmall; @ColorInt private int defaultColor; @ColorInt private int grayColor; - private OsmandSettings settings; - private ContextMenuLayer contextMenuLayer; - protected String getObjName() { return view.getContext().getString(R.string.favorite); } @@ -62,21 +60,27 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. @Override public void initLayer(OsmandMapTileView view) { this.view = view; - paint = new Paint(); - paint.setAntiAlias(true); - paint.setFilterBitmap(true); - paint.setDither(true); settings = view.getApplication().getSettings(); favorites = view.getApplication().getFavorites(); mapMarkersHelper = view.getApplication().getMapMarkersHelper(); textLayer = view.getLayerByClass(MapTextLayer.class); paintIcon = new Paint(); + for (FavouritePoint.BackType backType : FavouritePoint.BackType.values()) { + putBitmap(backType, "top"); + putBitmap(backType, "center"); + putBitmap(backType, "bottom"); + } pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small); defaultColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite); grayColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite_gray); contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class); } - + + private void putBitmap(FavouritePoint.BackType backType, String bottom) { + smallIconCache.put(backType.name() + bottom, BitmapFactory.decodeResource(view.getResources(), + getSmallIconID(bottom, backType.getIconId()))); + } + private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { return (Math.abs(objx - ex) <= radius * 1.5 && Math.abs(objy - ey) <= radius * 1.5) ; // return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ; @@ -87,14 +91,12 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. public void destroyLayer() { } - @Override public boolean drawInScreenPixels() { return true; } - @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { if (contextMenuLayer.getMoveableObject() instanceof FavouritePoint) { @@ -104,7 +106,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. drawBigPoint(canvas, objectInMotion, pf.x, pf.y, mapMarker); } } - + @Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { cache.clear(); @@ -145,8 +147,15 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. } else { color = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor(); } - paintIcon.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY)); - canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); + paintIcon.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)); + 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); + canvas.drawBitmap(pointSmallBottom, left, top, null); + canvas.drawBitmap(pointSmallCenter, left, top, paintIcon); + canvas.drawBitmap(pointSmallTop, left, top, null); smallObjectsLatLon.add(new LatLon(lat, lon)); } else { fullObjects.add(new Pair<>(o, marker)); @@ -171,6 +180,14 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. } + private Bitmap getBitmap(FavouritePoint o, String layer) { + Bitmap pointSmall = smallIconCache.get(o.getBackType().name() + layer); + if (pointSmall == null) { + pointSmall = this.pointSmall; + } + return pointSmall; + } + private void drawBigPoint(Canvas canvas, FavouritePoint o, float x, float y, @Nullable MapMarker marker) { FavoriteImageDrawable fid; boolean history = false; @@ -182,14 +199,19 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. } fid.drawBitmapInCenter(canvas, x, y, history); } - - + + private int getSmallIconID(String layer, int iconId) { + String iconName = view.getResources().getResourceEntryName(iconId); + return view.getResources().getIdentifier("map_" + iconName + "_" + layer + "_small" + , "drawable", view.getContext().getPackageName()); + } + @Override public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { return false; } - public void getFavoriteFromPoint(RotatedTileBox tb, PointF point, List res) { + private void getFavoriteFromPoint(RotatedTileBox tb, PointF point, List res) { int r = getDefaultRadiusPoi(tb); int ex = (int) point.x; int ey = (int) point.y; @@ -209,7 +231,6 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. } } - @Override public PointDescription getObjectName(Object o) { if(o instanceof FavouritePoint){ @@ -278,7 +299,6 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. return false; } - @Override public boolean isObjectMovable(Object o) { return o instanceof FavouritePoint; From 97f2f749e2fe98a32ef315608826aa3d69c61331 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 4 Mar 2020 19:08:42 +0200 Subject: [PATCH 007/113] Add name and description --- .../res/layout/new_point_editor_fragment.xml | 325 ++++++++++++++++++ OsmAnd/res/values/strings.xml | 4 + .../editors/PointEditorFragment.java | 122 ++++--- 3 files changed, 396 insertions(+), 55 deletions(-) create mode 100644 OsmAnd/res/layout/new_point_editor_fragment.xml diff --git a/OsmAnd/res/layout/new_point_editor_fragment.xml b/OsmAnd/res/layout/new_point_editor_fragment.xml new file mode 100644 index 0000000000..6ceac1df2b --- /dev/null +++ b/OsmAnd/res/layout/new_point_editor_fragment.xml @@ -0,0 +1,325 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +