Add selected context menu image for aidl points
This commit is contained in:
parent
8e0c75456b
commit
6b1e59f50b
4 changed files with 135 additions and 21 deletions
|
@ -59,8 +59,10 @@ class TelegramApplication : Application(), OsmandHelperListener {
|
|||
}
|
||||
osmandAidlHelper.setUpdatesListener(object : UpdatesListener {
|
||||
override fun update() {
|
||||
if (settings.hasAnyChatToShowOnMap()) {
|
||||
showLocationHelper.startUpdateMessagesTask()
|
||||
}
|
||||
}
|
||||
})
|
||||
shareLocationHelper = ShareLocationHelper(this)
|
||||
showLocationHelper = ShowLocationHelper(this)
|
||||
|
|
|
@ -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,9 @@ 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 float POINT_SELECTED_IMAGE_VERTICAL_OFFSET = 0.99f;
|
||||
|
||||
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 +62,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;
|
||||
|
@ -68,10 +73,13 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
private MapTextLayer mapTextLayer;
|
||||
|
||||
private Map<String, Bitmap> pointImages = new ConcurrentHashMap<>();
|
||||
private Map<String, Bitmap> selectedPointImages = new ConcurrentHashMap<>();
|
||||
|
||||
private Set<String> imageRequests = new HashSet<>();
|
||||
private List<AMapPoint> displayedPoints = new ArrayList<>();
|
||||
|
||||
private AMapPoint selectedPoint;
|
||||
|
||||
public AidlMapLayer(MapActivity map, AMapLayer aidlLayer) {
|
||||
this.map = map;
|
||||
this.aidlLayer = aidlLayer;
|
||||
|
@ -106,6 +114,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);
|
||||
|
@ -116,6 +126,18 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||
AMapPoint aMapPoint = selectedPoint;
|
||||
if (aMapPoint != null && !contextMenuOpenForPoint(aMapPoint)) {
|
||||
ALatLon l = aMapPoint.getLocation();
|
||||
if (l != null) {
|
||||
int x = (int) tileBox.getPixXFromLatLon(l.getLatitude(), l.getLongitude());
|
||||
int y = (int) tileBox.getPixYFromLatLon(l.getLatitude(), l.getLongitude());
|
||||
if (tileBox.containsPoint(x, y, bigIconSize)) {
|
||||
Bitmap image = getPointImage(aMapPoint);
|
||||
drawPoint(canvas, x, y, tileBox, aMapPoint, image);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,6 +158,40 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
int x = (int) tileBox.getPixXFromLatLon(l.getLatitude(), l.getLongitude());
|
||||
int y = (int) tileBox.getPixYFromLatLon(l.getLatitude(), l.getLongitude());
|
||||
if (tileBox.containsPoint(x, y, bigIconSize)) {
|
||||
Bitmap image = getPointImage(point);
|
||||
displayedPoints.add(point);
|
||||
boolean contextMenuOpenForPoint = contextMenuOpenForPoint(point);
|
||||
if (contextMenuOpenForPoint) {
|
||||
selectedPoint = point;
|
||||
} else {
|
||||
if (selectedPoint != null && point.getId().equals(selectedPoint.getId())) {
|
||||
selectedPoint = null;
|
||||
}
|
||||
drawPoint(canvas, x, y, tileBox, point, image);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (imageRequests.size() > 0) {
|
||||
executeTaskInBackground(new PointImageReaderTask(this), imageRequests.toArray(new String[imageRequests.size()]));
|
||||
}
|
||||
mapTextLayer.putData(this, displayedPoints);
|
||||
}
|
||||
|
||||
public Bitmap getSelectedPointImage(String imageUri) {
|
||||
return selectedPointImages.get(imageUri);
|
||||
}
|
||||
|
||||
public float getSelectedPointImageVerticalOffset() {
|
||||
return 1 - POINT_IMAGE_VERTICAL_OFFSET;
|
||||
}
|
||||
|
||||
public String getLayerId() {
|
||||
return aidlLayer.getId();
|
||||
}
|
||||
|
||||
private Bitmap getPointImage(AMapPoint point) {
|
||||
Bitmap image = null;
|
||||
if (pointsType != PointsType.STANDARD) {
|
||||
String imageUri = point.getParams().get(AMapPoint.POINT_IMAGE_URI_PARAM);
|
||||
|
@ -146,16 +202,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
}
|
||||
}
|
||||
}
|
||||
displayedPoints.add(point);
|
||||
drawPoint(canvas, x, y, tileBox, point, image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (imageRequests.size() > 0) {
|
||||
executeTaskInBackground(new PointImageReaderTask(this), imageRequests.toArray(new String[imageRequests.size()]));
|
||||
}
|
||||
mapTextLayer.putData(this, displayedPoints);
|
||||
return image;
|
||||
}
|
||||
|
||||
private void drawPoint(Canvas canvas, int x, int y, RotatedTileBox tb, AMapPoint point, Bitmap image) {
|
||||
|
@ -177,19 +224,29 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
} else if (pointsType == PointsType.BIG_ICON) {
|
||||
bitmapPaint.setColorFilter(null);
|
||||
Bitmap bg = isStale(point) ? bigIconBgStale : bigIconBg;
|
||||
float vOffset = bg.getHeight() * 0.91f;
|
||||
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 boolean contextMenuOpenForPoint(AMapPoint point) {
|
||||
MapContextMenu mapContextMenu = map.getContextMenu();
|
||||
Object object = mapContextMenu.getObject();
|
||||
if (!mapContextMenu.isVisible() || !mapContextMenu.isActive() || !(object instanceof AMapPoint)) {
|
||||
return false;
|
||||
}
|
||||
AMapPoint oldPoint = (AMapPoint) object;
|
||||
return oldPoint.getLayerId().equals(getLayerId()) && oldPoint.getId().equals(point.getId());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private Rect getDstRect(int centerX, int centerY, int offset) {
|
||||
private static Rect getDstRect(int centerX, int centerY, int offset) {
|
||||
Rect rect = new Rect();
|
||||
rect.left = centerX - offset;
|
||||
rect.top = centerY - offset;
|
||||
|
@ -401,6 +458,9 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
bitmap = AndroidUtils.scaleBitmap(bitmap, layer.bigIconSize, layer.bigIconSize, false);
|
||||
}
|
||||
layer.pointImages.put(imageUriStr, bitmap);
|
||||
|
||||
Bitmap selectedImage = overlay(layer.bigIconBgSelected, bitmap, layer.bitmapPaint, layer.bigIconSize);
|
||||
layer.selectedPointImages.put(imageUriStr, selectedImage);
|
||||
res = true;
|
||||
}
|
||||
ims.close();
|
||||
|
@ -418,6 +478,18 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
|
|||
return res;
|
||||
}
|
||||
|
||||
private Bitmap overlay(Bitmap background, Bitmap image, Paint bitmapPaint, int bigIconSize) {
|
||||
Bitmap bmOverlay = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig());
|
||||
Canvas canvas = new Canvas(bmOverlay);
|
||||
|
||||
int imageCenterY = (int) ((bmOverlay.getHeight() / 2) * POINT_SELECTED_IMAGE_VERTICAL_OFFSET);
|
||||
|
||||
canvas.drawBitmap(background, 0, 0, bitmapPaint);
|
||||
canvas.drawBitmap(image, null, getDstRect(background.getWidth() / 2, imageCenterY, bigIconSize / 2), bitmapPaint);
|
||||
|
||||
return bmOverlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean res) {
|
||||
AidlMapLayer layer = layerRef.get();
|
||||
|
|
|
@ -8,6 +8,8 @@ import android.graphics.Canvas;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Vibrator;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -25,6 +27,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;
|
||||
|
@ -94,6 +97,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
private MapQuickActionLayer mapQuickActionLayer;
|
||||
|
||||
private ImageView contextMarker;
|
||||
private Drawable contextMenuPin;
|
||||
private Paint paint;
|
||||
private Paint outlinePaint;
|
||||
private Bitmap pressedBitmap;
|
||||
|
@ -138,13 +142,11 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
this.view = view;
|
||||
|
||||
Context context = view.getContext();
|
||||
contextMenuPin = ContextCompat.getDrawable(context, R.drawable.map_pin_context_menu);
|
||||
contextMarker = new ImageView(context);
|
||||
contextMarker.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
contextMarker.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.map_pin_context_menu));
|
||||
contextMarker.setClickable(true);
|
||||
int minw = contextMarker.getDrawable().getMinimumWidth();
|
||||
int minh = contextMarker.getDrawable().getMinimumHeight();
|
||||
contextMarker.layout(0, 0, minw, minh);
|
||||
updateContextMarkerIcon(contextMenuPin);
|
||||
|
||||
paint = new Paint();
|
||||
pressedBitmap = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap);
|
||||
|
@ -195,6 +197,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
|
||||
boolean markerCustomized = false;
|
||||
float vOffset = 0f;
|
||||
if (selectedObject != null) {
|
||||
TIntArrayList x = null;
|
||||
TIntArrayList y = null;
|
||||
|
@ -206,6 +210,20 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
RenderedObject r = (RenderedObject) selectedObject;
|
||||
x = r.getX();
|
||||
y = r.getY();
|
||||
} else if (selectedObject instanceof AMapPoint) {
|
||||
AMapPoint mapPoint = (AMapPoint) selectedObject;
|
||||
String imageUri = mapPoint.getParams().get(AMapPoint.POINT_IMAGE_URI_PARAM);
|
||||
if (!TextUtils.isEmpty(imageUri)) {
|
||||
AidlMapLayer aidlLayer = view.getAidlMapLayer(mapPoint.getLayerId());
|
||||
if (aidlLayer != null) {
|
||||
Bitmap selectedImage = aidlLayer.getSelectedPointImage(imageUri);
|
||||
if (selectedImage != null) {
|
||||
vOffset = selectedImage.getHeight() * aidlLayer.getSelectedPointImageVerticalOffset();
|
||||
updateContextMarkerIcon(new BitmapDrawable(activity.getResources(), selectedImage));
|
||||
markerCustomized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x != null && y != null && x.size() > 2) {
|
||||
double lat = MapUtils.get31LatitudeY(y.get(0));
|
||||
|
@ -252,8 +270,11 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
LatLon latLon = menu.getLatLon();
|
||||
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||
canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight());
|
||||
canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight() + vOffset);
|
||||
contextMarker.draw(canvas);
|
||||
if (markerCustomized) {
|
||||
updateContextMarkerIcon(contextMenuPin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -509,6 +530,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
view.refreshMap();
|
||||
}
|
||||
|
||||
private void updateContextMarkerIcon(Drawable icon){
|
||||
contextMarker.setImageDrawable(icon);
|
||||
int minw = contextMarker.getDrawable().getMinimumWidth();
|
||||
int minh = contextMarker.getDrawable().getMinimumHeight();
|
||||
contextMarker.layout(0, 0, minw, minh);
|
||||
}
|
||||
|
||||
private void enterMovingMode(RotatedTileBox tileBox) {
|
||||
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (vibrator != null) {
|
||||
|
|
|
@ -311,6 +311,18 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
return layers;
|
||||
}
|
||||
|
||||
public AidlMapLayer getAidlMapLayer(String layerId) {
|
||||
for (OsmandMapLayer layer : layers) {
|
||||
if (layer instanceof AidlMapLayer) {
|
||||
AidlMapLayer aidlMapLayer = (AidlMapLayer) layer;
|
||||
if (aidlMapLayer.getLayerId().equals(layerId)) {
|
||||
return aidlMapLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends OsmandMapLayer> T getLayerByClass(Class<T> cl) {
|
||||
for (OsmandMapLayer lr : layers) {
|
||||
|
|
Loading…
Reference in a new issue