colored icons bug fix
This commit is contained in:
parent
4e4ff2b0f5
commit
674995734b
3 changed files with 104 additions and 11 deletions
|
@ -5,10 +5,12 @@ import android.animation.AnimatorListenerAdapter;
|
|||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Build;
|
||||
|
@ -89,6 +91,7 @@ import net.osmand.plus.views.controls.SingleTapConfirm;
|
|||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||
import net.osmand.router.TransportRouteResult;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.view.GravityDrawable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -1824,22 +1827,32 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
line2Str.append(typeStr);
|
||||
|
||||
Drawable icon = menu.getTypeIcon();
|
||||
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
|
||||
line2, icon, null, null, null);
|
||||
if (icon != null){
|
||||
GravityDrawable gravityIcon = new GravityDrawable(icon);
|
||||
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
|
||||
line2, gravityIcon, null, null, null);
|
||||
}
|
||||
String groupName = convertDisplayNameToGroupIdName(requireContext(),
|
||||
menu.getTypeStr());
|
||||
if (menu.getMyApplication() != null){
|
||||
FavouritesDbHelper helper = menu.getMyApplication().getFavorites();
|
||||
if (helper != null){
|
||||
if (helper != null && helper.getGroup(groupName) != null){
|
||||
Drawable line2icon = helper.setColoredIconForGroup(groupName);
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(line2icon, null, null, null);
|
||||
GravityDrawable line2GravityDrawable =
|
||||
new GravityDrawable(line2icon);
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(
|
||||
line2GravityDrawable, null, null, null);
|
||||
}
|
||||
}
|
||||
line2.setCompoundDrawablePadding(dpToPx(5f));
|
||||
}
|
||||
if (menu.getPointDescription().isFavorite() &&
|
||||
menu.getObject() instanceof FavouritePoint){
|
||||
streetStr = ((FavouritePoint)menu.getObject()).getAddress();
|
||||
}
|
||||
if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) {
|
||||
if (line2Str.length() > 0) {
|
||||
line2Str.append(": ");
|
||||
line2Str.append(", ");
|
||||
}
|
||||
line2Str.append(streetStr);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,14 @@ import androidx.annotation.Nullable;
|
|||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.OsmAndConstants;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.view.GravityDrawable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -90,18 +93,35 @@ public class MultiSelectionArrayAdapter extends ArrayAdapter<MapMultiSelectionMe
|
|||
// Text line 2
|
||||
TextView line2 = (TextView) convertView.findViewById(R.id.context_menu_line2);
|
||||
((TextView) line2).setTextColor(ContextCompat.getColor(getContext(), R.color.ctx_menu_subtitle_color));
|
||||
line2.setText(item.getTypeStr());
|
||||
StringBuilder line2Str = new StringBuilder(item.getTypeStr());
|
||||
String streetStr = "";
|
||||
if (item.getPointDescription().isFavorite() &&
|
||||
item.getObject() instanceof FavouritePoint){
|
||||
streetStr = ((FavouritePoint)item.getObject()).getAddress();
|
||||
}
|
||||
if (!Algorithms.isEmpty(streetStr) && !item.displayStreetNameInTitle()) {
|
||||
if (line2Str.length() > 0) {
|
||||
line2Str.append(", ");
|
||||
}
|
||||
line2Str.append(streetStr);
|
||||
}
|
||||
line2.setText(line2Str);
|
||||
Drawable slIcon = item.getTypeIcon();
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
|
||||
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(menu.getMapActivity(), 5f));
|
||||
|
||||
GravityDrawable line2Icon = new GravityDrawable(slIcon);
|
||||
if (slIcon != null){
|
||||
line2Icon.setBoundsFrom(slIcon);
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(line2Icon, null, null, null);
|
||||
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(menu.getMapActivity(), 5f));
|
||||
}
|
||||
String groupName = convertDisplayNameToGroupIdName(getContext(),
|
||||
item.getTypeStr());
|
||||
if (item.getMyApplication() != null){
|
||||
FavouritesDbHelper helper = item.getMyApplication().getFavorites();
|
||||
if (helper != null){
|
||||
if (helper != null && helper.getGroup(groupName) != null){
|
||||
Drawable line2icon = helper.setColoredIconForGroup(groupName);
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(line2icon, null, null, null);
|
||||
GravityDrawable line2GravityIcon = new GravityDrawable(line2icon);
|
||||
line2GravityIcon.setBoundsFrom(line2icon);
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(line2GravityIcon, null, null, null);
|
||||
}
|
||||
}
|
||||
// Divider
|
||||
|
|
60
OsmAnd/src/net/osmand/view/GravityDrawable.java
Normal file
60
OsmAnd/src/net/osmand/view/GravityDrawable.java
Normal file
|
@ -0,0 +1,60 @@
|
|||
package net.osmand.view;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class GravityDrawable extends Drawable {
|
||||
|
||||
// inner Drawable
|
||||
private final Drawable mDrawable;
|
||||
|
||||
public GravityDrawable(Drawable drawable) {
|
||||
mDrawable = drawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
if (mDrawable != null) return mDrawable.getIntrinsicWidth(); else return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
if (mDrawable != null) return mDrawable.getIntrinsicHeight(); else return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
int halfCanvas= canvas.getHeight() / 2;
|
||||
int halfDrawable = mDrawable.getIntrinsicHeight() / 2;
|
||||
|
||||
// align to top
|
||||
canvas.save();
|
||||
canvas.translate(0, -halfCanvas + halfDrawable);
|
||||
mDrawable.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int i) {
|
||||
if (mDrawable != null) mDrawable.setAlpha(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(@Nullable ColorFilter colorFilter) {
|
||||
if (mDrawable != null) mDrawable.setColorFilter(colorFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
if (mDrawable != null) return mDrawable.getOpacity(); else return PixelFormat.UNKNOWN;
|
||||
}
|
||||
|
||||
public void setBoundsFrom(Drawable line2Icon) {
|
||||
line2Icon.setBounds(0, 0, line2Icon.getIntrinsicWidth(), line2Icon.getIntrinsicHeight());
|
||||
this.setBounds(0, 0, line2Icon.getIntrinsicWidth(), line2Icon.getIntrinsicHeight());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue