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.example.hellogooglemaps.MarkerDemoActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override//from  www.  j  av  a2  s. co  m
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color.
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(new Random().nextFloat() * 360));
    }
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

From source file:crackerjack.education.Indijisites.StartUp.java

@Override
public boolean onMarkerClick(final Marker marker) {
    // This method makes the marker bounce when you click on it. It's not really needed, but it's a neat feature.
    // Will expand this if offered more time.
    if (marker.equals(mBrisbane)) {
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        Projection proj = mMap.getProjection();
        Point startPoint = proj.toScreenLocation(BRISBANE);
        startPoint.offset(0, -100);//from  w ww  . j  ava  2s  . com
        final LatLng startLatLng = proj.fromScreenLocation(startPoint);
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = interpolator.getInterpolation((float) elapsed / duration);
                double lng = t * BRISBANE.longitude + (1 - t) * startLatLng.longitude; // This allows the marker to pinpoint if offscreen (I think =/)
                double lat = t * BRISBANE.latitude + (1 - t) * startLatLng.latitude;
                marker.setPosition(new LatLng(lat, lng));

                if (t < 1.0) {
                    // Post again 16ms later
                    handler.postDelayed(this, 16);
                }
            }
        });
    }
    //False is returned to indicate we have not consumed the event and that we wish
    //for the default behaviour to occur (move to marker location).
    return false;
}

From source file:de.quist.app.maps.example.MarkerDemoActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override/*  w  ww .j  av a2 s .  c  o m*/
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(
                BuildConfig.MAP_BINDING.bitmapDescriptorFactory().defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }

    mLastSelectedMarker = marker;
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

From source file:com.example.com.benasque2014.mercurio.PuntosInfoFragment.java

private void addPoint(LatLng point) {
    if (markers == null)
        markers = new ArrayList<Marker>();
    if (points == null)
        points = new ArrayList<LatLng>();
    MarkerOptions marker = new MarkerOptions().position(point).title("Parada " + markers.size() + 1);

    final Marker mMarker = mMap.addMarker(marker);

    //if (markers.size()==0)
    //   Toast.makeText(getActivity(), "Haga click en un punto para eliminarlo", Toast.LENGTH_SHORT).show();

    markers.add(mMarker);/*from w w  w . j  av  a 2 s. com*/

    //mPage.getData().putParcelableArrayList(PuntosInfoPage.PUNTOS_DATA_KEY, (ArrayList<? extends Parcelable>) points);
    //mPage.notifyDataChanged();

    // This causes the marker at Perth to bounce into position when it is clicked.
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final long duration = 1500;

    final Interpolator interpolator = new BounceInterpolator();

    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
            mMarker.setAnchor(0.5f, 1.0f + 2 * t);

            if (t > 0.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            }
        }
    });
    //TODO: si queremos aadir lineas entre los puntos
    //addLines();
}

From source file:com.example.mapdemo.VisibleRegionDemoActivity.java

public void animatePadding(final int toLeft, final int toTop, final int toRight, final int toBottom) {

    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final long duration = 1000;

    final Interpolator interpolator = new OvershootInterpolator();

    final int startLeft = currentLeft;
    final int startTop = currentTop;
    final int startRight = currentRight;
    final int startBottom = currentBottom;

    currentLeft = toLeft;/* ww w .  j ava2  s .c  o m*/
    currentTop = toTop;
    currentRight = toRight;
    currentBottom = toBottom;

    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);

            int left = (int) (startLeft + ((toLeft - startLeft) * t));
            int top = (int) (startTop + ((toTop - startTop) * t));
            int right = (int) (startRight + ((toRight - startRight) * t));
            int bottom = (int) (startBottom + ((toBottom - startBottom) * t));

            mMap.setPadding(left, top, right, bottom);

            if (elapsed < duration) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            }
        }
    });
}

From source file:com.ibm.pickmeup.activities.MapActivity.java

/**
 * Update map with the new coordinates for the driver
 * @param intent containing driver coordinates
 *///w  ww.  j a va2 s.  c o  m
