diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-05-13 18:03:19 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-05-20 12:03:26 +0200 |
commit | 1548f27c6f29ccf284ea821de46ea2ceabd7ec26 (patch) | |
tree | e41aa4e050ebbffbae1fa67cbd7e4ed1609ddc88 /platform/android | |
parent | e50fb87e7bfaef07362feb84d661f003b352f354 (diff) | |
download | qtlocation-mapboxgl-1548f27c6f29ccf284ea821de46ea2ceabd7ec26.tar.gz |
[android] #3276 - for each view marker adapter have separate view pool
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 94 |
1 files changed, 40 insertions, 54 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 2ab00811d5..98dccb0bc2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -103,7 +103,6 @@ public class MapboxMap { private double mMaxZoomLevel = -1; private double mMinZoomLevel = -1; - private Pools.SimplePool<View> mViewReusePool = new Pools.SimplePool<>(20); private List<MapboxMap.MarkerViewAdapter> mMarkerViewAdapters; MapboxMap(@NonNull MapView mapView) { @@ -658,22 +657,22 @@ public class MapboxMap { convertView = outBoundsEntry.getValue(); if (convertView != null) { if (mMarkerViewItemAnimatorOutRes != 0) { - removeMarkerView(outBoundsEntry.getKey().getId()); Animator animator = AnimatorInflater.loadAnimator(mMapView.getContext(), mMarkerViewItemAnimatorOutRes); animator.setDuration(0); animator.setTarget(convertView); animator.start(); } + removeMarkerView(outBoundsEntry.getKey().getId()); } } // in bounds markers List<Marker> inBoundsMarkers = result.getInBounds(); for (final Marker marker : inBoundsMarkers) { - convertView = mViewReusePool.acquire(); Log.v("TAG", "Calling get view for " + marker.getId()); for (final MarkerViewAdapter adapter : mMarkerViewAdapters) { - if (adapter.getMarkerClass()==marker.getClass()) { + if (adapter.getMarkerClass() == marker.getClass()) { + convertView = (View) adapter.getViewReusePool().acquire(); View adaptedView = adapter.getView(marker, convertView, mMapView); if (adaptedView != null) { // hack to hide old marker, todo replace with visibility @@ -1020,26 +1019,35 @@ public class MapboxMap { private void removeMarkerView(long id) { final View viewHolder = mMarkerViews.get(id); - if (viewHolder != null) { - - // cancel ongoing animations - viewHolder.animate().cancel(); - viewHolder.setAlpha(1); - - // animate alpha - viewHolder.animate() - .alpha(0) - .setDuration(MapboxConstants.ANIMATION_DURATION_SHORT) - .setInterpolator(new FastOutSlowInInterpolator()) - .setListener(new AnimatorListenerAdapter() { - - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - viewHolder.setVisibility(View.GONE); - mViewReusePool.release(viewHolder); - } - }); + final Marker marker = (Marker) getAnnotation(id); + if (viewHolder != null && marker != null) { + for (final MarkerViewAdapter<?> adapter : mMarkerViewAdapters) { + if (adapter.getMarkerClass() == marker.getClass()) { + + // get pool of Views associated to an adapter + final Pools.SimplePool<View> viewPool = adapter.getViewReusePool(); + + // cancel ongoing animations + viewHolder.animate().cancel(); + viewHolder.setAlpha(1); + + // animate alpha + viewHolder.animate() + .alpha(0) + .setDuration(MapboxConstants.ANIMATION_DURATION_SHORT) + .setInterpolator(new FastOutSlowInInterpolator()) + .setListener(new AnimatorListenerAdapter() { + + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + viewHolder.setVisibility(View.GONE); + viewPool.release(viewHolder); + } + }); + } + } + } mMarkerViews.remove(id); } @@ -1912,46 +1920,24 @@ public class MapboxMap { public static abstract class MarkerViewAdapter<U extends Marker> { - private Class<U> persistentClass; + private final Class<U> persistentClass; + private final Pools.SimplePool<View> mViewReusePool; @SuppressWarnings("unchecked") public MarkerViewAdapter(Context context) { - this.persistentClass = (Class<U>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + persistentClass = (Class<U>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + mViewReusePool = new Pools.SimplePool<>(20); } - @AnimatorRes - private int animSelectOutRes; - - @AnimatorRes - private int animSelectInRes; - - @AnimatorRes - private int animEnterRes; - - @AnimatorRes - private int animExitRes; - @Nullable public abstract View getView(@NonNull U marker, @Nullable View convertView, @NonNull ViewGroup parent); - public int getAnimSelectOutRes() { - return animSelectOutRes; - } - - public int getAnimSelectInRes() { - return animSelectInRes; - } - - public int getAnimEnterRes() { - return animEnterRes; - } - - public int getAnimExitRes() { - return animExitRes; + public Class<U> getMarkerClass() { + return persistentClass; } - public Class<U> getMarkerClass(){ - return persistentClass; + public Pools.SimplePool<View> getViewReusePool() { + return mViewReusePool; } } |