Example usage for android.view.animation LinearInterpolator LinearInterpolator

List of usage examples for android.view.animation LinearInterpolator LinearInterpolator

Introduction

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

Prototype

public LinearInterpolator() 

Source Link

Usage

From source file:com.example.waitou.rxjava.LoadingView.java

/**
 * build FlexibleAnimation to control the progress
 *
 * @return Animatorset for control the progress
 *///from   www  .j a v  a 2 s .c o  m
private AnimatorSet buildFlexibleAnimation() {
    final Ring ring = mRing;
    AnimatorSet set = new AnimatorSet();
    ValueAnimator increment = ValueAnimator.ofFloat(0, MAX_PROGRESS_ARC - MIN_PROGRESS_ARC)
            .setDuration(ANIMATOR_DURATION / 2);
    increment.setInterpolator(new LinearInterpolator());
    increment.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float sweeping = ring.sweeping;
            final float value = (float) animation.getAnimatedValue();
            ring.sweep = sweeping + value;
            invalidate();
        }
    });
    increment.addListener(animatorListener);
    ValueAnimator reduce = ValueAnimator.ofFloat(0, MAX_PROGRESS_ARC - MIN_PROGRESS_ARC)
            .setDuration(ANIMATOR_DURATION / 2);
    reduce.setInterpolator(interpolator);
    reduce.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float sweeping = ring.sweeping;
            float starting = ring.starting;
            float value = (float) animation.getAnimatedValue();
            ring.sweep = sweeping - value;
            ring.start = starting + value;
        }
    });
    set.play(reduce).after(increment);
    return set;
}

From source file:com.example.google.maps.flyover.MainActivity.java

public void animateRoute() {
    LinkedList<Animator> animators = new LinkedList<Animator>();

    // For each segment of the route, create one heading adjustment animator
    // and one segment fly-over animator.
    for (int i = 0; i < ROUTE.length - 1; i++) {
        // If it the first segment, ensure the camera is rotated properly.
        float h1;
        if (i == 0) {
            h1 = mMap.getCameraPosition().bearing;
        } else {//from www.ja  v  a 2 s  .  co m
            h1 = (float) SphericalUtil.computeHeading(ROUTE[i - 1], ROUTE[i]);
        }

        float h2 = (float) SphericalUtil.computeHeading(ROUTE[i], ROUTE[i + 1]);

        ValueAnimator va = ValueAnimator.ofFloat(h1, h2);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float bearing = (Float) animation.getAnimatedValue();
                CameraPosition pos = CameraPosition.builder(mMap.getCameraPosition()).bearing(bearing).build();
                mMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos));
            }
        });

        // Use the change in degrees of the heading for the animation
        // duration.
        long d = Math.round(Math.abs(h1 - h2));
        va.setDuration(d * CAMERA_HEADING_CHANGE_RATE);
        animators.add(va);

        ObjectAnimator oa = ObjectAnimator.ofObject(mMarker, "position",
                new LatLngEvaluator(ROUTE[i], ROUTE[i + 1]), ROUTE[i], ROUTE[i + 1]);

        oa.setInterpolator(new LinearInterpolator());
        oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                LatLng target = (LatLng) animation.getAnimatedValue();
                mMap.moveCamera(CameraUpdateFactory.newLatLng(target));
            }
        });

        // Use the distance of the route segment for the duration.
        double dist = SphericalUtil.computeDistanceBetween(ROUTE[i], ROUTE[i + 1]);
        oa.setDuration(Math.round(dist) * 10);

        animators.add(oa);
    }

    mAnimatorSet = new AnimatorSet();
    mAnimatorSet.playSequentially(animators);
    mAnimatorSet.start();

    mAnimatorSet.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationCancel(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_replay);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_replay);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationStart(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_stop);
        }
    });
}

From source file:com.wl.tabguidance.utils.TabLayoutTitleStrip.java

public TabLayoutTitleStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTS//www .  ja  v a 2 s  . c  o  m

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TabTitleStrip);
    try {
        setStripColor(typedArray.getColor(R.styleable.TabTitleStrip_nts_color, DEFAULT_STRIP_COLOR));
        setTitleSize(typedArray.getDimension(R.styleable.TabTitleStrip_nts_size, DEFAULT_TITLE_SIZE));
        setStripWeight(typedArray.getDimension(R.styleable.TabTitleStrip_nts_weight, DEFAULT_STRIP_WEIGHT));
        setStripFactor(typedArray.getFloat(R.styleable.TabTitleStrip_nts_factor, DEFAULT_STRIP_FACTOR));
        setStripType(typedArray.getInt(R.styleable.TabTitleStrip_nts_type, StripType.LINE_INDEX));
        setStripGravity(typedArray.getInt(R.styleable.TabTitleStrip_nts_gravity, StripGravity.BOTTOM_INDEX));

        setTypeface(typedArray.getString(R.styleable.TabTitleStrip_nts_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.TabTitleStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(typedArray.getColor(R.styleable.TabTitleStrip_nts_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.TabTitleStrip_nts_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(
                typedArray.getDimension(R.styleable.TabTitleStrip_nts_corners_radius, DEFAULT_CORNER_RADIUS));

        // Get titles
        String[] titles = null;
        try {
            final int titlesResId = typedArray.getResourceId(R.styleable.TabTitleStrip_nts_titles, 0);
            titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId);
        } catch (Exception exception) {
            titles = null;
            exception.printStackTrace();
        } finally {
            if (titles == null) {
                if (isInEditMode()) {
                    titles = new String[new Random().nextInt(5) + 1];
                    Arrays.fill(titles, PREVIEW_TITLE);
                } else
                    titles = new String[0];
            }

            setTitles(titles);
        }

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });
    } finally {
        typedArray.recycle();
    }
}

From source file:com.gigamole.navigationtabstrip.NavigationTabStrip.java

public NavigationTabStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTS//from  ww  w  .  j a  v a2  s.c om

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabStrip);
    try {
        setStripColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_color, DEFAULT_STRIP_COLOR));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_size, DEFAULT_TITLE_SIZE));
        setStripWeight(
                typedArray.getDimension(R.styleable.NavigationTabStrip_nts_weight, DEFAULT_STRIP_WEIGHT));
        setStripFactor(typedArray.getFloat(R.styleable.NavigationTabStrip_nts_factor, DEFAULT_STRIP_FACTOR));
        setStripType(typedArray.getInt(R.styleable.NavigationTabStrip_nts_type, StripType.LINE_INDEX));
        setStripGravity(
                typedArray.getInt(R.styleable.NavigationTabStrip_nts_gravity, StripGravity.BOTTOM_INDEX));

        setTypeface(typedArray.getString(R.styleable.NavigationTabStrip_nts_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabStrip_nts_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabStrip_nts_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_corners_radius,
                DEFAULT_CORNER_RADIUS));

        // Get titles
        String[] titles = null;
        try {
            final int titlesResId = typedArray.getResourceId(R.styleable.NavigationTabStrip_nts_titles, 0);
            titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId);
        } catch (Exception exception) {
            titles = null;
            exception.printStackTrace();
        } finally {
            if (titles == null) {
                if (isInEditMode()) {
                    titles = new String[new Random().nextInt(5) + 1];
                    Arrays.fill(titles, PREVIEW_TITLE);
                } else
                    titles = new String[0];
            }

            setTitles(titles);
        }

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });
    } finally {
        typedArray.recycle();
    }
}

From source file:com.plusub.lib.example.view.TabView.java

/**
 * ?/*from w w  w .ja va2  s. c  o m*/
 * @param arg0
 */
private void moveCursor(int arg0) {
    TranslateAnimation animation = new TranslateAnimation(mCursorCurPosition, arg0 * mScreenWidth / tabCount,
            Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF);
    mCursorCurPosition = arg0 * mScreenWidth / tabCount;
    animation.setDuration(200);
    animation.setInterpolator(new LinearInterpolator());
    animation.setFillAfter(true);
    mIvCursor.startAnimation(animation);
}

From source file:com.fastbootmobile.encore.app.adapters.SongsListAdapter.java

/**
 * {@inheritDoc}/*from w ww.  j  a v  a 2s  .com*/
 */
