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.adityarathi.muo.ui.activities.NowPlayingActivity.java

/**
 * Smoothly scrolls the seekbar to the indicated position.
 *//*  www  .  j  a  va 2s . co m*/
private void smoothScrollSeekbar(int progress) {
    ObjectAnimator animation = ObjectAnimator.ofInt(mSeekbar, "progress", progress);
    animation.setDuration(200);
    animation.setInterpolator(new DecelerateInterpolator());
    animation.start();

}

From source file:io.plaidapp.core.ui.FeedAdapter.java

private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) {
    final Images.ImageSize imageSize = shot.getImages().bestSize();
    GlideApp.with(host).load(shot.getImages().best()).listener(new RequestListener<Drawable>() {

        @Override//from   w ww .  java 2  s  .  com
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target,
                DataSource dataSource, boolean isFirstResource) {
            if (!shot.getHasFadedIn()) {
                holder.image.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                final ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION,
                        0f, 1f);
                saturation.addUpdateListener(valueAnimator -> {
                    // just animating the color matrix does not invalidate the
                    // drawable so need this update listener.  Also have to create a
                    // new CMCF as the matrix is immutable :(
                    holder.image.setColorFilter(new ColorMatrixColorFilter(cm));
                });
                saturation.setDuration(2000L);
                saturation.setInterpolator(getFastOutSlowInInterpolator(host));
                saturation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.image.clearColorFilter();
                        holder.image.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.setHasFadedIn(true);
            }
            return false;
        }

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target,
                boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length])
            .diskCacheStrategy(DiskCacheStrategy.DATA).fitCenter()
            .transition(DrawableTransitionOptions.withCrossFade())
            .override(imageSize.getWidth(), imageSize.getHeight())
            .into(new DribbbleTarget(holder.image, false));
    // need both placeholder & background to prevent seeing through shot as it fades in
    holder.image.setBackground(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]);
    holder.image.setDrawBadge(shot.getAnimated());
    // need a unique transition name per shot, let's use it's url
    holder.image.setTransitionName(shot.getHtmlUrl());
    shotPreloadSizeProvider.setView(holder.image);
}

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

