[android] #3276 - add tilt support for view markers
This commit is contained in:
@@ -2,40 +2,26 @@ package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.AnimatorRes;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public class MarkerViewSettings implements Parcelable {
|
||||
public class MarkerViewSettings {
|
||||
|
||||
private PointF centerOffset;
|
||||
private Point infoWindowOffset;
|
||||
private boolean flat;
|
||||
|
||||
private int animEnterRes;
|
||||
private int animSelectRes;
|
||||
private int animDeselectRes;
|
||||
private int animExitRes;
|
||||
private int selectAnimRes;
|
||||
private int deselectAnimRes;
|
||||
|
||||
MarkerViewSettings(PointF centerOffset, Point infoWindowOffset, boolean flat, int animEnterRes, int animSelectRes, int animDeselectRes, int animExitRes) {
|
||||
private float tiltValue;
|
||||
|
||||
MarkerViewSettings(PointF centerOffset, Point infoWindowOffset, boolean flat, int selectAnimRes, int deselectAnimRes) {
|
||||
this.centerOffset = centerOffset;
|
||||
this.infoWindowOffset = infoWindowOffset;
|
||||
this.flat = flat;
|
||||
this.animEnterRes = animEnterRes;
|
||||
this.animSelectRes = animSelectRes;
|
||||
this.animDeselectRes = animDeselectRes;
|
||||
this.animExitRes = animExitRes;
|
||||
}
|
||||
|
||||
MarkerViewSettings(Parcel parcel) {
|
||||
this.centerOffset = parcel.readParcelable(PointF.class.getClassLoader());
|
||||
this.infoWindowOffset = parcel.readParcelable(Point.class.getClassLoader());
|
||||
this.flat = parcel.readByte() != 0;
|
||||
this.animEnterRes = parcel.readInt();
|
||||
this.animSelectRes = parcel.readInt();
|
||||
this.animDeselectRes = parcel.readInt();
|
||||
this.animExitRes = parcel.readInt();
|
||||
this.selectAnimRes = selectAnimRes;
|
||||
this.deselectAnimRes = deselectAnimRes;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -48,55 +34,26 @@ public class MarkerViewSettings implements Parcelable {
|
||||
return infoWindowOffset;
|
||||
}
|
||||
|
||||
@AnimatorRes
|
||||
public int getSelectAnimRes() {
|
||||
return selectAnimRes;
|
||||
}
|
||||
|
||||
@AnimatorRes
|
||||
public int getDeselectAnimRes() {
|
||||
return deselectAnimRes;
|
||||
}
|
||||
|
||||
public boolean isFlat() {
|
||||
return flat;
|
||||
}
|
||||
|
||||
@AnimatorRes
|
||||
public int getAnimEnterRes() {
|
||||
return animEnterRes;
|
||||
public void setTiltValue(float tilt) {
|
||||
tiltValue = tilt;
|
||||
}
|
||||
|
||||
@AnimatorRes
|
||||
public int getAnimSelectRes() {
|
||||
return animSelectRes;
|
||||
}
|
||||
|
||||
@AnimatorRes
|
||||
public int getAnimDeselectRes() {
|
||||
return animDeselectRes;
|
||||
}
|
||||
|
||||
@AnimatorRes
|
||||
public int getAnimExitRes() {
|
||||
return animExitRes;
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<MarkerViewSettings> CREATOR
|
||||
= new Parcelable.Creator<MarkerViewSettings>() {
|
||||
public MarkerViewSettings createFromParcel(Parcel in) {
|
||||
return new MarkerViewSettings(in);
|
||||
}
|
||||
|
||||
public MarkerViewSettings[] newArray(int size) {
|
||||
return new MarkerViewSettings[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(centerOffset, flags);
|
||||
dest.writeParcelable(infoWindowOffset, flags);
|
||||
dest.writeByte((byte) (flat ? 1 : 0));
|
||||
dest.writeInt(animEnterRes);
|
||||
dest.writeInt(animSelectRes);
|
||||
dest.writeInt(animDeselectRes);
|
||||
dest.writeInt(animExitRes);
|
||||
public float getTiltValue() {
|
||||
return tiltValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,10 +65,8 @@ public class MarkerViewSettings implements Parcelable {
|
||||
private Point infoWindowOffset;
|
||||
private boolean flat;
|
||||
|
||||
private int animEnterRes;
|
||||
private int animSelectRes;
|
||||
private int animDeselectRes;
|
||||
private int animExitRes;
|
||||
|
||||
public Builder() {
|
||||
centerOffset = new PointF();
|
||||
@@ -133,11 +88,6 @@ public class MarkerViewSettings implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder animEnterRes(@AnimatorRes int animatorRes) {
|
||||
animEnterRes = animatorRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder animSelectRes(@AnimatorRes int animatorRes) {
|
||||
animSelectRes = animatorRes;
|
||||
return this;
|
||||
@@ -148,13 +98,8 @@ public class MarkerViewSettings implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder animExitRes(@AnimatorRes int animatorRes) {
|
||||
animExitRes = animatorRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MarkerViewSettings build() {
|
||||
return new MarkerViewSettings(centerOffset, infoWindowOffset, flat, animEnterRes, animSelectRes, animDeselectRes, animExitRes);
|
||||
return new MarkerViewSettings(centerOffset, infoWindowOffset, flat, animSelectRes, animDeselectRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,6 @@ public class MapView extends FrameLayout {
|
||||
|
||||
private List<OnMapReadyCallback> mOnMapReadyCallbackList;
|
||||
private long mViewMarkerBoundsUpdateTime;
|
||||
private boolean mViewMarkersUpdateRunning;
|
||||
|
||||
@UiThread
|
||||
public MapView(@NonNull Context context) {
|
||||
@@ -453,9 +452,11 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
} else if (change == REGION_IS_CHANGING || change == REGION_DID_CHANGE) {
|
||||
if (mMapboxMap.getMarkerViewAdapters() != null) {
|
||||
if (!mMapboxMap.getMarkerViewAdapters().isEmpty()) {
|
||||
invalidateViewMarkers();
|
||||
}
|
||||
}else if(change== DID_FINISH_LOADING_MAP){
|
||||
invalidateViewMarkers();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -471,17 +472,11 @@ public class MapView extends FrameLayout {
|
||||
|
||||
void invalidateViewMarkers() {
|
||||
long currentTime = SystemClock.elapsedRealtime();
|
||||
|
||||
if (mViewMarkersUpdateRunning || currentTime < mViewMarkerBoundsUpdateTime) {
|
||||
if (currentTime < mViewMarkerBoundsUpdateTime) {
|
||||
return;
|
||||
}
|
||||
mViewMarkerBoundsUpdateTime = currentTime + 300;
|
||||
mViewMarkersUpdateRunning = true;
|
||||
|
||||
mMapboxMap.invalidateViewMarkersInBounds();
|
||||
|
||||
mViewMarkersUpdateRunning = false;
|
||||
Log.v(MapboxConstants.TAG, "Amount of child views " + getChildCount());
|
||||
mViewMarkerBoundsUpdateTime = currentTime + 250;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -623,13 +618,9 @@ public class MapView extends FrameLayout {
|
||||
return mNativeMapView.getPitch();
|
||||
}
|
||||
|
||||
void setTilt(Double pitch, @Nullable Long duration) {
|
||||
long actualDuration = 0;
|
||||
if (duration != null) {
|
||||
actualDuration = duration;
|
||||
}
|
||||
void setTilt(Double pitch) {
|
||||
mMyLocationView.setTilt(pitch);
|
||||
mNativeMapView.setPitch(pitch, actualDuration);
|
||||
mNativeMapView.setPitch(pitch, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1356,8 +1347,6 @@ public class MapView extends FrameLayout {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.v(MapboxConstants.TAG, "SurfaceTexture has been updated");
|
||||
|
||||
mCompassView.update(getDirection());
|
||||
mMyLocationView.update();
|
||||
|
||||
@@ -2003,7 +1992,7 @@ public class MapView extends FrameLayout {
|
||||
pitch = Math.max(MapboxConstants.MINIMUM_TILT, Math.min(MapboxConstants.MAXIMUM_TILT, pitch));
|
||||
|
||||
// Tilt the map
|
||||
setTilt(pitch, null);
|
||||
mMapboxMap.setTilt(pitch);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,8 @@ import android.animation.AnimatorListenerAdapter;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.location.Location;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.AnimatorRes;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -655,8 +653,6 @@ public class MapboxMap {
|
||||
|
||||
void invalidateViewMarkersInBounds() {
|
||||
List<Marker> markers = mMapView.getMarkersInBounds(mProjection.getVisibleRegion().latLngBounds);
|
||||
Log.v(MapboxConstants.TAG, "Annotations in bounds: " + markers.size());
|
||||
|
||||
View convertView;
|
||||
|
||||
// remove old markers
|
||||
@@ -667,7 +663,7 @@ public class MapboxMap {
|
||||
// remove marker
|
||||
convertView = mMarkerViewMap.get(m);
|
||||
MarkerViewSettings settings = mMarkerViewSettingsMap.get(m.getId());
|
||||
int deselectAnimRes = settings.getAnimDeselectRes();
|
||||
int deselectAnimRes = settings.getDeselectAnimRes();
|
||||
if (deselectAnimRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), deselectAnimRes);
|
||||
animator.setDuration(0);
|
||||
@@ -681,83 +677,92 @@ public class MapboxMap {
|
||||
|
||||
// introduce new markers
|
||||
for (final Marker marker : markers) {
|
||||
if (marker.isViewMarker()) {
|
||||
if (!mMarkerViewMap.containsKey(marker)) {
|
||||
Log.v("TAG", "Calling get view for " + marker.getId());
|
||||
for (final MarkerViewAdapter adapter : mMarkerViewAdapters) {
|
||||
if (adapter.getMarkerClass() == marker.getClass()) {
|
||||
if (marker.isViewMarker() && !mMarkerViewMap.containsKey(marker)) {
|
||||
for (final MarkerViewAdapter adapter : mMarkerViewAdapters) {
|
||||
if (adapter.getMarkerClass() == marker.getClass()) {
|
||||
|
||||
if (mMarkerViewSettingsMap.get(marker.getId()) == null) {
|
||||
mMarkerViewSettingsMap.put(marker.getId(), adapter.getMarkerViewSettings(marker));
|
||||
MarkerViewSettings settings = mMarkerViewSettingsMap.get(marker.getId());
|
||||
if (settings == null) {
|
||||
settings = adapter.getMarkerViewSettings(marker);
|
||||
mMarkerViewSettingsMap.put(marker.getId(), settings);
|
||||
}
|
||||
|
||||
convertView = (View) adapter.getViewReusePool().acquire();
|
||||
View adaptedView = adapter.getView(marker, convertView, mMapView);
|
||||
|
||||
// infowindow offset
|
||||
Point infoWindowOffset = settings.getInfoWindowOffset();
|
||||
marker.setTopOffsetPixels(infoWindowOffset.y);
|
||||
marker.setRightOffsetPixels(infoWindowOffset.x);
|
||||
|
||||
if (adaptedView != null) {
|
||||
|
||||
// tilt
|
||||
adaptedView.setRotationX(settings.getTiltValue());
|
||||
|
||||
if (mSelectedMarkers.contains(marker)) {
|
||||
// if a marker to be shown was selected
|
||||
// replay that animation with duration 0
|
||||
int selectAnimRes = settings.getSelectAnimRes();
|
||||
if (selectAnimRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), selectAnimRes);
|
||||
animator.setDuration(0);
|
||||
animator.setTarget(convertView);
|
||||
animator.start();
|
||||
}
|
||||
}
|
||||
|
||||
convertView = (View) adapter.getViewReusePool().acquire();
|
||||
View adaptedView = adapter.getView(marker, convertView, mMapView);
|
||||
|
||||
// set user provided offset to view marker
|
||||
final MarkerViewSettings markerViewSettings = mMarkerViewSettingsMap.get(marker.getId());
|
||||
Point infoWindowOffset = markerViewSettings.getInfoWindowOffset();
|
||||
marker.setTopOffsetPixels(infoWindowOffset.y);
|
||||
marker.setRightOffsetPixels(infoWindowOffset.x);
|
||||
|
||||
if (adaptedView != null) {
|
||||
if (mSelectedMarkers.contains(marker)) {
|
||||
// if a marker to be shown was selected
|
||||
// replay that animation with duration 0
|
||||
int selectAnimRes = markerViewSettings.getAnimSelectRes();
|
||||
if (selectAnimRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), selectAnimRes);
|
||||
animator.setDuration(0);
|
||||
animator.setTarget(convertView);
|
||||
animator.start();
|
||||
final int animSelectRes = settings.getSelectAnimRes();
|
||||
adaptedView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean clickHandled = false;
|
||||
if (mOnMarkerViewClickListener != null) {
|
||||
clickHandled = mOnMarkerViewClickListener.onMarkerClick(marker, v, adapter);
|
||||
}
|
||||
}
|
||||
|
||||
adaptedView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean clickHandled = false;
|
||||
if (mOnMarkerViewClickListener != null) {
|
||||
clickHandled = mOnMarkerViewClickListener.onMarkerClick(marker, v, adapter);
|
||||
}
|
||||
|
||||
if (!clickHandled) {
|
||||
int enterAnimatorRes = markerViewSettings.getAnimSelectRes();
|
||||
if (enterAnimatorRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), enterAnimatorRes);
|
||||
animator.setTarget(v);
|
||||
animator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
super.onAnimationEnd(animation);
|
||||
selectMarker(marker);
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
} else {
|
||||
selectMarker(marker);
|
||||
}
|
||||
if (!clickHandled) {
|
||||
if (animSelectRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), animSelectRes);
|
||||
animator.setTarget(v);
|
||||
animator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
super.onAnimationEnd(animation);
|
||||
selectMarker(marker);
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
} else {
|
||||
selectMarker(marker);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mMarkerViewMap.put(marker, adaptedView);
|
||||
if (convertView == null) {
|
||||
mMapView.addView(adaptedView);
|
||||
}
|
||||
});
|
||||
|
||||
mMarkerViewMap.put(marker, adaptedView);
|
||||
if (convertView == null) {
|
||||
mMapView.addView(adaptedView);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//already added
|
||||
Log.v(MapboxConstants.TAG, "Marker already added");
|
||||
}
|
||||
} else {
|
||||
Log.v(MapboxConstants.TAG, "Marker is not a view marker");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setTilt(double tilt) {
|
||||
for (Map.Entry<Marker, View> entry : mMarkerViewMap.entrySet()) {
|
||||
MarkerViewSettings settings = mMarkerViewSettingsMap.get(entry.getKey().getId());
|
||||
if (settings.isFlat()) {
|
||||
settings.setTiltValue((float) tilt);
|
||||
entry.getValue().setRotationX((float) tilt);
|
||||
}
|
||||
}
|
||||
mMapView.setTilt(tilt);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Adds a marker to this map.
|
||||
@@ -1281,7 +1286,7 @@ public class MapboxMap {
|
||||
|
||||
View viewMarker = mMarkerViewMap.get(marker);
|
||||
if (viewMarker != null) {
|
||||
int deselectAnimatorRes = mMarkerViewSettingsMap.get(marker.getId()).getAnimDeselectRes();
|
||||
int deselectAnimatorRes = mMarkerViewSettingsMap.get(marker.getId()).getDeselectAnimRes();
|
||||
if (deselectAnimatorRes != 0) {
|
||||
Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), deselectAnimatorRes);
|
||||
animator.setTarget(viewMarker);
|
||||
@@ -1965,7 +1970,6 @@ public class MapboxMap {
|
||||
public MarkerViewSettings getMarkerViewSettings(Marker marker) {
|
||||
return new MarkerViewSettings.Builder().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface OnMarkerViewClickListener {
|
||||
|
||||
@@ -254,7 +254,7 @@
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.annotation.ViewMarkerActivity"
|
||||
android:name=".activity.annotation.ViewMarkerAdapterActivity"
|
||||
android:description="@string/description_view_marker"
|
||||
android:label="@string/activity_view_marker">
|
||||
<meta-data
|
||||
@@ -262,15 +262,6 @@
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.annotation.MultipleViewMarkerAdapterActivity"
|
||||
android:description="@string/description_view_marker2"
|
||||
android:label="@string/activity_view_marker2">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
</activity>
|
||||
|
||||
<!-- Configuration Settings -->
|
||||
<meta-data
|
||||
android:name="com.mapbox.TestEventsServer"
|
||||
|
||||
@@ -77,43 +77,8 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
|
||||
});
|
||||
|
||||
final View fab = findViewById(R.id.fab);
|
||||
final TextView viewCountView = (TextView) findViewById(R.id.countView);
|
||||
if (fab != null) {
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mMapboxMap != null) {
|
||||
mCustomMarkerView = true;
|
||||
|
||||
fab.animate().alpha(0).start();
|
||||
mMapboxMap.addMarkerViewAdapter(new TextAdapter(BulkMarkerActivity.this));
|
||||
mMapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
|
||||
@Override
|
||||
public void onMapChanged(@MapView.MapChange int change) {
|
||||
if (change == MapView.REGION_IS_CHANGING || change == MapView.REGION_DID_CHANGE) {
|
||||
if (!mMapboxMap.getMarkerViewAdapters().isEmpty()) {
|
||||
viewCountView.setText("ViewCache size " + (mMapView.getChildCount() - 5));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mMapboxMap.setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
|
||||
Toast.makeText(BulkMarkerActivity.this, "Hello " + marker.getId(), Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// reload markers
|
||||
Spinner spinner = (Spinner) findViewById(R.id.spinner);
|
||||
if (spinner != null) {
|
||||
loadBulkMarkers(spinner.getSelectedItemPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
fab.setOnClickListener(new FabClickListener());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +112,6 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
loadBulkMarkers(position);
|
||||
@@ -204,6 +168,43 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
|
||||
}
|
||||
}
|
||||
|
||||
private class FabClickListener implements View.OnClickListener{
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mMapboxMap != null) {
|
||||
mCustomMarkerView = true;
|
||||
|
||||
v.animate().alpha(0).start();
|
||||
mMapboxMap.addMarkerViewAdapter(new TextAdapter(BulkMarkerActivity.this));
|
||||
mMapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
|
||||
@Override
|
||||
public void onMapChanged(@MapView.MapChange int change) {
|
||||
if (change == MapView.REGION_IS_CHANGING || change == MapView.REGION_DID_CHANGE) {
|
||||
if (!mMapboxMap.getMarkerViewAdapters().isEmpty()) {
|
||||
TextView viewCountView = (TextView) findViewById(R.id.countView);
|
||||
viewCountView.setText("ViewCache size " + (mMapView.getChildCount() - 5));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mMapboxMap.setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
|
||||
Toast.makeText(BulkMarkerActivity.this, "Hello " + marker.getId(), Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// reload markers
|
||||
Spinner spinner = (Spinner) findViewById(R.id.spinner);
|
||||
if (spinner != null) {
|
||||
loadBulkMarkers(spinner.getSelectedItemPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class LoadBulkMarkerTask extends AsyncTask<Void, Integer, List<BaseMarkerOptions>> {
|
||||
|
||||
private static final String TAG = "LoadBulkMarkerTask";
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.annotation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewSettings;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.model.annotations.CountryMarker;
|
||||
import com.mapbox.mapboxsdk.testapp.model.annotations.CountryMarkerOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ViewMarkerActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
private MapView mMapView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_marker_view);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mapView);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(final MapboxMap mapboxMap) {
|
||||
final List<BaseMarkerOptions> countries = new ArrayList<>();
|
||||
countries.add(new CountryMarkerOptions().markerView(true).title("China").abbrevName("ch").flagRes(R.drawable.ic_china).position(new LatLng(31.230416, 121.473701)));
|
||||
countries.add(new CountryMarkerOptions().markerView(true).title("United States").abbrevName("us").flagRes(R.drawable.ic_us).position(new LatLng(38.907192, -77.036871)));
|
||||
countries.add(new CountryMarkerOptions().markerView(true).title("Brazil").abbrevName("br").flagRes(R.drawable.ic_brazil).position(new LatLng(-15.798200, -47.922363)));
|
||||
countries.add(new CountryMarkerOptions().markerView(true).title("Germany").abbrevName("de").flagRes(R.drawable.ic_germany).position(new LatLng(52.520007, 13.404954)));
|
||||
final List<Marker> markers = mapboxMap.addMarkers(countries);
|
||||
|
||||
// Add view marker adapter
|
||||
mapboxMap.addMarkerViewAdapter(new CountryAdapter(this));
|
||||
mapboxMap.setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
|
||||
Log.d(MapboxConstants.TAG, "Country clicked " + ((CountryMarker) marker).getAbbrevName());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
View view = findViewById(R.id.fab);
|
||||
if (view != null) {
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mapboxMap.removeAnnotation(markers.get(2));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class CountryAdapter extends MapboxMap.MarkerViewAdapter<CountryMarker> {
|
||||
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public CountryAdapter(@NonNull Context context) {
|
||||
super(context);
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View getView(@NonNull CountryMarker marker, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
viewHolder = new ViewHolder();
|
||||
convertView = inflater.inflate(R.layout.view_custom_marker, parent, false);
|
||||
viewHolder.flag = (ImageView) convertView.findViewById(R.id.imageView);
|
||||
viewHolder.abbrev = (TextView) convertView.findViewById(R.id.textView);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
viewHolder.flag.setImageResource(marker.getFlagRes());
|
||||
viewHolder.abbrev.setText(marker.getAbbrevName());
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
ImageView flag;
|
||||
TextView abbrev;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mMapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mMapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mMapView.onLowMemory();
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.model.annotations.CountryMarker;
|
||||
import com.mapbox.mapboxsdk.testapp.model.annotations.CountryMarkerOptions;
|
||||
|
||||
public class MultipleViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
public class ViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
|
||||
private MapboxMap mMapboxMap;
|
||||
private MapView mMapView;
|
||||
@@ -45,14 +45,13 @@ public class MultipleViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_marker_bulk);
|
||||
setContentView(R.layout.activity_marker_view);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
@@ -65,7 +64,13 @@ public class MultipleViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
|
||||
int infoWindowOffset = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
|
||||
// add text markers
|
||||
for (int i = 0; i < LAT_LNGS.length; i++) {
|
||||
mMapboxMap.addMarker(new MarkerOptions()
|
||||
.position(LAT_LNGS[i])
|
||||
.markerView(true)
|
||||
.title(String.valueOf(i)));
|
||||
}
|
||||
|
||||
// add flag marker
|
||||
mMapboxMap.addMarker(new CountryMarkerOptions()
|
||||
@@ -76,24 +81,15 @@ public class MultipleViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
.position(new LatLng(38.899774, -77.023237))
|
||||
);
|
||||
|
||||
// default GL marker
|
||||
mMapboxMap.addMarker(new CountryMarkerOptions()
|
||||
.title("United States")
|
||||
.abbrevName("us")
|
||||
.flagRes(R.drawable.ic_us)
|
||||
.position(new LatLng(38.902580, -77.050102))
|
||||
);
|
||||
|
||||
// add text markers
|
||||
for (int i = 0; i < LAT_LNGS.length; i++) {
|
||||
mMapboxMap.addMarker(new MarkerOptions()
|
||||
.position(LAT_LNGS[i])
|
||||
.markerView(true)
|
||||
.title(String.valueOf(i)));
|
||||
}
|
||||
|
||||
// set adapters
|
||||
mMapboxMap.addMarkerViewAdapter(new TextAdapter(MultipleViewMarkerAdapterActivity.this));
|
||||
mMapboxMap.addMarkerViewAdapter(new CountryAdapter(MultipleViewMarkerAdapterActivity.this));
|
||||
mMapboxMap.addMarkerViewAdapter(new TextAdapter(ViewMarkerAdapterActivity.this));
|
||||
mMapboxMap.addMarkerViewAdapter(new CountryAdapter(ViewMarkerAdapterActivity.this));
|
||||
|
||||
mMapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
|
||||
@Override
|
||||
@@ -109,7 +105,7 @@ public class MultipleViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
mMapboxMap.setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
|
||||
Toast.makeText(MultipleViewMarkerAdapterActivity.this, "Hello " + marker.getId(), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(ViewMarkerAdapterActivity.this, "Hello " + marker.getId(), Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@@ -148,7 +144,7 @@ public class MultipleViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
.animSelectRes(R.animator.scale_up)
|
||||
.animDeselectRes(R.animator.scale_down)
|
||||
.infoWindowOffset(0, (int) getContext().getResources()
|
||||
.getDimension(R.dimen.fab_margin));
|
||||
.getDimension(R.dimen.coordinatebounds_margin));
|
||||
|
||||
if (marker.getId() == 0) {
|
||||
builder.flat(true);
|
||||
@@ -192,10 +188,10 @@ public class MultipleViewMarkerAdapterActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public MarkerViewSettings getMarkerViewSettings(Marker marker) {
|
||||
return new MarkerViewSettings.Builder()
|
||||
.animSelectRes(R.animator.scale_up)
|
||||
.animDeselectRes(R.animator.scale_down)
|
||||
.animSelectRes(R.animator.rotate_360)
|
||||
.animDeselectRes(R.animator.rotate_360)
|
||||
.infoWindowOffset(0, (int) getContext().getResources()
|
||||
.getDimension(R.dimen.coordinatebounds_margin))
|
||||
.getDimension(R.dimen.fab_margin))
|
||||
.flat(true)
|
||||
.build();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<objectAnimator
|
||||
android:propertyName="rotation"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="360"
|
||||
android:valueType="floatType"/>
|
||||
</set>
|
||||
@@ -45,7 +45,6 @@
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_animate_coordinates"
|
||||
app:backgroundTint="@android:color/white" />
|
||||
android:src="@drawable/ic_animate_coordinates" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -1,48 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@id/container"
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/toolbar"
|
||||
app:center_latitude="38.907192"
|
||||
app:center_longitude="-77.036871"
|
||||
app:style_url="@string/style_mapbox_streets"
|
||||
app:zoom="12" />
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:id="@+id/coordinator_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/countView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:padding="16dp"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
app:access_token="@string/mapbox_access_token"
|
||||
app:style_url="@string/style_light"
|
||||
app:zoom="1"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_layers_24dp"
|
||||
app:backgroundTint="@color/primary" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
<string name="activity_polygon">Polygon</string>
|
||||
<string name="activity_press_for_marker">Press Map For Marker</string>
|
||||
<string name="activity_view_marker">View Marker API</string>
|
||||
<string name="activity_view_marker2">View Marker AP2</string>
|
||||
|
||||
<!-- InfoWindow-->
|
||||
<string name="activity_info_window">Standard InfoWindow example</string>
|
||||
@@ -79,7 +78,6 @@
|
||||
<string name="description_snapshot">Example to make a snapshot of the map</string>
|
||||
<string name="description_doublemap">2 maps in a view hierarchy</string>
|
||||
<string name="description_view_marker">Use an Android SDK View as marker</string>
|
||||
<string name="description_view_marker2">Use an Android SDK View as marker2</string>
|
||||
|
||||
<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>r
|
||||
<string name="menuitem_title_tracking_mode_dismiss_on_gesture">Dismiss location tracking on gesture</string>
|
||||
|
||||
Reference in New Issue
Block a user