Merge pull request #6993 from osmandapp/TrackerImprovements

Tracker selected pin in context menu
This commit is contained in:
Alexey 2019-05-29 19:24:27 +03:00 committed by GitHub
commit 86a6ac085f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 12 deletions

View file

@ -59,7 +59,9 @@ class TelegramApplication : Application(), OsmandHelperListener {
}
osmandAidlHelper.setUpdatesListener(object : UpdatesListener {
override fun update() {
showLocationHelper.startUpdateMessagesTask()
if (settings.hasAnyChatToShowOnMap()) {
showLocationHelper.startUpdateMessagesTask()
}
}
})
shareLocationHelper = ShareLocationHelper(this)

View file

@ -24,6 +24,7 @@ import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
@ -40,6 +41,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider, MapTextLayer.MapTextProvider<AMapPoint> {
private static final float POINT_IMAGE_VERTICAL_OFFSET = 0.91f;
private static final int POINT_OUTER_COLOR = 0x88555555;
private static final float START_ZOOM = 7;
private static final int SMALL_ICON_SIZE_DP = 20;
@ -58,6 +61,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
private Bitmap smallIconBg;
private Bitmap bigIconBg;
private Bitmap bigIconBgStale;
private Bitmap bigIconBgSelected;
private Bitmap placeholder;
private int smallIconSize;
@ -106,6 +110,8 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
? R.drawable.map_pin_user_location_night : R.drawable.map_pin_user_location_day);
bigIconBgStale = BitmapFactory.decodeResource(res, night
? R.drawable.map_pin_user_stale_location_night : R.drawable.map_pin_user_stale_location_day);
bigIconBgSelected = BitmapFactory.decodeResource(res, night
? R.drawable.map_pin_user_location_selected_night : R.drawable.map_pin_user_location_selected_day);
placeholder = BitmapFactory.decodeResource(res, R.drawable.img_user_picture);
smallIconSize = AndroidUtils.dpToPx(map, SMALL_ICON_SIZE_DP);
@ -130,6 +136,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
String selectedPointId = getSelectedContextMenuPointId();
for (AMapPoint point : aidlLayer.getPoints()) {
ALatLon l = point.getLocation();
if (l != null) {
@ -147,7 +154,8 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
}
}
displayedPoints.add(point);
drawPoint(canvas, x, y, tileBox, point, image);
boolean selected = selectedPointId != null && selectedPointId.equals(point.getId());
drawPoint(canvas, x, y, tileBox, point, image, selected);
}
}
}
@ -158,11 +166,13 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
mapTextLayer.putData(this, displayedPoints);
}
private void drawPoint(Canvas canvas, int x, int y, RotatedTileBox tb, AMapPoint point, Bitmap image) {
private void drawPoint(Canvas canvas, int x, int y, RotatedTileBox tb, AMapPoint point, Bitmap image, boolean selected) {
if (image == null) {
image = placeholder;
}
if (pointsType == PointsType.STANDARD) {
if (selected) {
drawBigIcon(canvas, x, y, image, bigIconBgSelected);
} else if (pointsType == PointsType.STANDARD) {
int radius = getRadiusPoi(tb);
float density = tb.getDensity();
pointInnerCircle.setColor(point.getColor());
@ -175,15 +185,29 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
bitmapPaint.setColorFilter(null);
canvas.drawBitmap(image, null, getDstRect(x, y, smallIconSize / 2), bitmapPaint);
} else if (pointsType == PointsType.BIG_ICON) {
bitmapPaint.setColorFilter(null);
Bitmap bg = isStale(point) ? bigIconBgStale : bigIconBg;
float vOffset = bg.getHeight() * 0.91f;
int imageCenterY = (int) (y - vOffset + bg.getHeight() / 2);
canvas.drawBitmap(bg, x - bg.getWidth() / 2, y - vOffset, bitmapPaint);
canvas.drawBitmap(image, null, getDstRect(x, imageCenterY, bigIconSize / 2), bitmapPaint);
drawBigIcon(canvas, x, y, image, bg);
}
}
private void drawBigIcon(Canvas canvas, int x, int y, Bitmap image, Bitmap bg) {
bitmapPaint.setColorFilter(null);
float vOffset = bg.getHeight() * POINT_IMAGE_VERTICAL_OFFSET;
int imageCenterY = (int) (y - vOffset + bg.getHeight() / 2);
canvas.drawBitmap(bg, x - bg.getWidth() / 2, y - vOffset, bitmapPaint);
canvas.drawBitmap(image, null, getDstRect(x, imageCenterY, bigIconSize / 2), bitmapPaint);
}
private String getSelectedContextMenuPointId() {
MapContextMenu mapContextMenu = map.getContextMenu();
Object object = mapContextMenu.getObject();
if (mapContextMenu.isVisible() && object instanceof AMapPoint) {
AMapPoint aMapPoint = (AMapPoint) object;
return aMapPoint.getId();
}
return null;
}
private void drawColoredBitmap(Canvas canvas, int x, int y, Bitmap bitmap, int color) {
bitmapPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
canvas.drawBitmap(bitmap, x - bitmap.getWidth() / 2, y - bitmap.getHeight() / 2, bitmapPaint);

View file

@ -25,6 +25,7 @@ import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.NativeLibrary.RenderedObject;
import net.osmand.RenderingContext;
import net.osmand.aidl.maplayer.point.AMapPoint;
import net.osmand.core.android.MapRendererView;
import net.osmand.core.jni.AmenitySymbolsProvider.AmenitySymbolsGroup;
import net.osmand.core.jni.AreaI;
@ -195,6 +196,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
@Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
boolean markerCustomized = false;
if (selectedObject != null) {
TIntArrayList x = null;
TIntArrayList y = null;
@ -206,11 +208,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
RenderedObject r = (RenderedObject) selectedObject;
x = r.getX();
y = r.getY();
} else if (selectedObject instanceof AMapPoint) {
markerCustomized = true;
}
if (x != null && y != null && x.size() > 2) {
double lat = MapUtils.get31LatitudeY(y.get(0));
double lon = MapUtils.get31LongitudeX(x.get(0));
int px,py, prevX, prevY;
int px, py, prevX, prevY;
prevX = (int) box.getPixXFromLatLon(lat, lon);
prevY = (int) box.getPixYFromLatLon(lat, lon);
for (int i = 1; i < x.size(); i++) {
@ -235,7 +239,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
canvas.drawBitmap(pressedBitmap, x - pressedBitmap.getWidth() / 2, y - pressedBitmap.getHeight() / 2, paint);
}
if (mapQuickActionLayer!= null && mapQuickActionLayer.isInMovingMarkerMode())
if (mapQuickActionLayer != null && mapQuickActionLayer.isInMovingMarkerMode())
return;
if (mInChangeMarkerPositionMode) {
@ -248,7 +252,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight());
contextMarker.draw(canvas);
mAddGpxPointBottomSheetHelper.onDraw(box);
} else if (menu.isActive()) {
} else if (menu.isActive() && !markerCustomized) {
LatLon latLon = menu.getLatLon();
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());