private void updateUiMode() {
    // TODO: this should really just use fragment transactions and transitions

    int newUiMode = UI_MODE_INTRO;
    if (mWallpaperActive) {
        newUiMode = UI_MODE_TUTORIAL;//from w  ww  .j a v  a  2 s .c  o m
        if (mSeenTutorial) {
            newUiMode = UI_MODE_ART_DETAIL;
        }
    }

    if (mUiMode == newUiMode) {
        return;
    }

    // Crossfade between main containers
    final View oldContainerView = getMainContainerForUiMode(mUiMode);
    final View newContainerView = getMainContainerForUiMode(newUiMode);

    if (oldContainerView != null) {
        oldContainerView.animate().alpha(0).setDuration(1000).withEndAction(new Runnable() {
            @Override
            public void run() {
                oldContainerView.setVisibility(View.GONE);
            }
        });
    }

    if (newContainerView != null) {
        if (newContainerView.getAlpha() == 1) {
            newContainerView.setAlpha(0);
        }
        newContainerView.setVisibility(View.VISIBLE);
        newContainerView.animate().alpha(1).setDuration(1000).withEndAction(null);
    }

    // Special work
    if (newUiMode == UI_MODE_INTRO) {
        final View activateButton = findViewById(R.id.activate_muzei_button);
        activateButton.setAlpha(0);
        final AnimatedMuzeiLogoFragment logoFragment = (AnimatedMuzeiLogoFragment) getFragmentManager()
                .findFragmentById(R.id.animated_logo_fragment);
        logoFragment.reset();
        logoFragment.setOnFillStartedCallback(new Runnable() {
            @Override
            public void run() {
                activateButton.animate().alpha(1f).setDuration(500);
            }
        });
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                logoFragment.start();
            }
        }, 1000);
    }

    if (mUiMode == UI_MODE_INTRO || newUiMode == UI_MODE_INTRO) {
        FragmentManager fm = getSupportFragmentManager();
        Fragment demoFragment = fm.findFragmentById(R.id.demo_view_container);
        if (newUiMode == UI_MODE_INTRO && demoFragment == null) {
            fm.beginTransaction()
                    .add(R.id.demo_view_container, MuzeiRendererFragment.createInstance(true, true)).commit();
        } else if (newUiMode != UI_MODE_INTRO && demoFragment != null) {
            fm.beginTransaction().remove(demoFragment).commit();
        }
    }

    if (newUiMode == UI_MODE_TUTORIAL) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        View mainTextView = findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);

        View subTextView = findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);

        final View affordanceView = findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);

        View iconTextView = findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);

        AnimatorSet set = new AnimatorSet();
        set.setStartDelay(500);
        set.setDuration(250);
        set.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        set.start();

        set = new AnimatorSet();
        set.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);
        set.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) {
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    ImageView emanateView = (ImageView) findViewById(R.id.tutorial_icon_emanate);
                    AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                            .getDrawable(R.drawable.avd_tutorial_icon_emanate, getTheme());
                    emanateView.setImageDrawable(avd);
                    avd.start();
                }
            });
        }
        set.start();
    }

    mPanScaleProxyView.setVisibility(newUiMode == UI_MODE_ART_DETAIL ? View.VISIBLE : View.GONE);

    mUiMode = newUiMode;

    maybeUpdateArtDetailOpenedClosed();
}

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void animateIdleStateButtonAfterClick() {
    int textColorChangeDuration = 10;
    ObjectAnimator colorAnim = ObjectAnimator.ofInt(this, "textColor", getNormalColor(this.getTextColors()),
            mIdleStateTextColorAfterClick);
    colorAnim.setDuration(textColorChangeDuration);
    colorAnim.setEvaluator(new ArgbEvaluator());
    colorAnim.start();//from w ww . ja  va2s  .  co  m

    ObjectAnimator colorAnim1 = ObjectAnimator.ofInt(this, "textColor", mIdleStateTextColorAfterClick,
            getNormalColor(this.getTextColors()));
    colorAnim1.setDuration(0);
    colorAnim1.setStartDelay(IDLE_STATE_ANIMATION_DURATION_AFTER_CLICK - textColorChangeDuration);
    colorAnim1.setEvaluator(new ArgbEvaluator());
    colorAnim1.setInterpolator(new BounceInterpolator());
    colorAnim1.start();

    ObjectAnimator bgAnim = ObjectAnimator.ofInt(this, "backgroundColor", getNormalColor(mIdleColorState),
            mIdleStateBackgroundColorAfterClick);
    bgAnim.setDuration(0);
    bgAnim.setEvaluator(new ArgbEvaluator());
    bgAnim.start();

    int textSizeAnimationDuration = 150;
    ValueAnimator animator = ValueAnimator.ofFloat(textSize, textSize - textSize / 4);
    animator.setDuration(textSizeAnimationDuration);
    animator.setRepeatCount(1);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            setTextSize(animatedValue);
        }
    });

    animator.start();
}

From source file:com.waz.zclient.pages.main.participants.ParticipantFragment.java

@Override
public void onShowPickUser(IPickUserController.Destination destination, View anchorView) {
    if (LayoutSpec.isPhone(getActivity())) {
        return;/*from  ww  w.  j a  v a2s. co  m*/
    }
    if (!getCurrentPickerDestination().equals(destination)) {
        onHidePickUser(getCurrentPickerDestination(), true);
        return;
    }
    FragmentManager fragmentManager = getChildFragmentManager();

    int pickUserAnimation = LayoutSpec.isTablet(getActivity()) ? R.anim.fade_in
            : R.anim.slide_in_from_bottom_pick_user;

    if (!groupConversation && otherUser != null) {
        getControllerFactory().getPickUserController().addUser(otherUser);
    }
    fragmentManager.beginTransaction().setCustomAnimations(pickUserAnimation, R.anim.fade_out)
            .add(R.id.fl__add_to_conversation__pickuser__container,
                    PickUserFragment.newInstance(true, groupConversation), PickUserFragment.TAG)
            .addToBackStack(PickUserFragment.TAG).commit();

    if (LayoutSpec.isPhone(getActivity())) {
        getControllerFactory().getNavigationController().setRightPage(Page.PICK_USER_ADD_TO_CONVERSATION, TAG);
    }

    final ObjectAnimator hideParticipantsAnimator = ObjectAnimator.ofFloat(participantsContainerView,
            View.ALPHA, 1f, 0f);
    hideParticipantsAnimator.setInterpolator(new Quart.EaseOut());
    hideParticipantsAnimator
            .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium));
    hideParticipantsAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            participantsContainerView.setVisibility(View.GONE);
        }
    });
    hideParticipantsAnimator.start();
}