private void updateMap(final Intent intent) {
    // not logging entry as it will flood the logs

    // getting driver LatLng values from the intent
    final LatLng driverLatLng = new LatLng(intent.getFloatExtra(Constants.LATITUDE, 0),
            intent.getFloatExtra(Constants.LONGITUDE, 0));

    // create driver marker if it doesn't exist and move the camera accordingly
    if (driverMarker == null) {
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(driverLatLng, 10));
        driverMarker = mMap.addMarker(new MarkerOptions().position(driverLatLng)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_driver)));
        return;
    }

    // update driver location with LatLng
    driverLocation.setLatitude(driverLatLng.latitude);
    driverLocation.setLongitude(driverLatLng.longitude);

    // calculate current distance to the passenger
    float distance = passengerLocation.distanceTo(driverLocation) / 1000;

    // set the distance text
    distanceDetails.setText(String.format(getResources().getString(R.string.distance_with_value), distance));

    // calculating ETA - we are assuming here that the car travels at 20mph to simplify the calculations
    calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, Math.round(distance / 20 * 60));

    // set AM/PM to a relevant value
    AM_PM = getString(R.string.am);
    if (calendar.get(Calendar.AM_PM) == 1) {
        AM_PM = getString(R.string.pm);
    }

    // format ETA string to HH:MM
    String eta = String.format(getResources().getString(R.string.eta_with_value),
            calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), AM_PM);

    // set the ETA text
    etaDetails.setText(eta);

    // as we are throttling updates to the coordinates, we might need to smooth out the moving
    // of the driver's marker. To do so we are going to draw temporary markers between the
    // previous and the current coordinates. We are going to use interpolation for this and
    // use handler/looper to set the marker's position

    // get hold of the handler
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();

    // get map projection and the driver's starting point
    Projection proj = mMap.getProjection();
    Point startPoint = proj.toScreenLocation(driverMarker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);
    final long duration = 150;

    // create new Interpolator
    final Interpolator interpolator = new LinearInterpolator();

    // post a Runnable to the handler
    handler.post(new Runnable() {
        @Override
        public void run() {
            // calculate how soon we need to redraw the marker
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * intent.getFloatExtra(Constants.LONGITUDE, 0) + (1 - t) * startLatLng.longitude;
            double lat = t * intent.getFloatExtra(Constants.LATITUDE, 0) + (1 - t) * startLatLng.latitude;

            // set the driver's marker position
            driverMarker.setPosition(new LatLng(lat, lng));
            if (t < 1.0) {
                handler.postDelayed(this, 10);
            }
        }
    });
}

From source file:com.campusclipper.android.MyLocationActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override//from  w ww.j a  v  a  2  s.  c o m
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

From source file:com.shollmann.igcparser.ui.activity.FlightPreviewActivity.java

private void animateMarker() {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    duration = 300000;/*  w  ww  . j a v a  2  s .c o  m*/

    final Interpolator interpolator = new LinearInterpolator();

    handler.post(new Runnable() {
        int i = 0;

        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            if (i < listLatLngPoints.size()) {
                Double heading = SphericalUtil.computeHeading(markerGlider.getPosition(),
                        listLatLngPoints.get(i));
                markerGlider.setRotation(heading.floatValue());
                markerGlider.setPosition(listLatLngPoints.get(i));
            }
            i++;

            if (t < 1.0 && i < listLatLngPoints.size() && !isFinishReplay) {
                handler.postDelayed(this, replaySpeed);
            } else {
                finishReplay();
            }
        }
    });
}

From source file:fashiome.android.fragments.MapListFragment.java

private void dropPinEffect(final Marker marker) {
    // Handler allows us to repeat a code block after a specified delay
    final android.os.Handler handler = new android.os.Handler();
    final long start = SystemClock.uptimeMillis();
    final long duration = 1500;

    // Use the bounce interpolator
    final android.view.animation.Interpolator interpolator = new BounceInterpolator();

    // Animate marker with a bounce updating its position every 15ms
    handler.post(new Runnable() {
        @Override/* www  . j a  va 2s. co  m*/
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            // Calculate t for bounce based on elapsed time
            float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
            // Set the anchor
            marker.setAnchor(0.5f, 1.0f + 14 * t);

            if (t > 0.0) {
                // Post this event again 15ms from now.
                handler.postDelayed(this, 15);
            } else { // done elapsing, show window
                marker.showInfoWindow();
            }
        }
    });
}

From source file:com.trackdroid.activities.ShowInMapActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it
        // is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override/*from www  . j a v  a2 s  .  c  o m*/
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }
    // We return false to indicate that we have not consumed the event and
    // that we wish
    // for the default behavior to occur (which is for the camera to move
    // such that the
    // marker is centered and for the marker's info window to open, if it
    // has one).
    return false;
}