summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun Van Nuland <tobrun.van.nuland@gmail.com>2016-05-25 11:59:21 +0200
committerTobrun Van Nuland <tobrun.van.nuland@gmail.com>2016-05-25 14:07:45 +0200
commit75dbbcdcc03a7a4c613b2e49e07d4c975eef0f1b (patch)
tree226ddb19eeb96ff8af9a2bfc26ec10e4bdb2f477
parent621bb018454d2edd9e5367fb150045d59def4166 (diff)
downloadqtlocation-mapboxgl-75dbbcdcc03a7a4c613b2e49e07d4c975eef0f1b.tar.gz
[android] #5079 - add anchor and InfoWindowAnchor to MarkerView
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java38
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java70
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java20
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java16
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerViewOptions.java49
7 files changed, 111 insertions, 88 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java
index 18db87f2c1..892eee1806 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java
@@ -1,7 +1,5 @@
package com.mapbox.mapboxsdk.annotations;
-import android.graphics.Point;
-import android.graphics.PointF;
import android.os.Parcelable;
import android.support.annotation.AnimatorRes;
import android.support.annotation.NonNull;
@@ -23,16 +21,16 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
protected String title;
protected Icon icon;
protected boolean flat;
- protected PointF centerOffset;
- protected Point infoWindowOffset;
+ protected float anchorU = 0.5f;
+ protected float anchorV = 1f;
+ protected float infoWindowAnchorU = 0.5f;
+ protected float infoWindowAnchorV = 0.0f;
protected int selectAnimRes;
protected int deselectAnimRes;
protected int rotation;
protected boolean visible = true;
public BaseMarkerViewOptions() {
- centerOffset = new PointF();
- infoWindowOffset = new Point();
}
public T position(@NonNull LatLng position) {
@@ -60,13 +58,15 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
return getThis();
}
- public T centerOffset(PointF centerOffset) {
- this.centerOffset = centerOffset;
+ public T anchor(float u, float v) {
+ this.anchorU = u;
+ this.anchorV = v;
return getThis();
}
- public T infoWindowOffset(Point infoWindowOffset) {
- this.infoWindowOffset = infoWindowOffset;
+ public T infoWindowAnchor(float u, float v) {
+ this.infoWindowAnchorU = u;
+ this.infoWindowAnchorV = v;
return getThis();
}
@@ -80,7 +80,7 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
return getThis();
}
- public T rotation(int rotation){
+ public T rotation(int rotation) {
this.rotation = rotation;
return getThis();
}
@@ -110,12 +110,20 @@ public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends Base
return flat;
}
- public PointF getCenterOffset() {
- return centerOffset;
+ public float getAnchorU() {
+ return anchorU;
}
- public Point getInfoWindowOffset() {
- return infoWindowOffset;
+ public float getAnchorV() {
+ return anchorV;
+ }
+
+ public float getInfoWindowAnchorU() {
+ return infoWindowAnchorU;
+ }
+
+ public float getInfoWindowAnchorV() {
+ return infoWindowAnchorV;
}
public int getSelectAnimRes() {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
index c1fc9bb0ab..7452ab8fac 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
@@ -30,6 +30,7 @@ public class InfoWindow {
protected WeakReference<View> mView;
private float mMarkerHeightOffset;
+ private float mMarkerWidthOffset;
private float mViewWidthOffset;
private PointF mCoordinates;
private boolean mIsVisible;
@@ -108,9 +109,9 @@ public class InfoWindow {
// Calculate y-offset for update method
mMarkerHeightOffset = -view.getMeasuredHeight() + offsetY;
+ mMarkerWidthOffset = -offsetX;
// Calculate default Android x,y coordinate
-
mCoordinates = mapboxMap.getProjection().toScreenLocation(position);
float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX;
float y = mCoordinates.y - view.getMeasuredHeight() + offsetY;
@@ -244,7 +245,7 @@ public class InfoWindow {
View view = mView.get();
if (mapboxMap != null && marker != null && view != null) {
mCoordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
- view.setX(mCoordinates.x + mViewWidthOffset);
+ view.setX(mCoordinates.x + mViewWidthOffset - mMarkerWidthOffset);
view.setY(mCoordinates.y + mMarkerHeightOffset);
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java
index 270b43d450..870480b542 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java
@@ -1,18 +1,22 @@
package com.mapbox.mapboxsdk.annotations;
-import android.graphics.Point;
-import android.graphics.PointF;
-
import com.mapbox.mapboxsdk.maps.MapboxMap;
public class MarkerView extends Marker {
private MarkerViewManager markerViewManager;
- private PointF centerOffset;
- private Point infoWindowOffset;
+ private float anchorU;
+ private float anchorV;
+
+ private float offsetX;
+ private float offsetY;
+
+ private float infoWindowAnchorU;
+ private float infoWindowAnchorV;
+
private boolean flat;
- private boolean visible;
+ private boolean visible = true;
private int selectAnimRes;
private int deselectAnimRes;
@@ -22,33 +26,63 @@ public class MarkerView extends Marker {
private float alpha = 1;
MarkerView() {
- centerOffset = new PointF();
- infoWindowOffset = new Point();
}
public MarkerView(BaseMarkerViewOptions baseMarkerViewOptions) {
super(baseMarkerViewOptions);
- this.centerOffset = baseMarkerViewOptions.getCenterOffset();
- this.infoWindowOffset = baseMarkerViewOptions.getInfoWindowOffset();
+ this.anchorU = baseMarkerViewOptions.getAnchorU();
+ this.anchorV = baseMarkerViewOptions.getAnchorV();
+ this.infoWindowAnchorU = baseMarkerViewOptions.getInfoWindowAnchorU();
+ this.infoWindowAnchorV = baseMarkerViewOptions.getInfoWindowAnchorV();
this.flat = baseMarkerViewOptions.isFlat();
this.selectAnimRes = baseMarkerViewOptions.getSelectAnimRes();
this.deselectAnimRes = baseMarkerViewOptions.getDeselectAnimRes();
+ this.infoWindowAnchorU = baseMarkerViewOptions.infoWindowAnchorU;
+ this.infoWindowAnchorV = baseMarkerViewOptions.infoWindowAnchorV;
+ this.anchorU = baseMarkerViewOptions.anchorU;
+ this.anchorV = baseMarkerViewOptions.anchorV;
+ }
+
+ public void setAnchor(float u, float v) {
+ this.anchorU = u;
+ this.anchorV = v;
+ }
+
+ public float getAnchorU() {
+ return anchorU;
+ }
+
+ public float getAnchorV() {
+ return anchorV;
+ }
+
+ void setOffsetX(float x){
+ offsetX = x;
+ }
+
+ void setOffsetY(float y){
+ offsetY = y;
+ }
+
+ float getOffsetX() {
+ return offsetX;
}
- public PointF getCenterOffset() {
- return centerOffset;
+ float getOffsetY() {
+ return offsetY;
}
- public void setCenterOffset(PointF centerOffset) {
- this.centerOffset = centerOffset;
+ public void setInfoWindowAnchor(float u, float v) {
+ this.infoWindowAnchorU = u;
+ this.infoWindowAnchorV = v;
}
- public Point getInfoWindowOffset() {
- return infoWindowOffset;
+ public float getInfoWindowAnchorU() {
+ return infoWindowAnchorU;
}
- public void setInfoWindowOffset(Point infoWindowOffset) {
- this.infoWindowOffset = infoWindowOffset;
+ public float getInfoWindowAnchorV() {
+ return infoWindowAnchorV;
}
public boolean isFlat() {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index c0c18e59e7..fcb7894d1b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk.annotations;
-import android.graphics.Point;
import android.graphics.PointF;
import android.os.SystemClock;
import android.support.annotation.NonNull;
@@ -62,8 +61,13 @@ public class MarkerViewManager {
convertView = mMarkerViewMap.get(marker);
if (convertView != null) {
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
- convertView.setX(point.x - (convertView.getMeasuredWidth() / 2));
- convertView.setY(point.y - (convertView.getMeasuredHeight() / 2));
+ int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth());
+ int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight());
+ marker.setOffsetX(x);
+ marker.setOffsetY(y);
+ convertView.setX(point.x - x);
+ convertView.setY(point.y - y);
+
if (marker.isVisible() && convertView.getVisibility() == View.GONE) {
convertView.animate().cancel();
convertView.setAlpha(0);
@@ -176,7 +180,7 @@ public class MarkerViewManager {
for (final MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) {
if (adapter.getMarkerClass() == marker.getClass()) {
convertView = (View) adapter.getViewReusePool().acquire();
- View adaptedView = adapter.getView(marker, convertView, mapView);
+ final View adaptedView = adapter.getView(marker, convertView, mapView);
if (adaptedView != null) {
// tilt
@@ -210,11 +214,11 @@ public class MarkerViewManager {
}
if (!clickHandled) {
-
// InfoWindow offset
- Point infoWindowOffset = marker.getInfoWindowOffset();
- marker.setTopOffsetPixels(-(v.getHeight() / 2) - infoWindowOffset.y);
- marker.setRightOffsetPixels(infoWindowOffset.x);
+ int infoWindowOffsetX = (int) ((adaptedView.getWidth() * marker.getInfoWindowAnchorU()) - marker.getOffsetX());
+ int infoWindowOffsetY = (int) ((adaptedView.getHeight() * marker.getInfoWindowAnchorV()) -marker.getOffsetY());
+ marker.setTopOffsetPixels(infoWindowOffsetY);
+ marker.setRightOffsetPixels(infoWindowOffsetX);
if (animSelectRes != 0) {
AnimatorUtils.animate(v, animSelectRes, new AnimatorUtils.OnAnimationEndListener() {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java
index 29435a9d91..a688a8b1a9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java
@@ -1,8 +1,6 @@
package com.mapbox.mapboxsdk.annotations;
import android.graphics.Bitmap;
-import android.graphics.Point;
-import android.graphics.PointF;
import android.os.Parcel;
import android.os.Parcelable;
@@ -22,8 +20,8 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
snippet(in.readString());
title(in.readString());
flat(in.readByte() != 0);
- centerOffset((PointF) in.readParcelable(PointF.class.getClassLoader()));
- infoWindowOffset((Point) in.readParcelable(Point.class.getClassLoader()));
+ anchor(in.readFloat(), in.readFloat());
+ infoWindowAnchor(in.readFloat(), in.readFloat());
selectAnimatorResource(in.readInt());
deselectAnimatorResource(in.readInt());
rotation(in.readInt());
@@ -53,8 +51,10 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
out.writeString(getSnippet());
out.writeString(getTitle());
out.writeByte((byte) (isFlat() ? 1 : 0));
- out.writeParcelable(getCenterOffset(), flags);
- out.writeParcelable(getInfoWindowOffset(), flags);
+ out.writeFloat(getAnchorU());
+ out.writeFloat(getAnchorV());
+ out.writeFloat(getInfoWindowAnchorU());
+ out.writeFloat(getInfoWindowAnchorV());
out.writeInt(getSelectAnimRes());
out.writeInt(getDeselectAnimRes());
out.writeInt(getRotation());
@@ -74,8 +74,8 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
marker.setTitle(title);
marker.setIcon(icon);
marker.setFlat(flat);
- marker.setCenterOffset(centerOffset);
- marker.setInfoWindowOffset(infoWindowOffset);
+ marker.setAnchor(anchorU, anchorV);
+ marker.setInfoWindowAnchor(infoWindowAnchorU, infoWindowAnchorV);
marker.setSelectAnimRes(selectAnimRes);
marker.setDeselectAnimRes(deselectAnimRes);
marker.setRotation(rotation);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java
index e9a3401548..65a5afa602 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java
@@ -73,7 +73,6 @@ public class MarkerViewActivity extends AppCompatActivity {
mMapboxMap.addMarker(new MarkerViewOptions()
.position(LAT_LNGS[i])
.title(String.valueOf(i))
- .infoWindowOffset(new Point(0, (int) getResources().getDimension(R.dimen.fab_margin)))
.selectAnimatorResource(R.animator.scale_up)
.deselectAnimatorResource(R.animator.scale_down)
);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerViewOptions.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerViewOptions.java
index 261901bffb..c4ef4a8d13 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerViewOptions.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/model/annotations/CountryMarkerViewOptions.java
@@ -9,6 +9,7 @@ import android.os.Parcelable;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
+import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.geometry.LatLng;
public class CountryMarkerViewOptions extends BaseMarkerViewOptions<CountryMarkerView, CountryMarkerViewOptions> {
@@ -24,10 +25,11 @@ public class CountryMarkerViewOptions extends BaseMarkerViewOptions<CountryMarke
snippet(in.readString());
title(in.readString());
flat(in.readByte() != 0);
- centerOffset((PointF) in.readParcelable(PointF.class.getClassLoader()));
- infoWindowOffset((Point) in.readParcelable(Point.class.getClassLoader()));
+ anchor(in.readFloat(), in.readFloat());
+ infoWindowAnchor(in.readFloat(), in.readFloat());
selectAnimatorResource(in.readInt());
deselectAnimatorResource(in.readInt());
+ rotation(in.readInt());
if (in.readByte() != 0) {
// this means we have an icon
String iconId = in.readString();
@@ -35,6 +37,8 @@ public class CountryMarkerViewOptions extends BaseMarkerViewOptions<CountryMarke
Icon icon = IconFactory.recreate(iconId, iconBitmap);
icon(icon);
}
+ abbrevName(in.readString());
+ flagRes(in.readInt());
}
@Override
@@ -53,16 +57,21 @@ public class CountryMarkerViewOptions extends BaseMarkerViewOptions<CountryMarke
out.writeString(getSnippet());
out.writeString(getTitle());
out.writeByte((byte) (isFlat() ? 1 : 0));
- out.writeParcelable(getCenterOffset(), flags);
- out.writeParcelable(getInfoWindowOffset(), flags);
+ out.writeFloat(getAnchorU());
+ out.writeFloat(getAnchorV());
+ out.writeFloat(getInfoWindowAnchorU());
+ out.writeFloat(getInfoWindowAnchorV());
out.writeInt(getSelectAnimRes());
out.writeInt(getDeselectAnimRes());
+ out.writeInt(getRotation());
Icon icon = getIcon();
out.writeByte((byte) (icon != null ? 1 : 0));
if (icon != null) {
out.writeString(getIcon().getId());
out.writeParcelable(getIcon().getBitmap(), flags);
}
+ out.writeString(abbrevName);
+ out.writeInt(flagRes);
}
@Override
@@ -80,38 +89,6 @@ public class CountryMarkerViewOptions extends BaseMarkerViewOptions<CountryMarke
return getThis();
}
- public LatLng getPosition() {
- return position;
- }
-
- public String getSnippet() {
- return snippet;
- }
-
- public String getTitle() {
- return title;
- }
-
- public boolean isFlat() {
- return flat;
- }
-
- public PointF getCenterOffset() {
- return centerOffset;
- }
-
- public Point getInfoWindowOffset() {
- return infoWindowOffset;
- }
-
- public int getSelectAnimRes() {
- return selectAnimRes;
- }
-
- public int getDeselectAnimRes() {
- return deselectAnimRes;
- }
-
public static final Parcelable.Creator<CountryMarkerViewOptions> CREATOR
= new Parcelable.Creator<CountryMarkerViewOptions>() {
public CountryMarkerViewOptions createFromParcel(Parcel in) {