From source file:us.phyxsi.gameshelf.ui.FeedAdapter.java

private void bindBoardgameHolder(final Boardgame game, final BoardgameHolder holder) {
    final int[] imageSize = { 400, 400 };
    Glide.with(host).load("http:" + game.image).listener(new RequestListener<String, GlideDrawable>() {

        @Override//from ww w  .j a v  a2 s .c o  m
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                boolean isFromMemoryCache, boolean isFirstResource) {
            if (!game.hasFadedIn) {
                holder.image.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f,
                        1f);
                saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        // just animating the color matrix does not invalidate the
                        // drawable so need this update listener.  Also have to create a
                        // new CMCF as the matrix is immutable :(
                        if (holder.image.getDrawable() != null) {
                            holder.image.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
                        }
                    }
                });
                saturation.setDuration(1000);
                saturation.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));
                saturation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.image.setHasTransientState(false);
                    }
                });
                saturation.start();
                game.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[holder.getAdapterPosition() % shotLoadingPlaceholders.length])
            .diskCacheStrategy(DiskCacheStrategy.SOURCE).centerCrop().override(imageSize[0], imageSize[1])
            .into(new BoardgameTarget(holder.image, false));

}

From source file:org.protocoderrunner.apprunner.api.PUI.java

@ProtocoderScript
@APIMethod(description = "Makes the view blink", example = "")
@APIParam(params = { "View", "num" })
public void blink(View v, int num) {
    ObjectAnimator anim = ObjectAnimator.ofFloat(v, "alpha", 1f, 0f, 1f);
    anim.setDuration(AppSettings.animGeneralSpeed);
    anim.setInterpolator(new CycleInterpolator(1));
    anim.setRepeatCount(num);//from   w ww.  j  a va 2  s .  c o  m
    anim.start();
}

From source file:com.waz.zclient.pages.main.participants.dialog.ParticipantsDialogFragment.java

/**
 * @return true if the animation was performed,
 *         false otherwise//  w w  w. j a v a 2s. c  om
 */
private boolean animateBetweenMainAndDetail(boolean showGroup) {
    float startDetail;
    float endDetail;
    float startMain;
    float endMain;
    Interpolator interpolator;
    if (showGroup) {
        startDetail = 0;
        endDetail = dialogFrameLayout.getMeasuredWidth();
        startMain = -dialogFrameLayout.getMeasuredHeight();
        endMain = 0;
        interpolator = new Quart.EaseOut();
    } else {
        startDetail = dialogFrameLayout.getMeasuredWidth();
        endDetail = 0;
        startMain = 0;
        endMain = -dialogFrameLayout.getMeasuredHeight();
        interpolator = new Quart.EaseOut();
    }

    if (MathUtils.floatEqual(mainParticipantsContainer.getTranslationX(), endMain)
            && MathUtils.floatEqual(detailParticipantContainer.getTranslationX(), endDetail)) {
        return false;
    }

    ObjectAnimator slideInDetailParticipantAnimation = ObjectAnimator.ofFloat(detailParticipantContainer,
            View.TRANSLATION_X, startDetail, endDetail);
    slideInDetailParticipantAnimation
            .setDuration(getResources().getInteger(R.integer.framework_animation_duration_long));
    slideInDetailParticipantAnimation.setInterpolator(interpolator);

    ObjectAnimator slideOutMainAnimation = ObjectAnimator.ofFloat(mainParticipantsContainer, View.TRANSLATION_X,
            startMain, endMain);
    slideOutMainAnimation.setDuration(getResources().getInteger(R.integer.framework_animation_duration_long));
    slideOutMainAnimation.setInterpolator(interpolator);

    AnimatorSet participantTransition = new AnimatorSet();
    participantTransition.playTogether(slideOutMainAnimation, slideInDetailParticipantAnimation);
    participantTransition.start();
    return true;
}

From source file:com.yekertech.tvbarsetting.dialog.DialogFragment.java

