Minor fixes
This commit is contained in:
parent
0e2ffc4d84
commit
b2b2064993
5 changed files with 82 additions and 79 deletions
|
@ -130,10 +130,8 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
|
||||
public Drawable getColoredIconForGroup(String groupName) {
|
||||
FavouritesDbHelper.FavoriteGroup favoriteGroup = getGroup(
|
||||
FavouritesDbHelper.FavoriteGroup.
|
||||
convertDisplayNameToGroupIdName(
|
||||
context, groupName));
|
||||
String groupIdName = FavoriteGroup.convertDisplayNameToGroupIdName(context, groupName);
|
||||
FavoriteGroup favoriteGroup = getGroup(groupIdName);
|
||||
if (favoriteGroup != null) {
|
||||
int color = favoriteGroup.getColor() == 0 ?
|
||||
context.getResources().getColor(R.color.color_favorite) : favoriteGroup.getColor();
|
||||
|
|
|
@ -83,7 +83,6 @@ import net.osmand.plus.views.layers.TransportStopsLayer;
|
|||
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;
|
||||
|
@ -1817,16 +1816,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
if (!Algorithms.isEmpty(typeStr)) {
|
||||
line2Str.append(typeStr);
|
||||
Drawable icon = menu.getTypeIcon();
|
||||
if (icon != null) {
|
||||
if (menu.getTypeIcon() instanceof GravityDrawable) {
|
||||
GravityDrawable line2Icon = (GravityDrawable) menu.getTypeIcon();
|
||||
line2Icon.setBoundsFrom(icon);
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(line2Icon, null, null, null);
|
||||
} else {
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||
}
|
||||
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(requireContext(), 5f));
|
||||
}
|
||||
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(
|
||||
line2, icon, null, null, null);
|
||||
line2.setCompoundDrawablePadding(dpToPx(5f));
|
||||
}
|
||||
if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) {
|
||||
|
|
|
@ -161,20 +161,22 @@ public class FavouritePointMenuController extends MenuController {
|
|||
|
||||
@Override
|
||||
public Drawable getSecondLineTypeIcon() {
|
||||
if (this.getMapActivity() != null) {
|
||||
OsmandApplication app = this.getMapActivity().getMyApplication();
|
||||
if (app != null) {
|
||||
FavouritesDbHelper helper = app.getFavorites();
|
||||
String group = fav.getCategory();
|
||||
if (helper != null && helper.getGroup(group) != null) {
|
||||
Drawable line2icon = helper.getColoredIconForGroup(group);
|
||||
GravityDrawable gravityIcon = new GravityDrawable(line2icon);
|
||||
gravityIcon.setBoundsFrom(line2icon);
|
||||
return gravityIcon;
|
||||
}
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
FavouritesDbHelper helper = app.getFavorites();
|
||||
String group = fav.getCategory();
|
||||
if (helper.getGroup(group) != null) {
|
||||
Drawable line2icon = helper.getColoredIconForGroup(group);
|
||||
GravityDrawable gravityIcon = new GravityDrawable(line2icon);
|
||||
gravityIcon.setBoundsFrom(line2icon);
|
||||
return gravityIcon;
|
||||
} else {
|
||||
int colorId = isLight() ? R.color.icon_color_default_light : R.color.ctx_menu_bottom_view_icon_dark;
|
||||
return getIcon(R.drawable.ic_action_group_name_16, colorId);
|
||||
}
|
||||
}
|
||||
return getIcon(R.drawable.ic_action_group_name_16, isLight() ? R.color.icon_color_default_light : R.color.ctx_menu_bottom_view_icon_dark);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,7 +15,6 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.view.GravityDrawable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -94,16 +93,8 @@ public class MultiSelectionArrayAdapter extends ArrayAdapter<MapMultiSelectionMe
|
|||
}
|
||||
line2.setText(line2Str);
|
||||
Drawable slIcon = item.getTypeIcon();
|
||||
if (slIcon != null) {
|
||||
if (item.getTypeIcon() instanceof GravityDrawable) {
|
||||
GravityDrawable line2Icon = (GravityDrawable) item.getTypeIcon();
|
||||
line2Icon.setBoundsFrom(slIcon);
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(line2Icon, null, null, null);
|
||||
} else {
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
|
||||
}
|
||||
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(menu.getMapActivity(), 5f));
|
||||
}
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
|
||||
line2.setCompoundDrawablePadding(AndroidUtils.dpToPx(menu.getMapActivity(), 5f));
|
||||
// Divider
|
||||
View divider = convertView.findViewById(R.id.divider);
|
||||
divider.setBackgroundColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_divider_light : R.color.multi_selection_menu_divider_dark));
|
||||
|
|
|
@ -2,59 +2,80 @@ 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;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class GravityDrawable extends Drawable {
|
||||
|
||||
// inner Drawable
|
||||
private final Drawable mDrawable;
|
||||
// inner Drawable
|
||||
private final Drawable original;
|
||||
|
||||
public GravityDrawable(Drawable drawable) {
|
||||
mDrawable = drawable;
|
||||
}
|
||||
public GravityDrawable(@NonNull Drawable drawable) {
|
||||
this.original = drawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
if (mDrawable != null) return mDrawable.getIntrinsicWidth(); else return 0;
|
||||
}
|
||||
@Override
|
||||
public int getMinimumHeight() {
|
||||
return original.getMinimumHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
if (mDrawable != null) return mDrawable.getIntrinsicHeight(); else return 0;
|
||||
}
|
||||
@Override
|
||||
public int getMinimumWidth() {
|
||||
return original.getMinimumWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
int halfCanvas= canvas.getHeight() / 2;
|
||||
int halfDrawable = mDrawable.getIntrinsicHeight() / 2;
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return original.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
// align to top
|
||||
canvas.save();
|
||||
canvas.translate(0, -halfCanvas + halfDrawable);
|
||||
mDrawable.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return original.getIntrinsicWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int i) {
|
||||
if (mDrawable != null) mDrawable.setAlpha(i);
|
||||
}
|
||||
@Override
|
||||
public void setChangingConfigurations(int configs) {
|
||||
super.setChangingConfigurations(configs);
|
||||
original.setChangingConfigurations(configs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(@Nullable ColorFilter colorFilter) {
|
||||
if (mDrawable != null) mDrawable.setColorFilter(colorFilter);
|
||||
}
|
||||
@Override
|
||||
public void setBounds(int left, int top, int right, int bottom) {
|
||||
super.setBounds(left, top, right, bottom);
|
||||
original.setBounds(left, top, right, bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
if (mDrawable != null) return mDrawable.getOpacity(); else return PixelFormat.UNKNOWN;
|
||||
}
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
original.setAlpha(alpha);
|
||||
}
|
||||
|
||||
public void setBoundsFrom(Drawable line2Icon) {
|
||||
line2Icon.setBounds(0, 0, line2Icon.getIntrinsicWidth(), line2Icon.getIntrinsicHeight());
|
||||
this.setBounds(0, 0, line2Icon.getIntrinsicWidth(), line2Icon.getIntrinsicHeight());
|
||||
}
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
original.setColorFilter(cf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return original.getOpacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
int halfCanvas = canvas.getHeight() / 2;
|
||||
int halfDrawable = original.getIntrinsicHeight() / 2;
|
||||
|
||||
// align to top
|
||||
canvas.save();
|
||||
canvas.translate(0, -halfCanvas + halfDrawable);
|
||||
original.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
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