@Override
public View getView(final int position, final View convertView, ViewGroup parent) {
    final Context ctx = parent.getContext();
    assert ctx != null;
    final ProviderAggregator aggregator = ProviderAggregator.getDefault();

    View root = convertView;
    if (convertView == null) {
        // Recycle the existing view
        LayoutInflater inflater = LayoutInflater.from(ctx);
        root = inflater.inflate(R.layout.item_playlist_view, parent, false);
        assert root != null;

        ViewHolder holder = new ViewHolder();
        holder.tvTitle = (TextView) root.findViewById(R.id.tvTitle);
        holder.tvArtist = (TextView) root.findViewById(R.id.tvArtist);
        holder.tvDuration = (TextView) root.findViewById(R.id.tvDuration);
        holder.ivOverflow = (ImageView) root.findViewById(R.id.ivOverflow);
        holder.ivAlbumArt = (AlbumArtImageView) root.findViewById(R.id.ivAlbumArt);
        holder.ivOffline = (ImageView) root.findViewById(R.id.ivOffline);
        holder.vCurrentIndicator = root.findViewById(R.id.currentSongIndicator);
        holder.vRoot = (ViewGroup) root;

        holder.vRoot.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        if (mShowAlbumArt) {
            // Fixup some style stuff
            holder.ivAlbumArt.setVisibility(View.VISIBLE);
        } else {
            holder.ivAlbumArt.setVisibility(View.GONE);
        }

        holder.ivOverflow.setOnClickListener(mOverflowClickListener);
        holder.ivOverflow.setTag(holder);
        root.setTag(holder);
    }
    final Song song = getItem(position);
    final ViewHolder tag = (ViewHolder) root.getTag();

    // Update tag
    tag.position = position;
    tag.song = song;
    root.setTag(tag);

    // Fill fields
    if (song != null && song.isLoaded()) {
        tag.tvTitle.setText(song.getTitle());
        tag.tvDuration.setText(Utils.formatTrackLength(song.getDuration()));

        if (mShowAlbumArt) {
            tag.ivAlbumArt.loadArtForSong(song);
        }

        if (song.getArtist() == null) {
            tag.tvArtist.setText(null);
        } else {
            Artist artist = aggregator.retrieveArtist(song.getArtist(), song.getProvider());
            if (artist != null) {
                tag.tvArtist.setText(artist.getName());
            } else {
                tag.tvArtist.setText("...");
            }
        }
    } else {
        tag.tvTitle.setText("...");
        tag.tvDuration.setText("...");
        tag.tvArtist.setText("...");

        if (mShowAlbumArt) {
            tag.ivAlbumArt.setDefaultArt();
        }
    }

    // Set current song indicator
    tag.vCurrentIndicator.setVisibility(View.INVISIBLE);

    Song currentSong = PlaybackProxy.getCurrentTrack();
    if (currentSong != null && currentSong.equals(tag.song)) {
        tag.vCurrentIndicator.setVisibility(View.VISIBLE);
    }

    if (song != null) {
        // Set alpha based on offline availability and mode
        if ((aggregator.isOfflineMode() && song.getOfflineStatus() != BoundEntity.OFFLINE_STATUS_READY)
                || !song.isAvailable()) {
            Utils.setChildrenAlpha(tag.vRoot,
                    Float.parseFloat(ctx.getResources().getString(R.string.unavailable_track_alpha)));
        } else {
            Utils.setChildrenAlpha(tag.vRoot, 1.0f);
        }

        // Show offline indicator in any case
        tag.ivOffline.setVisibility(View.VISIBLE);
        tag.ivOffline.clearAnimation();
        if (song.getOfflineStatus() == BoundEntity.OFFLINE_STATUS_READY) {
            tag.ivOffline.setImageResource(R.drawable.ic_track_downloaded);
        } else if (song.getOfflineStatus() == BoundEntity.OFFLINE_STATUS_DOWNLOADING) {
            tag.ivOffline.setImageResource(R.drawable.ic_sync_in_progress);

            if (mSyncRotateAnimation == null && tag.ivOffline.getMeasuredWidth() != 0) {
                mSyncRotateAnimation = new RotateAnimation(0, -360, tag.ivOffline.getMeasuredWidth() / 2.0f,
                        tag.ivOffline.getMeasuredHeight() / 2.0f);
                mSyncRotateAnimation.setRepeatMode(Animation.INFINITE);
                mSyncRotateAnimation.setRepeatCount(Animation.INFINITE);
                mSyncRotateAnimation.setDuration(1000);
                mSyncRotateAnimation.setInterpolator(new LinearInterpolator());
            }

            if (mSyncRotateAnimation != null) {
                tag.ivOffline.startAnimation(mSyncRotateAnimation);
            }
        } else if (song.getOfflineStatus() == BoundEntity.OFFLINE_STATUS_ERROR) {
            tag.ivOffline.setImageResource(R.drawable.ic_sync_problem);
        } else if (song.getOfflineStatus() == BoundEntity.OFFLINE_STATUS_PENDING) {
            tag.ivOffline.setImageResource(R.drawable.ic_track_download_pending);
        } else {
            tag.ivOffline.setVisibility(View.GONE);
        }
    }

    return root;
}

From source file:com.sociablue.nanodegree_p1.MovieListFragment.java

