Example usage for android.animation ObjectAnimator setInterpolator

List of usage examples for android.animation ObjectAnimator setInterpolator

Introduction

In this page you can find the example usage for android.animation ObjectAnimator setInterpolator.

Prototype

@Override
public void setInterpolator(TimeInterpolator value) 

Source Link

Document

The time interpolator used in calculating the elapsed fraction of this animation.

Usage

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   w ww  .  j  a v a  2  s .c  om*/
            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.josecalles.porridge.widget.BottomSheet.java

@Override
public void onStopNestedScroll(View child) {
    final int dragDisplacement = dragView.getTop() - dragViewTop;
    if (dragDisplacement == 0)
        return;/*from   ww w .j  a  v  a 2 s . c o m*/

    // check if we should perform a dismiss or settle back into place
    final boolean dismiss = lastNestedScrollWasDownward && dragDisplacement >= dragDismissDistance;
    // animate either back into place or to bottom
    ObjectAnimator settleAnim = ObjectAnimator.ofInt(dragViewOffsetHelper, ViewOffsetHelper.OFFSET_Y,
            dragView.getTop(), dismiss ? dragViewBottom : dragViewTop);
    settleAnim.setDuration(200L);
    settleAnim.setInterpolator(
            AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.fast_out_slow_in));
    if (dismiss) {
        settleAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                dispatchDismissCallback();
            }
        });
    }
    settleAnim.start();
}

From source file:com.ffmpegtest.VideoActivity.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void swapScaleType() {
    FFmpegSurfaceView view = (FFmpegSurfaceView) mVideoView;
    FFmpegSurfaceView.ScaleType scaleType = view.getScaleType();
    ScaleType newScaleType;/*www . jav a2s.  c om*/
    if (ScaleType.CENTER_INSIDE.equals(scaleType)) {
        newScaleType = ScaleType.CENTER_CROP;
    } else if (ScaleType.CENTER_CROP.equals(scaleType)) {
        newScaleType = ScaleType.FIT_XY;
    } else {
        newScaleType = ScaleType.CENTER_INSIDE;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setScaleType(newScaleType, true);
        RectF dst = new RectF();
        view.calculateRect(dst, newScaleType);
        ObjectAnimator anim = ObjectAnimator.ofObject(view, "destinationRect", new RectEvaluator(), dst);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.start();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        view.setScaleType(newScaleType, true);
        RectF dst = new RectF();
        view.calculateRect(dst, newScaleType);
        ObjectAnimator anim = ObjectAnimator.ofObject(view, new PropertyDestinationRect(), new RectEvaluator(),
                dst);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.start();
    } else {
        view.setScaleType(newScaleType, false);
    }
}

From source file:com.jaredrummler.materialspinner.MaterialSpinner.java

private void animateArrow(boolean shouldRotateUp) {
    int start = shouldRotateUp ? 0 : 10000;
    int end = shouldRotateUp ? 10000 : 0;
    ObjectAnimator animator = ObjectAnimator.ofInt(arrowDrawable, "level", start, end);
    animator.setInterpolator(new LinearOutSlowInInterpolator());
    animator.start();//  w  w  w . j av a 2 s.co  m
}

From source file:com.google.android.apps.muzei.TutorialFragment.java

@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
    view.findViewById(R.id.tutorial_icon_affordance).setOnClickListener(new View.OnClickListener() {
        @Override//  w w  w  . j  a va 2 s  .com
        public void onClick(View view) {
            FirebaseAnalytics.getInstance(getContext()).logEvent(FirebaseAnalytics.Event.TUTORIAL_COMPLETE,
                    null);
            final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
            sp.edit().putBoolean(PREF_SEEN_TUTORIAL, true).apply();
        }
    });

    if (savedInstanceState == null) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        View mainTextView = view.findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);
        View subTextView = view.findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);
        final View affordanceView = view.findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);
        View iconTextView = view.findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);
        mAnimator = new AnimatorSet();
        mAnimator.setStartDelay(500);
        mAnimator.setDuration(250);
        mAnimator.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        mAnimator.start();
        mAnimator = new AnimatorSet();
        mAnimator.setStartDelay(2000);
        // Bug in older versions where set.setInterpolator didn't work
        Interpolator interpolator = new OvershootInterpolator();
        ObjectAnimator a1 = ObjectAnimator.ofFloat(affordanceView, View.TRANSLATION_Y, 0);
        ObjectAnimator a2 = ObjectAnimator.ofFloat(iconTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a3 = ObjectAnimator.ofFloat(mainTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a4 = ObjectAnimator.ofFloat(subTextView, View.TRANSLATION_Y, 0);
        a1.setInterpolator(interpolator);
        a2.setInterpolator(interpolator);
        a3.setInterpolator(interpolator);
        a4.setInterpolator(interpolator);
        mAnimator.setDuration(500).playTogether(ObjectAnimator.ofFloat(affordanceView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(iconTextView, View.ALPHA, 1f), a1, a2, a3, a4);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (isAdded()) {
                        ImageView emanateView = (ImageView) view.findViewById(R.id.tutorial_icon_emanate);
                        AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                                .getDrawable(R.drawable.avd_tutorial_icon_emanate, getContext().getTheme());
                        emanateView.setImageDrawable(avd);
                        avd.start();
                    }
                }
            });
        }
        mAnimator.start();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ImageView emanateView = (ImageView) view.findViewById(R.id.tutorial_icon_emanate);
        AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                .getDrawable(R.drawable.avd_tutorial_icon_emanate, getContext().getTheme());
        emanateView.setImageDrawable(avd);
        avd.start();
    }
}

From source file:io.plaidapp.ui.FilterAdapter.java

@Override
public FilterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    final FilterViewHolder holder = new FilterViewHolder(
            LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.filter_item, viewGroup, false));
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override//  w w w .  ja  va  2  s. co m
        public void onClick(View v) {
            final int position = holder.getAdapterPosition();
            if (position == RecyclerView.NO_POSITION)
                return;
            final Source filter = filters.get(position);
            if (isAuthorisedDribbbleSource(filter)
                    && !DribbblePrefs.get(holder.itemView.getContext()).isLoggedIn()) {
                authoriser.requestDribbbleAuthorisation(holder.filterIcon, filter);
            } else {
                holder.itemView.setHasTransientState(true);
                ObjectAnimator fade = ObjectAnimator.ofInt(holder.filterIcon, ViewUtils.IMAGE_ALPHA,
                        filter.active ? FILTER_ICON_DISABLED_ALPHA : FILTER_ICON_ENABLED_ALPHA);
                fade.setDuration(300);
                fade.setInterpolator(AnimationUtils.loadInterpolator(holder.itemView.getContext(),
                        android.R.interpolator.fast_out_slow_in));
                fade.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.itemView.setHasTransientState(false);
                    }
                });
                fade.start();
                filter.active = !filter.active;
                holder.filterName.setEnabled(filter.active);
                notifyItemChanged(position);
                SourceManager.updateSource(filter, holder.itemView.getContext());
                dispatchFiltersChanged(filter);
            }
        }
    });
    return holder;
}

From source file:com.viewpagerindicator.TabMovablePageIndicator.java

private void animateScrollWithIndicator(TabView tabView) {
    int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;

    AnimatorSet as = new AnimatorSet();
    as.setDuration(300);/*w  ww.j av a 2 s .co  m*/

    ArrayList<Animator> animations = new ArrayList<Animator>();

    // scroll
    ObjectAnimator animScrollX = ObjectAnimator.ofInt(TabMovablePageIndicator.this, "scrollX", scrollPos);
    animScrollX.setInterpolator(new AccelerateDecelerateInterpolator());
    animations.add(animScrollX);

    // indicator position
    int left = tabView.getLeft();
    //      int width = tabView.getWidth();
    int textWidth = tabView.wordWidth;
    //      int x = left + (width - textWidth) / 2 - mExtendWidth * 2;
    //      x = x < 0 ? 0 : x;

    ObjectAnimator translateXAnim = ObjectAnimator.ofFloat(mIndicator, "translationX", left);
    translateXAnim.setInterpolator(new OvershootInterpolator(0.8f));
    animations.add(translateXAnim);

    // indicator width
    ValueAnimator animWidth = ValueAnimator.ofInt(mIndicator.getLayoutParams().width,
            textWidth + mExtendWidth * 2);
    animWidth.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mIndicator.getLayoutParams();
            lp.width = (Integer) animation.getAnimatedValue();

            mIndicator.setLayoutParams(lp);
            requestLayout();
        }
    });
    animations.add(animWidth);

    as.playTogether(animations);
    as.start();
}

