Minor fixes

This commit is contained in:
Vitaliy 2020-08-20 17:29:38 +03:00
parent 0e2ffc4d84
commit b2b2064993
5 changed files with 82 additions and 79 deletions

View file

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

View file

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

View file

@ -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) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
FavouritesDbHelper helper = app.getFavorites();
String group = fav.getCategory();
if (helper != null && helper.getGroup(group) != null) {
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

View file

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

View file

@ -2,55 +2,76 @@ 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;
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;
public int getMinimumHeight() {
return original.getMinimumHeight();
}
@Override
public int getMinimumWidth() {
return original.getMinimumWidth();
}
@Override
public int getIntrinsicHeight() {
if (mDrawable != null) return mDrawable.getIntrinsicHeight(); else return 0;
return original.getIntrinsicHeight();
}
@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();
public int getIntrinsicWidth() {
return original.getIntrinsicWidth();
}
@Override
public void setAlpha(int i) {
if (mDrawable != null) mDrawable.setAlpha(i);
public void setChangingConfigurations(int configs) {
super.setChangingConfigurations(configs);
original.setChangingConfigurations(configs);
}
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) {
if (mDrawable != null) mDrawable.setColorFilter(colorFilter);
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 void setAlpha(int alpha) {
original.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
original.setColorFilter(cf);
}
@Override
public int getOpacity() {
if (mDrawable != null) return mDrawable.getOpacity(); else return PixelFormat.UNKNOWN;
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) {