Revert fav/wpt icon. Fix fav's visibility on small zooms

This commit is contained in:
Alexey Kulish 2015-12-11 16:44:17 +03:00
parent b14e285e76
commit e64db571e3
3 changed files with 79 additions and 73 deletions

View file

@ -13,7 +13,7 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import net.osmand.plus.R;
import java.util.TreeMap;
@ -35,41 +35,33 @@ public class FavoriteImageDrawable extends Drawable {
this.withShadow = withShadow;
this.resources = ctx.getResources();
this.color = color;
paintIcon = new Paint();
int col = color == 0 || color == Color.BLACK ? getResources().getColor(R.color.color_favorite) : color;
paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.SRC_IN));
paintBackground = new Paint();
int col = color == 0 || color == Color.BLACK ? getResources().getColor(R.color.color_favorite) : color;
paintBackground.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
paintIcon = new Paint();
favIcon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_favorite);
favBackground = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_white_favorite_shield);
listDrawable = getResources().getDrawable(R.drawable.ic_action_fav_dark).mutate();
listDrawable.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.SRC_IN));
DisplayMetrics metrics = getResources().getDisplayMetrics();
paintOuter = new Paint();
paintOuter.setAntiAlias(true);
paintOuter.setStyle(Style.FILL_AND_STROKE);
paintInnerCircle = new Paint();
paintInnerCircle.setStyle(Style.FILL_AND_STROKE);
if(metrics != null && metrics.density > 0) {
paintOuter.setStrokeWidth(metrics.density * 1);
} else {
paintOuter.setStrokeWidth(1);
}
// paintOuter.setColor(color == 0 || color == Color.BLACK ? 0x88555555 : color);
paintOuter.setColor(0xffbbbbbb);
paintInnerCircle.setColor(Color.WHITE);
paintOuter.setColor(color == 0 || color == Color.BLACK ? 0x88555555 : color);
paintInnerCircle.setColor(color == 0 || color == Color.BLACK ? getResources().getColor(R.color.color_favorite)
: color);
paintInnerCircle.setAntiAlias(true);
}
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
if (!withShadow) {
Rect bs = new Rect(bounds);
//bs.inset((int) (4 * density), (int) (4 * density));
bs.inset(bs.width() / 4, (int) bs.height() / 4);
//bs.inset((int) (4 * density), (int) (4 * density));
bs.inset(bs.width() / 4, bs.height() / 4);
listDrawable.setBounds(bs);
}
}
@ -100,8 +92,8 @@ public class FavoriteImageDrawable extends Drawable {
canvas.drawBitmap(favIcon, bs.exactCenterX() - favIcon.getWidth() / 2f, bs.exactCenterY() - favIcon.getHeight() / 2f, paintIcon);
} else {
int min = Math.min(bs.width(), bs.height());
int r = (int) (min * 4 / 10);
int rs = (int) (r - 1);
int r = (min * 4 / 10);
int rs = (r - 1);
canvas.drawCircle(min / 2, min / 2, r, paintOuter);
canvas.drawCircle(min / 2, min / 2, rs, paintInnerCircle);
listDrawable.draw(canvas);
@ -152,4 +144,4 @@ public class FavoriteImageDrawable extends Drawable {
}
return drawable;
}
}
}

View file

