diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 6c5ead8955..2fe8a6e033 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -160,7 +160,7 @@ public class GPXUtilities { if (!Algorithms.isEmpty(colorString)) { if (colorString.charAt(0) == '#') { long color = Long.parseLong(colorString.substring(1), 16); - if (colorString.length() == 7) { + if (colorString.length() <= 7) { color |= 0x00000000ff000000; } else if (colorString.length() != 9) { return defColor; diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index f13872fa02..95236d4815 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -77,11 +77,7 @@ public class FavouritePoint implements Serializable, LocationPoint { } public int getColor() { - if ((color & 0xFF000000) != 0) { return color; - } else { - return color | 0xFF000000; - } } public String getAddress() { diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index ca8b6ad8f0..3decf9e607 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -102,11 +102,7 @@ public class FavouritesDbHelper { } public int getColor() { - if ((color & 0xFF000000) != 0) { return color; - } else { - return color | 0xFF000000; - } } public boolean isVisible() { @@ -132,6 +128,22 @@ public class FavouritesDbHelper { } } + public int getColorWithCategory(FavouritePoint point, int defaultColor) { + int color = 0; + if (point.getColor() != 0) { + color = point.getColor(); + } else { + FavoriteGroup favoriteGroup = getGroup(point); + if (favoriteGroup != null) { + color = favoriteGroup.getColor(); + } + if (color == 0) { + color = defaultColor; + } + } + return color; + } + public void loadFavorites() { flatGroups.clear(); favoriteGroups.clear(); diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java index 3347241e65..2b9b50fd7c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java @@ -232,7 +232,8 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA } ((TextView) row.findViewById(R.id.group_name)).setText(favorite.getCategory()); - icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, favorite.getColor(), false, favorite)); + icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, app.getFavorites().getColorWithCategory(favorite, + app.getResources().getColor(R.color.color_favorite)), false, favorite)); app.getUIUtilities().updateLocationView(cache, direction, distanceText, favorite.getLatitude(), favorite.getLongitude()); diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java index 34265a37b2..7faf328dad 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java @@ -462,7 +462,9 @@ public class FavoritesSearchFragment extends DialogFragment { TextView title = (TextView) view.findViewById(R.id.title); TextView subtitle = (TextView) view.findViewById(R.id.subtitle); - imageView.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, point.getColor(), false, point)); + imageView.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, + helper.getColorWithCategory(point, getResources().getColor(R.color.color_favorite)), + false, point)); title.setText(point.getDisplayName(app)); int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 2388e0ffe8..08b6b48361 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -3,7 +3,6 @@ package net.osmand.plus.activities; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.Drawable; @@ -838,7 +837,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen int enabledColor = light ? R.color.text_color_primary_light : R.color.text_color_primary_dark; int disabledColor = light ? R.color.text_color_secondary_light : R.color.text_color_secondary_dark; row.findViewById(R.id.group_divider).setVisibility(groupPosition == 0 ? View.GONE : View.VISIBLE); - int color = model.getColor() == 0 || model.getColor() == Color.BLACK ? getResources().getColor(R.color.color_favorite) : model.getColor(); + int color = model.getColor() == 0 ? getResources().getColor(R.color.color_favorite) : model.getColor(); if (!model.isPersonal()) { setCategoryIcon(app, app.getUIUtilities().getPaintedIcon( R.drawable.ic_action_folder, visible ? color : getResources().getColor(disabledColor)), @@ -958,13 +957,13 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen if (model.isAddressSpecified()) { distanceText.setText(String.format(getString(R.string.ltr_or_rtl_combine_via_comma), distance.trim(), model.getAddress())); } + int color = visible + ? app.getFavorites().getColorWithCategory(model, getResources().getColor(R.color.color_favorite)) + : ContextCompat.getColor(app, disabledIconColor); if(model.getBackgroundType().equals(FavouritePoint.BackgroundType.CIRCLE)){ - int color = visible ? model.getColor() : getResources().getColor(disabledIconColor); - int col = color == 0 || color == Color.BLACK ? getResources().getColor(R.color.color_favorite) : color; - icon.setImageDrawable(UiUtilities.createTintedDrawable(getActivity(),model.getIconId(),col)); + icon.setImageDrawable(UiUtilities.createTintedDrawable(getActivity(), model.getIconId(), color)); }else { - icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), - visible ? model.getColor() : getResources().getColor(disabledIconColor), false, model)); + icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), color, false, model)); } if (visible) { distanceText.setTextColor(getResources().getColor(R.color.color_distance)); diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 490e7c538f..5999468241 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -5,7 +5,6 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PorterDuff; @@ -58,7 +57,7 @@ public class FavoriteImageDrawable extends Drawable { 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; + int col = color == 0 ? res.getColor(R.color.color_favorite) : color; uiListIcon = uiUtilities.getIcon(uiIconId, R.color.color_white); int uiBackgroundIconId = point != null ? point.getBackgroundType().getIconId() : R.drawable.bg_point_circle; uiBackgroundIcon = uiUtilities.getPaintedIcon(uiBackgroundIconId, col); diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 7f51847964..9946692ae9 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -773,7 +773,9 @@ public class WaypointHelper { } } else if (type == FAVORITES ) { - return FavoriteImageDrawable.getOrCreate(uiCtx, point.getColor(), false, (FavouritePoint) point); + return FavoriteImageDrawable.getOrCreate(uiCtx, + app.getFavorites().getColorWithCategory((FavouritePoint) point, + app.getResources().getColor(R.color.color_favorite)), false, (FavouritePoint) point); } else if (type == WAYPOINTS) { if (point instanceof WptLocationPoint) { return FavoriteImageDrawable.getOrCreate(uiCtx, point.getColor(), false, ((WptLocationPoint) point).getPt()); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 4e4dd22668..a2eb9efe1c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -1,7 +1,6 @@ package net.osmand.plus.mapcontextmenu.builders; import android.content.Context; -import android.graphics.Color; import android.view.View; import android.widget.LinearLayout; @@ -93,7 +92,7 @@ public class FavouritePointMenuBuilder extends MenuBuilder { FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav); List groupFavourites = favoriteGroup.getPoints(); if (groupFavourites.size() > 0) { - int color = favoriteGroup.getColor() == 0 || favoriteGroup.getColor() == Color.BLACK ? view.getResources().getColor(R.color.color_favorite) : favoriteGroup.getColor(); + int color = favoriteGroup.getColor() == 0 ? view.getResources().getColor(R.color.color_favorite) : favoriteGroup.getColor(); int disabledColor = light ? R.color.text_color_secondary_light : R.color.text_color_secondary_dark; color = favoriteGroup.isVisible() ? (color | 0xff000000) : view.getResources().getColor(disabledColor); String name = view.getContext().getString(R.string.context_menu_points_of_group); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java index c62e72a566..59d649d362 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.controllers; import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import net.osmand.data.Amenity; @@ -125,8 +126,9 @@ public class FavouritePointMenuController extends MenuController { public Drawable getRightIcon() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - return FavoriteImageDrawable.getOrCreate(mapActivity.getMyApplication(), fav.getColor(), - false, fav); + return FavoriteImageDrawable.getOrCreate(mapActivity.getMyApplication(), + mapActivity.getMyApplication().getFavorites().getColorWithCategory(fav, + ContextCompat.getColor(mapActivity, R.color.color_favorite)), false, fav); } else { return null; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index 304360dede..0986437dc0 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -425,10 +425,10 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { FavouritePoint favorite = getFavorite(); int color = favorite != null ? getColor() : 0; FavoriteGroup group = getGroup(); - if (group != null && (color == 0 || color == 0xFF000000)) { + if (group != null && (color == 0)) { color = group.getColor(); } - if (color == 0 || color == 0xFF000000) { + if (color == 0) { color = defaultColor; } 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 99aa0a666d..8364f64ddb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -4,7 +4,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; -import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Build; @@ -832,7 +831,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { final String group = items.get(position); holder.groupName.setText(group); int categoryColor = getCategoryColor(group); - int color = categoryColor == 0 || categoryColor == Color.BLACK ? getDefaultColor() : categoryColor; + int color = categoryColor == 0 ? getDefaultColor() : categoryColor; holder.groupIcon.setImageDrawable(UiUtilities.tintDrawable( ContextCompat.getDrawable(app, R.drawable.ic_action_folder), color)); holder.pointsCounter.setText(String.valueOf(getCategoryPointsCount(group))); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java index 0dfa444a8e..be307b8aea 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java @@ -122,7 +122,7 @@ public class SelectCategoryDialogFragment extends DialogFragment { private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor) { View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_category_dialog_item, null); Button button = (Button)itemView.findViewById(R.id.button); - if (categoryColor != 0 & categoryColor != Color.BLACK) { + if (categoryColor != 0) { button.setCompoundDrawablesWithIntrinsicBounds( getIcon(activity, R.drawable.ic_action_folder, categoryColor), null, null, null); } else { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java index cb9f9d0d7b..94ac032e63 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java @@ -6,6 +6,7 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import net.osmand.data.FavouritePoint; @@ -46,7 +47,9 @@ public class FavouritesAdapter extends RecyclerView.Adapter