diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-06-17 16:05:45 +0200 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2016-06-17 16:06:37 +0200 |
commit | 8c83af7b977d1091e3e3c35a47bce451488ba080 (patch) | |
tree | 1778b8aec546a0b80cbf296da173b64914721128 /platform/android | |
parent | 8e9b158e7347c00465d99f30f1220dff6c375178 (diff) | |
download | qtlocation-mapboxgl-8c83af7b977d1091e3e3c35a47bce451488ba080.tar.gz |
[android] #5299 - remove MarkerView x,y animation
Diffstat (limited to 'platform/android')
4 files changed, 20 insertions, 200 deletions
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 ba7d58b838..cee634c435 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 @@ -48,16 +48,6 @@ public class MarkerView extends Marker { private boolean selected; - private LatLng targetPosition; - private boolean shouldAnimate; - private boolean isAnimationRunning; - private AnimatorSet set; - - private long startTime; - private long duration; - private long remainingTime; - private AnimatorUtils.OnAnimationEndListener animationEndListener; - /** * Publicly hidden default constructor */ @@ -354,82 +344,6 @@ public class MarkerView extends Marker { markerViewManager = mapboxMap.getMarkerViewManager(); } - @Override - public void setPosition(LatLng position) { - setPosition(position, 0); - } - - public void setPosition(LatLng position, long duration) { - setPosition(position, duration, null); - } - - public void setPosition(LatLng position, long duration, AnimatorUtils.OnAnimationEndListener animationEndListener) { - this.animationEndListener = animationEndListener; - - if (duration <= 0) { - // update position instantly - super.setPosition(position); - if (markerViewManager != null) { - markerViewManager.update(); - } - } else { - // animate using Android SDK animations - this.targetPosition = position; - if (markerViewManager != null) { - markerViewManager.animatePosition(this, duration); - } - } - } - - boolean shouldAnimate() { - return shouldAnimate; - } - - void setShouldAnimate(boolean animating) { - shouldAnimate = animating; - } - - boolean isAnimating() { - return isAnimationRunning; - } - - void setAnimating(boolean animationRunning) { - isAnimationRunning = animationRunning; - } - - LatLng getTargetPosition() { - return targetPosition; - } - - void setAnimation(AnimatorSet set) { - this.set = set; - } - - AnimatorSet getAnimation() { - return set; - } - - long getRemainingTime() { - long time = duration - (AnimationUtils.currentAnimationTimeMillis() - startTime); - return time > 0 ? time : 0; - } - - void setDuration(long duration) { - this.duration = duration; - } - - void setStartTime(long startTime) { - this.startTime = startTime; - } - - AnimatorUtils.OnAnimationEndListener getAnimationEndListener() { - return animationEndListener; - } - - PointF getScreenLocation(@NonNull View convertView) { - return new PointF(convertView.getX() + offsetX, convertView.getY() + offsetY); - } - /** * Get the String representation of a MarkerView. * 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 b438e28d96..f99516bb0b 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,19 +1,13 @@ package com.mapbox.mapboxsdk.annotations; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.AnimatorSet; -import android.animation.ObjectAnimator; import android.content.Context; import android.graphics.PointF; -import android.os.CountDownTimer; import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.AnimationUtils; import android.widget.ImageView; import com.mapbox.mapboxsdk.R; @@ -43,7 +37,6 @@ public class MarkerViewManager { private long viewMarkerBoundsUpdateTime; private MapboxMap.OnMarkerViewClickListener onMarkerViewClickListener; private ImageMarkerViewAdapter defaultMarkerViewAdapter; - private CountDownTimer timer; /** * Creates an instance of MarkerViewManager. @@ -120,57 +113,22 @@ public class MarkerViewManager { for (final MarkerView marker : markerViewMap.keySet()) { final View convertView = markerViewMap.get(marker); if (convertView != null) { - if (marker.isAnimating() || !marker.shouldAnimate()) { - if (marker.isAnimating()) { - // cancel ongoing animations - marker.setAnimating(false); - AnimatorSet set = marker.getAnimation(); - List<Animator> animations = set.getChildAnimations(); - float x = (Float) ((ObjectAnimator) animations.get(0)).getAnimatedValue(); - float y = (Float) ((ObjectAnimator) animations.get(1)).getAnimatedValue(); - PointF pointF = new PointF(x + marker.getOffsetX(), y + marker.getOffsetY()); - marker.setPosition(mapboxMap.getProjection().fromScreenLocation(pointF)); - set.cancel(); - } - - // update position on map - PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); - if (marker.getOffsetX() == -1) { - int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth()); - int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight()); - marker.setOffsetX(x); - marker.setOffsetY(y); - } - - convertView.setX(point.x - marker.getOffsetX()); - convertView.setY(point.y - marker.getOffsetY()); - - // animate visibility - if (marker.isVisible() && convertView.getVisibility() == View.GONE) { - convertView.animate().cancel(); - convertView.setAlpha(0); - AnimatorUtils.alpha(convertView, 1); - } - } else { - if (timer == null) { - timer = new CountDownTimer(50, 560) { - @Override - public void onTick(long millisUntilFinished) { + PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); + if (marker.getOffsetX() == -1) { + int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth()); + int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight()); + marker.setOffsetX(x); + marker.setOffsetY(y); + } - } + convertView.setX(point.x - marker.getOffsetX()); + convertView.setY(point.y - marker.getOffsetY()); - @Override - public void onFinish() { - animate(marker, convertView); - } - }; - } else { - timer.cancel(); - PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); - convertView.setX(point.x - marker.getOffsetX()); - convertView.setY(point.y - marker.getOffsetY()); - } - timer.start(); + // animate visibility + if (marker.isVisible() && convertView.getVisibility() == View.GONE) { + convertView.animate().cancel(); + convertView.setAlpha(0); + AnimatorUtils.alpha(convertView, 1); } } } @@ -283,23 +241,17 @@ public class MarkerViewManager { * @param marker the MarkerView to remove */ public void removeMarkerView(MarkerView marker) { - boolean isAnimating = marker.isAnimating(); final View viewHolder = markerViewMap.get(marker); if (viewHolder != null && marker != null) { for (final MapboxMap.MarkerViewAdapter<?> adapter : markerViewAdapters) { if (adapter.getMarkerClass().equals(marker.getClass())) { - if (!isAnimating) { - if (adapter.prepareViewForReuse(marker, viewHolder)) { - adapter.releaseView(viewHolder); - } + if (adapter.prepareViewForReuse(marker, viewHolder)) { + adapter.releaseView(viewHolder); } } } } - - if (!isAnimating) { - markerViewMap.remove(marker); - } + markerViewMap.remove(marker); } /** @@ -373,7 +325,7 @@ public class MarkerViewManager { Iterator<MarkerView> iterator = markerViewMap.keySet().iterator(); while (iterator.hasNext()) { MarkerView m = iterator.next(); - if (!m.shouldAnimate() && !markers.contains(m)) { + if (!markers.contains(m)) { // remove marker convertView = markerViewMap.get(m); for (MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { @@ -445,50 +397,6 @@ public class MarkerViewManager { } } - public void animatePosition(@NonNull MarkerView marker, long duration) { - marker.setDuration(duration); - marker.setStartTime(AnimationUtils.currentAnimationTimeMillis()); - marker.setShouldAnimate(true); - animate(marker, markerViewMap.get(marker)); - } - - private void animate(final MarkerView marker, @Nullable View convertView) { - if (convertView != null) { - marker.setAnimating(true); - PointF screenLocation = mapboxMap.getProjection().toScreenLocation(marker.getTargetPosition()); - PointF currentLocation = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); - convertView.setX(currentLocation.x - marker.getOffsetX()); - convertView.setY(currentLocation.y - marker.getOffsetY()); - ObjectAnimator animatorX = ObjectAnimator.ofFloat(convertView, "x", screenLocation.x - marker.getOffsetX()); - ObjectAnimator animatorY = ObjectAnimator.ofFloat(convertView, "y", screenLocation.y - marker.getOffsetY()); - AnimatorSet set = new AnimatorSet(); - set.playTogether(animatorX, animatorY); - marker.setAnimation(set); - set.setDuration(marker.getRemainingTime()); - set.addListener(new AnimatorListenerAdapter() { - - private boolean canceled; - - @Override - public void onAnimationCancel(Animator animation) { - super.onAnimationCancel(animation); - canceled = true; - } - - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - if (!canceled) { - marker.setShouldAnimate(false); - marker.setPosition(marker.getTargetPosition()); - } - } - }); - marker.setAnimation(set); - set.start(); - } - } - /** * Default MarkerViewAdapter used for base class of MarkerView to adapt a MarkerView to an ImageView */ 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 f11d46dbaa..c26b079526 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 @@ -52,7 +52,7 @@ import java.util.concurrent.TimeUnit; * you must obtain one from the getMapAsync() method on a MapFragment or MapView that you have * added to your application. * <p> - * Note: Similar to a View object, a GoogleMap should only be read and modified from the main thread. + * Note: Similar to a View object, a MapboxMap should only be read and modified from the main thread. * </p> */ public class MapboxMap { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java index 76e662d6a7..118f4d1661 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java @@ -4,6 +4,7 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.animation.TypeEvaluator; +import android.animation.ValueAnimator; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; @@ -16,7 +17,6 @@ import android.view.animation.AccelerateDecelerateInterpolator; import com.mapbox.mapboxsdk.annotations.Icon; import com.mapbox.mapboxsdk.annotations.IconFactory; import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.annotations.MarkerViewOptions; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.geometry.LatLng; @@ -30,8 +30,6 @@ import java.util.Random; public class AnimatedMarkerActivity extends AppCompatActivity { - private final static String LOG_TAG = "AnimatedMarkerActivity"; - private MapView mMapView; private MapboxMap mMapboxMap; |