@ -3,8 +3,11 @@ package net.osmand.plus.views;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
@ -25,7 +28,7 @@ import java.util.List;
public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, MapTextProvider<LocationPoint> {
protected int startZoom = 6;
protected OsmandMapTileView view;
private Paint paint;
private FavouritesDbHelper favorites;
@ -33,21 +36,22 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
private MapTextLayer textLayer;
private Paint paintIcon;
private Bitmap pointSmall;
private int defaultColor;
private OsmandSettings settings;
protected Class<? extends LocationPoint> getFavoriteClass() {
return (Class<? extends LocationPoint>) FavouritePoint.class;
}
protected String getObjName() {
return view.getContext().getString(R.string.favorite);
}
protected List<? extends LocationPoint> getPoints() {
return favorites.getFavouritePoints();
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
@ -60,8 +64,9 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
textLayer = view.getLayerByClass(MapTextLayer.class);
paintIcon = new Paint();
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
defaultColor = view.getResources().getColor(R.color.color_favorite);
}
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
return (Math.abs(objx - ex) <= radius * 2 && Math.abs(objy - ey) <= radius * 2) ;
// return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ;
@ -70,37 +75,42 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return true;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
cache.clear();
if (this.settings.SHOW_FAVORITES.get()) {
if (tileBox.getZoom() >= startZoom) {
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
true).getIntrinsicWidth() * 3 / 2.5f;
true).getIntrinsicWidth() * 3 / 2.5f;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
// request to load
final QuadRect latLonBounds = tileBox.getLatLonBounds();
List<LocationPoint> fullObjects = new ArrayList<>();
for (LocationPoint o : getPoints()) {
if (!o.isVisible()) {
continue;
}
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
int col = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor();
paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
} else {
fullObjects.add(o);
@ -130,8 +140,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
// y - favoriteIcon.getHeight(), paint);
}
}
@Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
return false;
@ -147,8 +157,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
}
private void getFavFromPoint(RotatedTileBox tb, List<? super LocationPoint> res, int r, int ex, int ey,
LocationPoint n) {
if (n.isVisible()) {
LocationPoint n) {
if (n.isVisible()) {
int x = (int) tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude());
int y = (int) tb.getPixYFromLatLon(n.getLatitude(), n.getLongitude());
if (calculateBelongs(ex, ey, x, y, r)) {
@ -166,8 +176,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
return null;
}
@Override
public PointDescription getObjectName(Object o) {
if(o instanceof LocationPoint){
@ -215,7 +225,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
public String getText(LocationPoint o) {
return PointDescription.getSimpleName(o, view.getContext());
}
}

View file

@ -10,6 +10,7 @@ import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.NonNull;
@ -42,11 +43,11 @@ import java.util.List;
import gnu.trove.list.array.TIntArrayList;
public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
MapTextProvider<WptPt> {
public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
MapTextProvider<WptPt> {
private OsmandMapTileView view;
private Paint paint;
private Paint paint2;
private boolean isPaint2;
@ -61,7 +62,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private static final int startZoom = 7;
private GpxSelectionHelper selectedGpxHelper;
private Paint paintBmp;
private List<WptPt> cache = new ArrayList<WptPt>();
@ -79,7 +80,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private List<TrkSegment> points;
private GPXFile gpx;
private void initUI() {
paint = new Paint();
paint.setStyle(Style.STROKE);
@ -93,21 +94,21 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
paint_1 = new Paint();
paint_1.setStyle(Style.STROKE);
paint_1.setAntiAlias(true);
paintBmp = new Paint();
paintBmp.setAntiAlias(true);
paintBmp.setFilterBitmap(true);
paintBmp.setDither(true);
paintTextIcon = new Paint();
paintTextIcon.setTextSize(10 * view.getDensity());
paintTextIcon.setTextAlign(Align.CENTER);
paintTextIcon.setFakeBoldText(true);
paintTextIcon.setColor(Color.BLACK);
paintTextIcon.setAntiAlias(true);
textLayer = view.getLayerByClass(MapTextLayer.class);
paintOuter = new Paint();
@ -122,7 +123,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
paintIcon = new Paint();
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
}
@Override
public void initLayer(OsmandMapTileView view) {
@ -132,11 +133,11 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
initUI();
}
public void updateLayerStyle() {
cachedHash = -1;
}
private int updatePaints(int color, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox){
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
final boolean isNight = nightMode != null && nightMode.isNightMode();
@ -195,7 +196,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
paint.setColor(color == 0 ? cachedColor : color);
return cachedColor;
}
private int calculateHash(Object... o) {
return Arrays.hashCode(o);
}
@ -220,9 +221,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
}
}
private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles,
DrawSettings settings) {
private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles,
DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
// request to load
for (SelectedGpxFile g : selectedGPXFiles) {
@ -240,7 +241,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private void drawSplitItems(Canvas canvas, RotatedTileBox tileBox, List<GpxDisplayItem> items, DrawSettings settings) {
final QuadRect latLonBounds = tileBox.getLatLonBounds();
int r = (int) (12 * tileBox.getDensity());
int dr = r * 3 / 2;
int dr = r * 3 / 2;
int px = -1;
int py = -1;
for(int k = 0; k < items.size(); k++) {
@ -294,6 +295,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
boolean visit = isPointVisited(o);
int col = visit ? visitedColor : o.getColor(fcolor);
paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
} else {
fullObjects.add(o);
@ -313,7 +317,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox,
List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
for (SelectedGpxFile g : selectedGPXFiles) {
List<TrkSegment> points = g.getPointsToDisplay();
boolean routePoints = g.isRoutePoints();
@ -346,8 +350,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
for (TrkSegment l : points) {
int startIndex = -1;
int endIndex = -1;
int prevCross = 0;
double shift = 0;
int prevCross = 0;
double shift = 0;
for (int i = 0; i < l.points.size(); i++) {
WptPt ls = l.points.get(i);
int cross = 0;
@ -376,13 +380,13 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
private void drawSegment(Canvas canvas, RotatedTileBox tb, TrkSegment l, int startIndex, int endIndex) {
TIntArrayList tx = new TIntArrayList();
TIntArrayList ty = new TIntArrayList();
@ -414,10 +418,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
canvas.drawPath(path, paint2);
}
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
}
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
return (Math.abs(objx - ex) <= radius * 2 && Math.abs(objy - ey) <= radius * 2) ;
// return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ;
@ -447,7 +451,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
return null;
}
@Override
public PointDescription getObjectName(Object o) {
if(o instanceof WptPt){
@ -478,11 +482,11 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
return null;
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
@ -518,4 +522,4 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
}