private void performEntryTransition() {
    final View dialogView = getView();
    final View contentView = (View) dialogView.getTag(R.id.content_fragment);
    final View actionContainerView = dialogView.findViewById(R.id.action_fragment);

    mIntroAnimationInProgress = true;/*from  ww w . j av  a 2s. c  o m*/

    // Fade out the old activity.
    getActivity().overridePendingTransition(0, R.anim.lb_dialog_fade_out);

    int bgColor = contentView.getContext().getResources().getColor(R.color.lb_dialog_activity_background);
    final ColorDrawable bgDrawable = new ColorDrawable();
    bgDrawable.setColor(bgColor);
    bgDrawable.setAlpha(0);
    dialogView.setBackground(bgDrawable);
    dialogView.setVisibility(View.INVISIBLE);

    runDelayedAnim(new Runnable() {
        @Override
        public void run() {
            if (!isAdded()) {
                // We have been detached before this could run,
                // so just bail
                return;
            }

            dialogView.setVisibility(View.VISIBLE);

            // Fade in the activity background protection
            ObjectAnimator oa = ObjectAnimator.ofInt(bgDrawable, "alpha", 255);
            oa.setDuration(ANIMATE_IN_DURATION);
            oa.setStartDelay(SECONDARY_ANIMATE_DELAY);
            oa.setInterpolator(new DecelerateInterpolator(1.0f));
            oa.start();

            boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL;
            int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE;
            int endDist = isRtl ? -actionContainerView.getMeasuredWidth()
                    : actionContainerView.getMeasuredWidth();

            // Fade in and slide in the ContentFragment
            // TextViews from the start.
            prepareAndAnimateView((View) contentView.getTag(R.id.title), startDist, false);
            prepareAndAnimateView((View) contentView.getTag(R.id.breadcrumb), startDist, false);
            prepareAndAnimateView((View) contentView.getTag(R.id.description), startDist, false);

            // Fade in and slide in the ActionFragment from the
            // end.
            prepareAndAnimateView(actionContainerView, endDist, false);
            prepareAndAnimateView((View) contentView.getTag(R.id.icon), startDist, true);

            // Fade in the selector.
            if (mSelectorAnimator != null) {
                mSelectorAnimator.fadeIn();
            }
        }
    });
}

From source file:com.android.tv.settings.dialog.DialogFragment.java

private void performEntryTransition() {
    final View dialogView = getView();
    final View contentView = (View) dialogView.getTag(R.id.content_fragment);
    final View actionContainerView = dialogView.findViewById(R.id.action_fragment);

    mIntroAnimationInProgress = true;//from  w ww.  j  a va 2 s  . c  om

    // Fade out the old activity.
    getActivity().overridePendingTransition(0, R.anim.lb_dialog_fade_out);

    int bgColor = contentView.getContext().getResources().getColor(R.color.lb_dialog_activity_background);
    final ColorDrawable bgDrawable = new ColorDrawable();
    bgDrawable.setColor(bgColor);
    bgDrawable.setAlpha(0);
    dialogView.setBackground(bgDrawable);
    dialogView.setVisibility(View.INVISIBLE);

    runDelayedAnim(new Runnable() {
        @Override
        public void run() {
            if (!isAdded()) {
                // We have been detached before this could run,
                // so just bail
                return;
            }

            dialogView.setVisibility(View.VISIBLE);

            // Fade in the activity background protection
            ObjectAnimator oa = ObjectAnimator.ofInt(bgDrawable, "alpha", 255);
            oa.setDuration(ANIMATE_IN_DURATION);
            oa.setStartDelay(SECONDARY_ANIMATE_DELAY);
            oa.setInterpolator(new DecelerateInterpolator(1.0f));
            oa.start();

            boolean isRtl = ViewCompat.getLayoutDirection(contentView) == View.LAYOUT_DIRECTION_RTL;
            int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE;
            int endDist = isRtl ? -actionContainerView.getMeasuredWidth()
                    : actionContainerView.getMeasuredWidth();

            // Fade in and slide in the ContentFragment
            // TextViews from the start.
            prepareAndAnimateView((View) contentView.getTag(R.id.title), startDist, false);
            prepareAndAnimateView((View) contentView.getTag(R.id.breadcrumb), startDist, false);
            prepareAndAnimateView((View) contentView.getTag(R.id.description), startDist, false);

            // Fade in and slide in the ActionFragment from the
            // end.
            prepareAndAnimateView(actionContainerView, endDist, false);
            prepareAndAnimateView((View) contentView.getTag(R.id.icon), startDist, true);

            // Fade in the selector.
            if (mSelectorAnimator != null) {
                mSelectorAnimator.fadeIn();
            }
        }
    });
}