Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - increase touch target to match largest Marker icon (#9565)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 21, 2017
1 parent a39b4cf commit 820c04e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,12 @@ private void handleClickForShapeAnnotation(long shapeAnnotationId) {
}

private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) {
int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2;
int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2;
final RectF tapRect = new RectF(tapPoint.x - averageIconWidthOffset,
tapPoint.y - averageIconHeightOffset,
tapPoint.x + averageIconWidthOffset,
tapPoint.y + averageIconHeightOffset
int touchSurfaceWidth = (int) (iconManager.getHighestIconHeight() * 1.5);
int touchSurfaceHeight = (int) (iconManager.getHighestIconWidth() * 1.5);
final RectF tapRect = new RectF(tapPoint.x - touchSurfaceWidth,
tapPoint.y - touchSurfaceHeight,
tapPoint.x + touchSurfaceWidth,
tapPoint.y + touchSurfaceHeight
);
return new MarkerHit(tapRect, getMarkersInRect(tapRect));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;

/**
* Responsible for managing icons added to the Map.
* <p>
Expand All @@ -30,8 +28,8 @@ class IconManager {
private NativeMapView nativeMapView;
private List<Icon> icons;

private int averageIconHeight;
private int averageIconWidth;
private int highestIconWidth;
private int highestIconHeight;

IconManager(NativeMapView nativeMapView) {
this.nativeMapView = nativeMapView;
Expand All @@ -47,7 +45,7 @@ Icon loadIconForMarker(Marker marker) {
// TODO we can move this code afterwards to getIcon as with MarkerView.getIcon
icon = loadDefaultIconForMarker(marker);
} else {
updateAverageIconSize(icon);
updateHighestIconSize(icon);
}
addIcon(icon);
return icon;
Expand All @@ -56,26 +54,26 @@ Icon loadIconForMarker(Marker marker) {
void loadIconForMarkerView(MarkerView marker) {
Icon icon = marker.getIcon();
Bitmap bitmap = icon.getBitmap();
updateAverageIconSize(bitmap);
updateHighestIconSize(bitmap);
addIcon(icon, false);
}

int getTopOffsetPixelsForIcon(Icon icon) {
return (int) (nativeMapView.getTopOffsetPixelsForAnnotationSymbol(icon.getId()) * nativeMapView.getPixelRatio());
}

int getAverageIconHeight() {
return averageIconHeight;
int getHighestIconWidth() {
return highestIconWidth;
}

int getAverageIconWidth() {
return averageIconWidth;
int getHighestIconHeight() {
return highestIconHeight;
}

private Icon loadDefaultIconForMarker(Marker marker) {
Icon icon = IconFactory.getInstance(Mapbox.getApplicationContext()).defaultMarker();
Bitmap bitmap = icon.getBitmap();
updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight() / 2);
updateHighestIconSize(bitmap.getWidth(), bitmap.getHeight() / 2);
marker.setIcon(icon);
return icon;
}
Expand All @@ -95,20 +93,22 @@ private void addIcon(Icon icon, boolean addIconToMap) {
}
}

private void updateAverageIconSize(Icon icon) {
updateAverageIconSize(icon.getBitmap());
private void updateHighestIconSize(Icon icon) {
updateHighestIconSize(icon.getBitmap());
}

private void updateAverageIconSize(Bitmap bitmap) {
updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight());
private void updateHighestIconSize(Bitmap bitmap) {
updateHighestIconSize(bitmap.getWidth(), bitmap.getHeight());
}

private void updateAverageIconSize(int width, int height) {
int iconSize = icons.size() + 1;
averageIconHeight = averageIconHeight + (height - averageIconHeight) / iconSize;
averageIconWidth = averageIconWidth + (width - averageIconWidth) / iconSize;
Timber.e("OnUpdateAverageSizeIcon with: %s %s", width, height);
Timber.e("OnUpdateAverageSizeIcon now: %s %s", averageIconWidth, averageIconHeight);
private void updateHighestIconSize(int width, int height) {
if (width > highestIconWidth) {
highestIconWidth = width;
}

if (height > highestIconHeight) {
highestIconHeight = height;
}
}

private void loadIcon(Icon icon) {
Expand Down

0 comments on commit 820c04e

Please sign in to comment.