package com.evgenii.walktocircle.WalkMap;

import android.graphics.Point;
import android.location.Location;
import android.os.Handler;
import android.os.SystemClock;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

import com.evgenii.walktocircle.Utils.WalkGeo;
import com.evgenii.walktocircle.Utils.WalkLocation;
import com.evgenii.walktocircle.WalkConstants;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class DropPin {
    static private Marker mPreviousMarker;

    public void dropPin(Location currentLocation, GoogleMap map) {
        removePreviousMarker();

        Location pinLocation = WalkGeo.randomLocationAtDistanceRange(currentLocation,
                WalkConstants.minCircleDistanceFromCurrentLocationMeters,
                WalkConstants.maxCircleDistanceFromCurrentLocationMeters);

        LatLng latLng = WalkLocation.latLngFromLocation(pinLocation);
        MarkerOptions markerOptions = new MarkerOptions().position(latLng).title("Walk to Circle");
        mPreviousMarker = map.addMarker(markerOptions);
        animateMarker(mPreviousMarker, map);
    }

    private void removePreviousMarker() {
        if (mPreviousMarker == null) { return; }
        mPreviousMarker.remove();
    }

    private void animateMarker(final Marker marker, GoogleMap map) {
        final LatLng target = new LatLng(marker.getPosition().latitude, marker.getPosition().longitude);
        Projection projection = map.getProjection();
        Point startPoint = projection.toScreenLocation(target);
        startPoint.y = 0;
        final LatLng startLatLng = projection.fromScreenLocation(startPoint);

        final long duration = 400;
        final long startTime = SystemClock.uptimeMillis();
        final Interpolator interpolator = new LinearInterpolator();
        final Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - startTime;
                float t = interpolator.getInterpolation((float) elapsed / duration);
                double lng = t * target.longitude + (1 - t) * startLatLng.longitude;
                double lat = t * target.latitude + (1 - t) * startLatLng.latitude;
                marker.setPosition(new LatLng(lat, lng));
                if (t < 1.0) {
                    // Post again 10ms later.
                    handler.postDelayed(this, 5);
                } else {
                    // animation ended
                }
            }
        });
    }
}

@@ -36,16 +36,56 @@
 lkMap;%0A%0A
+import android.animation.TypeEvaluator;%0A
 import a
@@ -199,16 +199,134 @@
 mClock;%0A
+import android.view.animation.AccelerateDecelerateInterpolator;%0Aimport android.view.animation.AccelerateInterpolator;%0A
 import a
@@ -412,16 +412,73 @@
 lator;%0A%0A
+import com.evgenii.walktocircle.Libs.BounceInterpolator;%0A
 import c
@@ -2212,22 +2212,22 @@
 r = new 
-Linear
+Bounce
 Interpol
@@ -2231,16 +2231,22 @@
 polator(
+0.1, 2
 );%0A     
@@ -2785,15 +2785,26 @@
 if (
-t %3C 1.0
+elapsed %3C duration
 ) %7B%0A
@@ -2948,45 +2948,530 @@
     
-// animation ended%0A                %7D%0A
+marker.setPosition(target);%0A                %7D%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private void animateMarkerTwo(final Marker marker, GoogleMap map) %7B%0A//        final Interpolator interpolator = new AccelerateDecelerateInterpolator();%0A//%0A//        TypeEvaluator%3CLatLng%3E typeEvaluator = new TypeEvaluator%3CLatLng%3E() %7B%0A//            @Override%0A//            public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) %7B%0A//                return latLngInterpolator.interpolate(fraction, startValue, endValue);%0A//
     
@@ -3472,32 +3472,34 @@
 //            %7D%0A
+//
         %7D);%0A    
@@ -3483,27 +3483,300 @@
    %7D%0A//        %7D
+;%0A//        Property%3CMarker, LatLng%3E property = Property.of(Marker.class, LatLng.class, %22position%22);%0A//        ObjectAnimator animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, finalPosition);%0A//        animator.setDuration(3000);%0A//        animator.start(
 );%0A    %7D%0A%7D%0A

Drop a pin