From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

/**
 * Create and start an animator that animates the given view's translationX
 * from its current value to the value given by animateTo.
 *//*w w  w.  j a v  a2s .c o  m*/
private ObjectAnimator getSwipeTranslationXAnimator(final ConversationListItemView itemView,
        final float animateTo, final long duration, final TimeInterpolator interpolator) {
    final ObjectAnimator animator = ObjectAnimator.ofFloat(itemView, "swipeTranslationX", animateTo);
    animator.setDuration(duration);
    animator.setInterpolator(interpolator);
    return animator;
}

From source file:com.bar.foldinglayout.sample.FoldingLayoutActivity.java

/**
 * Animates the folding view inwards (to a completely folded state) from its
 * current state and then back out to its original state.
 *//*from   ww w  .j  a v a2s.c o m*/
public void animateFold() {
    float foldFactor = mFoldLayout.getFoldFactor();

    ObjectAnimator animator = ObjectAnimator.ofFloat(mFoldLayout, "foldFactor", foldFactor, 1);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(1);
    animator.setDuration(FOLD_ANIMATION_DURATION);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.start();
}

From source file:com.waz.zclient.views.menus.ConfirmationMenu.java

public void animateToShow(boolean show) {
    if (show) {//from   w  ww . j a v  a 2s .com
        confirmed = false;
        cancelled = false;

        // Init views and post animations to get measured height of message container
        backgroundView.setAlpha(0);
        messageContainerView.setVisibility(INVISIBLE);
        setVisibility(VISIBLE);

        messageContainerView.post(new Runnable() {
            @Override
            public void run() {

                ObjectAnimator showBackgroundAnimator = ObjectAnimator.ofFloat(backgroundView, View.ALPHA, 0,
                        1);
                showBackgroundAnimator.setInterpolator(new Quart.EaseOut());
                showBackgroundAnimator
                        .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short));

                ObjectAnimator showMessageAnimator = ObjectAnimator.ofFloat(messageContainerView,
                        View.TRANSLATION_Y, messageContainerView.getMeasuredHeight(), 0);
                showMessageAnimator.setInterpolator(new Expo.EaseOut());
                showMessageAnimator
                        .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium));
                showMessageAnimator.setStartDelay(getResources()
                        .getInteger(R.integer.framework_animation__confirmation_menu__show_message_delay));
                showMessageAnimator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        messageContainerView.setVisibility(VISIBLE);
                    }
                });

                AnimatorSet showSet = new AnimatorSet();
                showSet.playTogether(showBackgroundAnimator, showMessageAnimator);
                showSet.setDuration(getResources()
                        .getInteger(R.integer.background_accent_color_transition_animation_duration));
                showSet.start();
            }
        });
    } else {
        ObjectAnimator hideBackgroundAnimator = ObjectAnimator.ofFloat(backgroundView, View.ALPHA, 1, 0);
        hideBackgroundAnimator.setInterpolator(new Quart.EaseOut());
        hideBackgroundAnimator
                .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short));
        hideBackgroundAnimator.setStartDelay(getResources()
                .getInteger(R.integer.framework_animation__confirmation_menu__hide_background_delay));
        hideBackgroundAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                setVisibility(GONE);
                boolean checkboxIsSelected = checkBoxView.getVisibility() == VISIBLE
                        && checkBoxView.isSelected();
                if (callback != null) {
                    callback.onHideAnimationEnd(confirmed, cancelled, checkboxIsSelected);
                }
            }
        });

        ObjectAnimator hideMessageAnimator = ObjectAnimator.ofFloat(messageContainerView, View.TRANSLATION_Y, 0,
                messageContainerView.getMeasuredHeight());
        hideMessageAnimator.setInterpolator(new Expo.EaseIn());
        hideMessageAnimator
                .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium));

        AnimatorSet hideSet = new AnimatorSet();
        hideSet.playTogether(hideMessageAnimator, hideBackgroundAnimator);
        hideSet.start();
    }
}