Example usage for android.view.animation Interpolator getInterpolation

List of usage examples for android.view.animation Interpolator getInterpolation

Introduction

In this page you can find the example usage for android.view.animation Interpolator getInterpolation.

Prototype

float getInterpolation(float input);

Source Link

Document

Maps a value representing the elapsed fraction of an animation to a value that represents the interpolated fraction.

Usage

From source file:com.corporatetaxi.TaxiOntheWay_Activity.java

private void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);//marker1.getPosition();
    final long duration = 600;

    final Interpolator interpolator = new LinearInterpolator();
    handler.post(new Runnable() {
        @Override/*from www  .j a  v a  2 s. c  o m*/
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude;
            double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));

            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            } else {
                if (hideMarker) {
                    marker.setVisible(false);
                } else {
                    marker.setVisible(true);
                }
            }
            map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng)));
        }
    });

}

From source file:com.goka.flickableview.ImageViewTouchBase.java

protected void zoomTo(float scale, float centerX, float centerY, final long durationMs) {
    if (scale > getMaxScale()) {
        scale = getMaxScale();//w ww  .j a va2s  .  co  m
    }

    final float oldScale = getScale();

    Matrix m = new Matrix(mSuppMatrix);
    m.postScale(scale, scale, centerX, centerY);
    RectF rect = getCenter(m, true, true);

    final float finalScale = scale;
    final float destX = centerX + rect.left * scale;
    final float destY = centerY + rect.top * scale;

    stopAllAnimations();

    ValueAnimatorCompat animatorCompat = AnimatorCompatHelper.emptyValueAnimator();
    animatorCompat.setDuration(durationMs);
    final Interpolator interpolator = new DecelerateInterpolator(1.0f);
    animatorCompat.addUpdateListener(new AnimatorUpdateListenerCompat() {
        @Override
        public void onAnimationUpdate(ValueAnimatorCompat animation) {
            float fraction = interpolator.getInterpolation(animation.getAnimatedFraction());
            float value = oldScale + (fraction * (finalScale - oldScale));
            zoomTo(value, destX, destY);
        }
    });
    animatorCompat.start();
}

From source file:com.corporatetaxi.TaxiArrived_Acitivity.java

private void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);
    final long duration = 1000;

    final Interpolator interpolator = new LinearInterpolator();
    handler.post(new Runnable() {
        @Override/*from w w w  .  j  a  v a 2s .com*/
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude;
            double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));

            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            } else {
                if (hideMarker) {
                    marker.setVisible(false);
                } else {
                    marker.setVisible(true);
                }
            }
            map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng)));
        }
    });
}

From source file:com.goka.flickableview.ImageViewTouchBase.java

protected void scrollBy(final float distanceX, final float distanceY, final long durationMs) {
    ValueAnimatorCompat animatorCompat = AnimatorCompatHelper.emptyValueAnimator();
    animatorCompat.setDuration(durationMs);

    stopAllAnimations();//from  ww w . j  a v  a  2  s  .c  o  m

    mCurrentAnimation = animatorCompat;
    mCurrentAnimation.start();

    final Interpolator interpolator = new DecelerateInterpolator();
    animatorCompat.addUpdateListener(new AnimatorUpdateListenerCompat() {
        float oldValueX = 0;

        float oldValueY = 0;

        @Override
        public void onAnimationUpdate(ValueAnimatorCompat animation) {
            float fraction = interpolator.getInterpolation(animation.getAnimatedFraction());
            float valueX = fraction * distanceX;
            float valueY = fraction * distanceY;
            panBy(valueX - oldValueX, valueY - oldValueY);

            oldValueX = valueX;
            oldValueY = valueY;
        }
    });

    mCurrentAnimation.addListener(new AnimatorListenerCompat() {
        @Override
        public void onAnimationStart(ValueAnimatorCompat animation) {

        }

        @Override
        public void onAnimationEnd(ValueAnimatorCompat animation) {
            RectF centerRect = getCenter(mSuppMatrix, true, true);
            if (centerRect.left != 0 || centerRect.top != 0) {
                scrollBy(centerRect.left, centerRect.top);
            }
        }

        @Override
        public void onAnimationCancel(ValueAnimatorCompat animation) {

        }

        @Override
        public void onAnimationRepeat(ValueAnimatorCompat animation) {

        }
    });

}

From source file:com.usertaxi.TaxiOntheWay_Activity.java

private void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);//marker1.getPosition();
    final long duration = 600;

    final Interpolator interpolator = new LinearInterpolator();
    handler.post(new Runnable() {
        @Override//from  w  w  w  .  ja v  a  2 s .co  m
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude;
            double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));

            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            } else {
                if (hideMarker) {
                    marker.setVisible(false);
                } else {
                    marker.setVisible(true);
                }
            }
            //   map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng)));
        }
    });

    AppPreferences.setPreviouslat(getApplicationContext(),
            AppPreferences.getCurrentlat(getApplicationContext()));
    AppPreferences.setPreviouslong(getApplicationContext(),
            AppPreferences.getCurrentlong(getApplicationContext()));
}

From source file:com.iride.ayride.HomePageActivity.java

private void animateMarkerTo(final Marker marker, final double lat, final double lng) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final long DURATION_MS = 1000;
    final Interpolator interpolator = new AccelerateDecelerateInterpolator();
    final LatLng startPosition = marker.getPosition();
    handler.post(new Runnable() {
        @Override//from  w w w .  j ava  2  s. c om
        public void run() {
            float elapsed = SystemClock.uptimeMillis() - start;
            float t = elapsed / DURATION_MS;
            float v = interpolator.getInterpolation(t);

            double currentLat = (lat - startPosition.latitude) * v + startPosition.latitude;
            double currentLng = (lng - startPosition.longitude) * v + startPosition.longitude;
            marker.setPosition(new LatLng(currentLat, currentLng));

            // if animation is not finished yet, repeat
            if (t < 1) {
                handler.postDelayed(this, 16);
            }
        }
    });
}