diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 81e9d6a502..eca4245375 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"; private static final String BACKGROUND_TYPE_EXTENSION = "background"; - private static final String DEFAULT_BACKGROUND_TYPE = "CIRCLE"; + private static final String DEFAULT_BACKGROUND_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$ diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 779290ef22..bf7d0da095 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -93,10 +93,7 @@ public class FavouritePoint implements Serializable, LocationPoint { } public int getIconId() { - if (iconId == 0) { - return R.drawable.mx_special_star; - } - return iconId; + return iconId == 0 ? R.drawable.mx_special_star : iconId; } public String getIconEntryName(Context ctx) { @@ -201,10 +198,7 @@ public class FavouritePoint implements Serializable, LocationPoint { } public BackgroundType getBackgroundType() { - if (backgroundType == null) { - return BackgroundType.CIRCLE; - } - return backgroundType; + return backgroundType == null ? BackgroundType.CIRCLE : backgroundType; } public void setBackgroundType(BackgroundType backgroundType) { @@ -323,6 +317,19 @@ public class FavouritePoint implements Serializable, LocationPoint { public int getIconId() { return iconId; } + + public String getTypeName() { + return typeName; + } + + public static BackgroundType getByTypeName(String typeName, BackgroundType defaultValue) { + for (BackgroundType type : BackgroundType.values()) { + if (type.typeName.equals(typeName)) { + return type; + } + } + return defaultValue; + } } public static FavouritePoint fromWpt(@NonNull WptPt pt, @NonNull Context ctx) { @@ -344,7 +351,8 @@ public class FavouritePoint implements Serializable, LocationPoint { if (iconName != null) { fp.setIconIdFromName(ctx, iconName); } - fp.setBackgroundType(BackgroundType.valueOf((pt.getBackgroundType().toUpperCase()))); + BackgroundType backgroundType = BackgroundType.getByTypeName(pt.getBackgroundType(), BackgroundType.CIRCLE); + fp.setBackgroundType(backgroundType); return fp; } diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 6b28f8b5d7..d4e908a195 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -18,6 +18,7 @@ import androidx.annotation.NonNull; import net.osmand.GPXUtilities; import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.BackgroundType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -136,9 +137,9 @@ public class FavoriteImageDrawable extends Drawable { } } - 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 drawBitmap(@NonNull Canvas canvas, Rect bs, Bitmap bitmap, Paint paintBackground) { + canvas.drawBitmap(bitmap, bs.exactCenterX() - bitmap.getWidth() / 2f, + bs.exactCenterY() - bitmap.getHeight() / 2f, paintBackground); } public void drawBitmapInCenter(Canvas canvas, float x, float y, boolean history) { @@ -206,7 +207,7 @@ public class FavoriteImageDrawable extends Drawable { if (pt != null) { point = new FavouritePoint(pt.getLatitude(), pt.getLongitude(), pt.name, pt.category); point.setIconIdFromName(a, pt.getIconName()); - point.setBackgroundType(FavouritePoint.BackgroundType.valueOf(pt.getBackgroundType())); + point.setBackgroundType(BackgroundType.getByTypeName(pt.getBackgroundType(), BackgroundType.CIRCLE)); } return point; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragment.java index 244c923770..384024c54f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragment.java @@ -93,16 +93,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - if (autoFill) { - -// String name = favorite.getName() != null && !favorite.getName().isEmpty() ? -// favorite.getName() : getString(R.string.favorite_empty_place_name); -// -// String tostText = name + getString(R.string.favorite_autofill_toast_text) + group.name; -// -// Toast.makeText(getContext(), tostText, Toast.LENGTH_SHORT).show(); - save(true); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index 226c960282..816dd89d26 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -18,6 +18,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentActivity; import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.BackgroundType; import net.osmand.data.LatLon; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; @@ -43,7 +44,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { private int color; private int iconId; @NonNull - private FavouritePoint.BackgroundType backgroundType = FavouritePoint.BackgroundType.CIRCLE; + private BackgroundType backgroundType = BackgroundType.CIRCLE; @Nullable FavouritesDbHelper helper; @@ -118,16 +119,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - if (autoFill) { - -// String name = favorite.getName() != null && !favorite.getName().isEmpty() ? -// favorite.getName() : getString(R.string.favorite_empty_place_name); -// -// String tostText = name + getString(R.string.favorite_autofill_toast_text) + group.name; -// -// Toast.makeText(getContext(), tostText, Toast.LENGTH_SHORT).show(); - save(true); } } @@ -185,7 +177,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } @Override - public void setBackgroundType(@NonNull FavouritePoint.BackgroundType backgroundType) { + public void setBackgroundType(@NonNull BackgroundType backgroundType) { this.backgroundType = backgroundType; } @@ -281,7 +273,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } private void doSave(FavouritePoint favorite, String name, String category, String description, - @ColorInt int color, FavouritePoint.BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) { + @ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) { FavouritesDbHelper helper = getHelper(); FavoritePointEditor editor = getFavoritePointEditor(); if (editor != null && helper != null) { @@ -311,7 +303,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } private void doAddFavorite(String name, String category, String description, @ColorInt int color, - FavouritePoint.BackgroundType backgroundType, @DrawableRes int iconId) { + BackgroundType backgroundType, @DrawableRes int iconId) { OsmandApplication app = getMyApplication(); FavouritesDbHelper helper = getHelper(); FavouritePoint favorite = getFavorite(); @@ -414,7 +406,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { @Override @NonNull - public FavouritePoint.BackgroundType getBackgroundType() { + public BackgroundType getBackgroundType() { return backgroundType; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditor.java index 6661e505b8..7a71f8e760 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditor.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditor.java @@ -90,21 +90,14 @@ public abstract class PointEditor { if (mapActivity != null) { Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(getFragmentTag()); if (fragment != null) { - if (!checkNewUiFragment(fragment, name, color)) { //todo remove "if" after switch to new UI + if (fragment instanceof PointEditorFragment) { PointEditorFragment editorFragment = (PointEditorFragment) fragment; editorFragment.setCategory(name, color); + } else if (fragment instanceof PointEditorFragmentNew) { + PointEditorFragmentNew editorFragment = (PointEditorFragmentNew) fragment; + editorFragment.setCategory(name, color); } } } } - - //todo remove after switch to new UI - private boolean checkNewUiFragment(Fragment fragment, String name, int color) { - if (fragment instanceof PointEditorFragmentNew) { - PointEditorFragmentNew editorFragment = (PointEditorFragmentNew) fragment; - editorFragment.setCategory(name, color); - return true; - } - return false; - } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index 1673afc51a..0ace25c96b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -82,7 +82,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { private LinkedHashMap group; private OsmandApplication app; - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java index cf7a5638b4..99d6423f54 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java @@ -15,7 +15,7 @@ import androidx.fragment.app.DialogFragment; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; -import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.BackgroundType; import net.osmand.data.LatLon; import net.osmand.data.WptLocationPoint; import net.osmand.plus.GpxSelectionHelper; @@ -51,7 +51,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { protected boolean skipDialog; private String iconName; @NonNull - private String backgroundTypeName = FavouritePoint.BackgroundType.CIRCLE.name(); + private String backgroundTypeName = BackgroundType.CIRCLE.getTypeName(); private Map categoriesMap; private OsmandApplication app; @@ -357,7 +357,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { } @Override - public void setBackgroundType(FavouritePoint.BackgroundType backgroundType) { + public void setBackgroundType(BackgroundType backgroundType) { this.backgroundTypeName = backgroundType.name(); } @@ -419,8 +419,8 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { } @Override - public FavouritePoint.BackgroundType getBackgroundType() { - return FavouritePoint.BackgroundType.valueOf(backgroundTypeName); + public BackgroundType getBackgroundType() { + return BackgroundType.getByTypeName(backgroundTypeName, BackgroundType.CIRCLE); } @Override @@ -439,7 +439,13 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { @Override public int getCategoryColor(String category) { - return categoriesMap != null ? categoriesMap.get(category) : defaultColor; + if (categoriesMap != null) { + Integer color = categoriesMap.get(category); + if (color != null) { + return color; + } + } + return defaultColor; } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java index 396354a8c8..4aafbd8266 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavouritesLayer.java @@ -16,6 +16,7 @@ import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.BackgroundType; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; @@ -66,10 +67,10 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. mapMarkersHelper = view.getApplication().getMapMarkersHelper(); textLayer = view.getLayerByClass(MapTextLayer.class); paintIcon = new Paint(); - for (FavouritePoint.BackgroundType backgroundType : FavouritePoint.BackgroundType.values()) { - putBitmap(backgroundType, "top"); - putBitmap(backgroundType, "center"); - putBitmap(backgroundType, "bottom"); + for (BackgroundType backgroundType : BackgroundType.values()) { + putBitmapToIconCache(backgroundType, "top"); + putBitmapToIconCache(backgroundType, "center"); + putBitmapToIconCache(backgroundType, "bottom"); } pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small); defaultColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite); @@ -77,9 +78,9 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class); } - private void putBitmap(FavouritePoint.BackgroundType backgroundType, String bottom) { - smallIconCache.put(backgroundType.name() + bottom, BitmapFactory.decodeResource(view.getResources(), - getSmallIconID(bottom, backgroundType.getIconId()))); + private void putBitmapToIconCache(BackgroundType backgroundType, String layer) { + smallIconCache.put(backgroundType.getTypeName() + "_" + layer, BitmapFactory.decodeResource(view.getResources(), + getSmallIconId(layer, backgroundType.getIconId()))); } private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { @@ -182,7 +183,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. } private Bitmap getBitmap(FavouritePoint o, String layer) { - Bitmap pointSmall = smallIconCache.get(o.getBackgroundType().name() + layer); + Bitmap pointSmall = smallIconCache.get(o.getBackgroundType().getTypeName() + "_" + layer); if (pointSmall == null) { pointSmall = this.pointSmall; } @@ -201,7 +202,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer. fid.drawBitmapInCenter(canvas, x, y, history); } - private int getSmallIconID(String layer, int iconId) { + 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());