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

Commit

Permalink
[android] Refactor annotations API
Browse files Browse the repository at this point in the history
Remove unimplemented properties.
Correct defintions of equals() and hasCode().
Add setOnInfoWindowClickListener and remove old method from Marker.
Refactor showInfoWindow() to remove need for exposing internal method.
Make select/deselectMarker public. Add getSelectedMarker.
Fix bug where you couldn't reselect a closed info window.
Add empty constructor to LatLng and LatLngZoom.
Fixes #2546
Fixes #2631
Fixes #2448
  • Loading branch information
Leith Bade committed Oct 22, 2015
1 parent 8b79a8d commit 927b4c6
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 728 deletions.
39 changes: 0 additions & 39 deletions android/cpp/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,15 @@ jfieldID markerIconId = nullptr;

jclass polylineClass = nullptr;
jfieldID polylineAlphaId = nullptr;
jfieldID polylineVisibleId = nullptr;
jfieldID polylineColorId = nullptr;
jfieldID polylineWidthId = nullptr;
jfieldID polylinePointsId = nullptr;

jclass polygonClass = nullptr;
jfieldID polygonAlphaId = nullptr;
jfieldID polygonVisibleId = nullptr;
jfieldID polygonFillColorId = nullptr;
jfieldID polygonStrokeColorId = nullptr;
jfieldID polygonStrokeWidthId = nullptr;
jfieldID polygonPointsId = nullptr;
jfieldID polygonHolesId = nullptr;

jclass runtimeExceptionClass = nullptr;
jclass nullPointerExceptionClass = nullptr;
Expand Down Expand Up @@ -338,7 +334,6 @@ mbgl::AnnotationSegment annotation_segment_from_latlng_jlist(JNIEnv *env, jobjec

std::pair<mbgl::AnnotationSegment, mbgl::StyleProperties> annotation_std_pair_from_polygon_jobject(JNIEnv *env, jobject polygon) {
jfloat alpha = env->GetFloatField(polygon, polygonAlphaId);
//jboolean visible = env->GetBooleanField(polygon, polygonVisibleId);
jint fillColor = env->GetIntField(polygon, polygonFillColorId);
jint strokeColor = env->GetIntField(polygon, polygonStrokeColorId);

Expand Down Expand Up @@ -918,12 +913,6 @@ jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr
return -1;
}

/*jboolean visible = env->GetBooleanField(polyline, polylineVisibleId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return -1;
}*/

jint color = env->GetIntField(polyline, polylineColorId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
Expand Down Expand Up @@ -1476,12 +1465,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}

polylineVisibleId = env->GetFieldID(polylineClass, "visible", "Z");
if (polylineVisibleId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}

polylineColorId = env->GetFieldID(polylineClass, "color", "I");
if (polylineColorId == nullptr) {
env->ExceptionDescribe();
Expand Down Expand Up @@ -1512,12 +1495,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}

polygonVisibleId = env->GetFieldID(polygonClass, "visible", "Z");
if (polygonVisibleId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}

polygonFillColorId = env->GetFieldID(polygonClass, "fillColor", "I");
if (polygonFillColorId == nullptr) {
env->ExceptionDescribe();
Expand All @@ -1530,24 +1507,12 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}

polygonStrokeWidthId = env->GetFieldID(polygonClass, "strokeWidth", "F");
if (polygonStrokeWidthId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}

polygonPointsId = env->GetFieldID(polygonClass, "points", "Ljava/util/List;");
if (polygonPointsId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}

polygonHolesId = env->GetFieldID(polygonClass, "holes", "Ljava/util/List;");
if (polygonHolesId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}

jclass nativeMapViewClass = env->FindClass("com/mapbox/mapboxsdk/views/NativeMapView");
if (nativeMapViewClass == nullptr) {
env->ExceptionDescribe();
Expand Down Expand Up @@ -2040,20 +2005,16 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
env->DeleteGlobalRef(polylineClass);
polylineClass = nullptr;
polylineAlphaId = nullptr;
polylineVisibleId = nullptr;
polylineColorId = nullptr;
polylineWidthId = nullptr;
polylinePointsId = nullptr;

env->DeleteGlobalRef(polygonClass);
polygonClass = nullptr;
polygonAlphaId = nullptr;
polygonVisibleId = nullptr;
polygonFillColorId = nullptr;
polygonStrokeColorId = nullptr;
polygonStrokeWidthId = nullptr;
polygonPointsId = nullptr;
polygonHolesId = nullptr;

onInvalidateId = nullptr;
onMapChangedId = nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mapbox.mapboxsdk.annotations;

import android.support.annotation.NonNull;

import com.mapbox.mapboxsdk.views.MapView;

import java.lang.ref.WeakReference;
Expand All @@ -8,19 +10,13 @@ public abstract class Annotation implements Comparable<Annotation> {

/**
* The annotation id
*
* <p/>
* Internal C++ id is stored as unsigned int.
*/
private long id = -1; // -1 unless added to a MapView
private WeakReference<MapView> mapView;

private float alpha = 1.0f;
private boolean visible = true;

protected Annotation() {}

public float getAlpha() {
return alpha;
protected Annotation() {
}

/**
Expand All @@ -30,21 +26,13 @@ public long getId() {
return id;
}

boolean isVisible() {
return visible;
}

public void remove() {
if ((mapView == null) || (mapView.get() == null)) {
return;
}
mapView.get().removeAnnotation(this);
}

void setAlpha(float alpha) {
this.alpha = alpha;
}

/**
* Do not use this method. Used internally by the SDK.
*/
Expand All @@ -56,7 +44,7 @@ public void setId(long id) {
* Do not use this method. Used internally by the SDK.
*/
public void setMapView(MapView mapView) {
this.mapView = new WeakReference<MapView>(mapView);
this.mapView = new WeakReference<>(mapView);
}

protected MapView getMapView() {
Expand All @@ -66,41 +54,8 @@ protected MapView getMapView() {
return mapView.get();
}

void setVisible(boolean visible) {
this.visible = visible;
}

// TODO: Implement getZIndex of Google Maps Android API
// public float getZIndex() {
//
// }

// TODO: Implement setZIndex of Google Maps Android API
// public void setZIndex(float zIndex) {
//
// }


@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}

if (o instanceof Annotation) {
Annotation comp = (Annotation) o;
return id == comp.id;
}
return false;
}

@Override
public int compareTo(Annotation annotation) {

if (annotation == null) {
return -1;
}

public int compareTo(@NonNull Annotation annotation) {
if (id < annotation.getId()) {
return 1;
} else if (id > annotation.getId()) {
Expand All @@ -110,4 +65,19 @@ public int compareTo(Annotation annotation) {
// Equal
return 0;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Annotation that = (Annotation) o;

return getId() == that.getId();
}

@Override
public int hashCode() {
return (int) (getId() ^ (getId() >>> 32));
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 927b4c6

Please sign in to comment.