[android] - add MarkerViewManager and MarkerViewTransformer

This commit is contained in:
Tobrun
2016-05-23 10:18:20 +02:00
committed by Tobrun
parent 2865e7d35c
commit 40bb02fe74
7 changed files with 361 additions and 247 deletions

View File

@@ -8,7 +8,6 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -28,11 +27,11 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
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.utils.GeoParseUtil;
import com.mapbox.mapboxsdk.maps.MapView;
import org.json.JSONException;
@@ -252,13 +251,13 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
}
// add adapter
mMapboxMap.addMarkerViewAdapter(new TextAdapter(BulkMarkerActivity.this));
mMapboxMap.getMarkerViewManager().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()) {
if (!mMapboxMap.getMarkerViewManager().getMarkerViewAdapters().isEmpty()) {
TextView viewCountView = (TextView) findViewById(R.id.countView);
viewCountView.setText("ViewCache size " + (mMapView.getChildCount() - 5));
}
@@ -266,7 +265,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
}
});
mMapboxMap.setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
mMapboxMap.getMarkerViewManager().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();

View File

@@ -8,7 +8,6 @@ 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;
@@ -19,8 +18,8 @@ import android.widget.Toast;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerView;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
@@ -99,21 +98,22 @@ public class ViewMarkerAdapterActivity extends AppCompatActivity {
);
// set adapters
mMapboxMap.addMarkerViewAdapter(new TextAdapter(ViewMarkerAdapterActivity.this));
mMapboxMap.addMarkerViewAdapter(new CountryAdapter(ViewMarkerAdapterActivity.this));
final MarkerViewManager markerViewManager = mapboxMap.getMarkerViewManager();
markerViewManager.addMarkerViewAdapter(new TextAdapter(ViewMarkerAdapterActivity.this));
markerViewManager.addMarkerViewAdapter(new CountryAdapter(ViewMarkerAdapterActivity.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 != null) {
if (!markerViewManager.getMarkerViewAdapters().isEmpty() && viewCountView != null) {
viewCountView.setText("ViewCache size " + (mMapView.getChildCount() - 5));
}
}
}
});
mMapboxMap.setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
mMapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() {
@Override
public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) {
Toast.makeText(ViewMarkerAdapterActivity.this, "Hello " + marker.getId(), Toast.LENGTH_SHORT).show();