private void initializeFab(View rootView) {
    final RelativeLayout buttonContainer = (RelativeLayout) rootView.findViewById(R.id.menu_button_container);
    final FloatingActionButton Fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    final ImageView bottomBar = (ImageView) rootView.findViewById(R.id.menu_bottom_bar);
    final ImageView topBar = (ImageView) rootView.findViewById(R.id.menu_top_bar);
    Fab.setOnClickListener(new View.OnClickListener() {
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override//from   w w  w . j  a v  a2s  .c o m
        public void onClick(View v) {

            //Menu Button Icon Animation
            //Setting up necessary variables
            long animationDuration = 500;
            float containerHeight = buttonContainer.getHeight();
            float containerCenterY = containerHeight / 2;
            float containerCenterX = buttonContainer.getWidth() / 2;
            float topBarCenter = topBar.getTop() + topBar.getHeight() / 2;
            float widthOfBar = topBar.getWidth();
            float heightOfBar = topBar.getHeight();
            final float distanceBetweenBars = (containerCenterY - topBarCenter);

            /**
             *TODO: Refactor block of code to use Value Property Animator. Should be more efficient to animate multiple properties
             *and objects at the same time. Also, will try to break intialization into smaller functions.
             */

            //Setting up animations of hamburger bars and rotation

            /**
             * Animation For Top Menu Button Icon Bar. Sliding from the top to rest on top of the middle bar.
             * Y Translation is 1/2 the height of the hamburger bar minus the distance.
             * Subtracting the distance from the height because the distance between bars is
             * calculated of the exact center of the button.
             * With out the subtraction the bar would translate slightly below the middle bar.
             */
            float yTranslation = heightOfBar / 2 - distanceBetweenBars;
            float xTranslation = widthOfBar / 2 + heightOfBar / 2;
            TranslateAnimation topBarTranslationAnim = new TranslateAnimation(Animation.ABSOLUTE, 0f,
                    Animation.ABSOLUTE, 0F, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, distanceBetweenBars);
            topBarTranslationAnim.setDuration((long) (animationDuration * 0.8));
            topBarTranslationAnim.setFillAfter(true);

            //Animation for bottom hamburger bar. Translates and Rotates to create 'X'
            AnimationSet bottomBarAnimation = new AnimationSet(true);
            bottomBarAnimation.setFillAfter(true);

            //Rotate to create cross. (The cross becomes the X after the button rotation completes"
            RotateAnimation bottomBarRotationAnimation = new RotateAnimation(0f, 90f,
                    Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
            bottomBarRotationAnimation.setDuration(animationDuration);
            bottomBarAnimation.addAnimation(bottomBarRotationAnimation);

            //Translate to correct X alignment
            TranslateAnimation bottomBarTranslationAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0f,
                    Animation.ABSOLUTE, -xTranslation, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE,
                    -yTranslation);
            bottomBarTranslationAnimation.setDuration(animationDuration);
            bottomBarAnimation.addAnimation(bottomBarTranslationAnimation);

            //Button Specific Animations
            //Rotate Button Container
            RotateAnimation containerRotationAnimation = new RotateAnimation(0, 135f,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            containerRotationAnimation.setDuration(animationDuration);
            containerRotationAnimation.setFillAfter(true);

            //Animate change of button color between Active and Disabled colors that have been
            //defined in color.xml
            int activeColor = getResources().getColor(R.color.active_button);
            int disabledColor = getResources().getColor(R.color.disabled_button);

            //Need to use ValueAnimator because property animator does not support BackgroundTint
            ValueAnimator buttonColorAnimation = ValueAnimator.ofArgb(activeColor, disabledColor);
            buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    Fab.setBackgroundTintList(ColorStateList.valueOf((int) animation.getAnimatedValue()));
                }
            });
            buttonColorAnimation.setDuration(animationDuration);

            //Start all the animations
            topBar.startAnimation(topBarTranslationAnim);
            bottomBar.startAnimation(bottomBarAnimation);
            buttonContainer.startAnimation(containerRotationAnimation);
            buttonColorAnimation.start();

            //Toogle mMenu open and closed
            if (mMenu.isOpen()) {
                //If mMenu is open, do the reverse of the animation
                containerRotationAnimation
                        .setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                topBarTranslationAnim.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                bottomBarAnimation.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
                buttonColorAnimation.setInterpolator(new ReverseInterpolator(new LinearInterpolator()));
                mMenu.close();
            } else {
                bottomBarAnimation.setInterpolator(new AccelerateInterpolator());
                mMenu.open();
            }
        }
    });
}

From source file:com.example.fansonlib.widget.calendar.CalendarView.java

/**
 * //from   w ww  .  j  a  va 2s.  c  o  m
 *
 * @param year 
 */
public void showSelectLayout(final int year) {
    if (mParentLayout != null && mParentLayout.mContentView != null) {
        mParentLayout.mContentView.setVisibility(GONE);
    }
    mLinearWeek.animate().translationY(-mLinearWeek.getHeight()).setInterpolator(new LinearInterpolator())
            .setDuration(180).setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mLinearWeek.setVisibility(GONE);
                    mSelectLayout.setVisibility(VISIBLE);
                    mSelectLayout.init(year);
                }
            });
    mViewPager.animate().scaleX(0).scaleY(0).setDuration(180).setInterpolator(new LinearInterpolator())
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mViewPager.setVisibility(GONE);
                }
            });
}

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

/**
 * Update map with the new coordinates for the driver
 * @param intent containing driver coordinates
 *//*w  w w  .j ava2  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);
            }
        }
    });
}