summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-05-11 16:18:03 +0200
committerTobrun <tobrun@mapbox.com>2016-05-20 12:00:03 +0200
commit833319ce91de01a63373748eed75bfefd517b4b1 (patch)
tree4f666a7c5eca26768db46e88d08d3996d5140870
parentdb2c3e59e34c8981e468a1835a064e1c1bbc252e (diff)
downloadqtlocation-mapboxgl-833319ce91de01a63373748eed75bfefd517b4b1.tar.gz
[android] #3276 - add show/hide animation to view markers
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java15
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java30
3 files changed, 40 insertions, 10 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
index f8dc5e3484..124de326c4 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
@@ -33,6 +33,11 @@ public class MapboxConstants {
public static final int ANIMATION_DURATION = 300;
/**
+ * Default short animation time
+ */
+ public static final int ANIMATION_DURATION_SHORT = 150;
+
+ /**
* The currently supported minimum zoom level.
*/
public static final float MINIMUM_ZOOM = 0.0f;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 02b2298948..4468e4f5da 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -1,6 +1,8 @@
package com.mapbox.mapboxsdk.maps;
import android.Manifest;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
@@ -36,6 +38,7 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.util.LongSparseArray;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ScaleGestureDetectorCompat;
+import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.AttributeSet;
@@ -1444,8 +1447,16 @@ public class MapView extends FrameLayout {
mViewHolder.setX(point.x - (mViewHolder.getMeasuredWidth() / 2));
mViewHolder.setY(point.y - (mViewHolder.getMeasuredHeight() / 2));
- if (mViewHolder.getVisibility() == View.GONE) {
- mViewHolder.setVisibility(View.VISIBLE);
+ if (mViewHolder.getVisibility() == GONE) {
+ mViewHolder.animate().cancel();
+ mViewHolder.setAlpha(0);
+ mViewHolder.animate().alpha(1).setDuration(MapboxConstants.ANIMATION_DURATION_SHORT).setInterpolator(new FastOutSlowInInterpolator()).setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationStart(Animator animation) {
+ super.onAnimationStart(animation);
+ mViewHolder.setVisibility(VISIBLE);
+ }
+ }).start();
}
}
}
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 69a025733f..5e4f4b872c 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
@@ -4,7 +4,6 @@ import android.content.Context;
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
-import android.animation.ObjectAnimator;
import android.graphics.Bitmap;
import android.location.Location;
import android.os.SystemClock;
@@ -15,6 +14,7 @@ import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.util.LongSparseArray;
import android.support.v4.util.Pools;
+import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -22,7 +22,6 @@ import android.view.View;
import com.mapbox.mapboxsdk.MapboxAccountManager;
import android.view.ViewGroup;
-import android.view.animation.Animation;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
@@ -655,9 +654,7 @@ public class MapboxMap {
for (Map.Entry<Marker, View> outBoundsEntry : outBoundsMarker.entrySet()) {
convertView = outBoundsEntry.getValue();
if (convertView != null) {
- convertView.setVisibility(View.GONE);
- viewSimplePool.release(convertView);
- mMarkerViews.remove(outBoundsEntry.getKey().getId());
+ removeMarkerView(outBoundsEntry.getKey().getId());
}
}
@@ -998,10 +995,27 @@ public class MapboxMap {
}
private void removeMarkerView(long id) {
- View viewHolder = mMarkerViews.get(id);
+ final View viewHolder = mMarkerViews.get(id);
if (viewHolder != null) {
- viewHolder.setVisibility(View.GONE);
- viewSimplePool.release(viewHolder);
+
+ // 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);
+ viewSimplePool.release(viewHolder);
+ }
+ });
}
mMarkerViews.remove(id);
}