Fix black color favorite icon.

This commit is contained in:
Dima-1 2020-05-06 18:17:42 +03:00
parent 7e550e683c
commit dfdd6d5729
18 changed files with 57 additions and 42 deletions

View file

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

View file

@ -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() {

View file

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

View file

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

View file

@ -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(),

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<RecyclerView.ViewHol
favouritesViewHolder.title.setText(favouritePoint.getDisplayName(app));
favouritesViewHolder.description.setText(favouritePoint.getCategoryDisplayName(app));
favouritesViewHolder.favouriteImage.setImageDrawable(
FavoriteImageDrawable.getOrCreate(app, favouritePoint.getColor(), false, favouritePoint));
FavoriteImageDrawable.getOrCreate(app,
app.getFavorites().getColorWithCategory(favouritePoint,
ContextCompat.getColor(app, R.color.color_favorite)), false, favouritePoint));
app.getUIUtilities().updateLocationView(cache, favouritesViewHolder.arrowImage, favouritesViewHolder.distance,
favouritePoint.getLatitude(), favouritePoint.getLongitude());
}

View file

@ -1,8 +1,8 @@
package net.osmand.plus.mapmarkers.adapters;
import android.content.Context;
import android.graphics.Color;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
@ -28,7 +28,7 @@ public class FavouritesGroupsAdapter extends GroupsAdapter {
} else if (holder instanceof MapMarkersGroupViewHolder) {
FavoriteGroup favoriteGroup = getItem(position);
MapMarkersGroupViewHolder markersGroupViewHolder = (MapMarkersGroupViewHolder) holder;
int color = favoriteGroup.getColor() == 0 || favoriteGroup.getColor() == Color.BLACK ? app.getResources().getColor(R.color.color_favorite) : favoriteGroup.getColor();
int color = favoriteGroup.getColor() == 0 ? ContextCompat.getColor(app, R.color.color_favorite) : favoriteGroup.getColor();
markersGroupViewHolder.icon.setImageDrawable(iconsCache.getPaintedIcon(R.drawable.ic_action_folder, color | 0xff000000));
markersGroupViewHolder.name.setText(favoriteGroup.getName().length() == 0 ? app.getString(R.string.shared_string_favorites) : favoriteGroup.getName());
markersGroupViewHolder.numberCount.setText(String.valueOf(favoriteGroup.getPoints().size()));

View file

@ -3,7 +3,6 @@ package net.osmand.plus.routepreparationmenu;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.SpannableString;
@ -656,8 +655,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
} else {
favoriteViewHolder.description.setText(point.getCategory());
}
int pointColor = point.getColor();
int color = pointColor == 0 || pointColor == Color.BLACK ? ContextCompat.getColor(app, R.color.color_favorite) : pointColor;
int color = app.getFavorites().getColorWithCategory(point, ContextCompat.getColor(app, R.color.color_favorite));
favoriteViewHolder.icon.setImageDrawable(app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_fav_dark, color));
}
favoriteViewHolder.description.setVisibility(View.VISIBLE);

View file

@ -1,10 +1,11 @@
package net.osmand.plus.search.listitems;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import androidx.core.content.ContextCompat;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.Amenity;
import net.osmand.data.City;
@ -374,10 +375,11 @@ public class QuickSearchListItem {
return getIcon(app, R.drawable.ic_action_world_globe);
case FAVORITE:
FavouritePoint fav = (FavouritePoint) searchResult.object;
return FavoriteImageDrawable.getOrCreate(app, fav.getColor(), false, fav);
return FavoriteImageDrawable.getOrCreate(app,
app.getFavorites().getColorWithCategory(fav, app.getResources().getColor(R.color.color_favorite)), false, fav);
case FAVORITE_GROUP:
FavoriteGroup group = (FavoriteGroup) searchResult.object;
int color = group.getColor() == 0 || group.getColor() == Color.BLACK ? app.getResources().getColor(R.color.color_favorite) : group.getColor();
int color = group.getColor() == 0 ? ContextCompat.getColor(app, R.color.color_favorite) : group.getColor();
return app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_fav_dark, color | 0xff000000);
case REGION:
return getIcon(app, R.drawable.ic_world_globe_dark);

View file

@ -147,7 +147,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
if (marker != null && marker.history) {
color = grayColor;
} else {
color = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor();
color = favorites.getColorWithCategory(o,defaultColor);
// color = o.getColor() == 0 ? defaultColor : o.getColor();
}
paintIcon.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
Bitmap pointSmallTop = getBitmap(o, "top");
@ -194,10 +195,10 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
FavoriteImageDrawable fid;
boolean history = false;
if (marker != null) {
fid = FavoriteImageDrawable.getOrCreateSyncedIcon(view.getContext(), o.getColor(), o);
fid = FavoriteImageDrawable.getOrCreateSyncedIcon(view.getContext(), favorites.getColorWithCategory(o,defaultColor), o);
history = marker.history;
} else {
fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor(), true, o);
fid = FavoriteImageDrawable.getOrCreate(view.getContext(), favorites.getColorWithCategory(o,defaultColor), true, o);
}
fid.drawBitmapInCenter(canvas, x, y, history);
}