Example usage for android.animation ObjectAnimator setDuration

List of usage examples for android.animation ObjectAnimator setDuration

Introduction

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

Prototype

@Override
@NonNull
public ObjectAnimator setDuration(long duration) 

Source Link

Document

Sets the length of the animation.

Usage

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;/*w w w .  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) == 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 w w .  jav a  2 s. 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) == 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();
            }
        }
    });
}

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 ava2  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 www. java  2 s.c  om*/
    anim.start();
}

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

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

From source file:com.hannesdorfmann.FeedAdapter.java

private void bindDribbbleShotView(final Shot shot, final DribbbleShotHolder holder, final int position) {
    final BadgedFourThreeImageView iv = (BadgedFourThreeImageView) holder.itemView;
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override/*from   ww  w .j av a2  s  .  c o  m*/
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                iv.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 (iv.getDrawable() != null) {
                            iv.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
                        }
                    }
                });
                saturation.setDuration(2000);
                saturation.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));
                saturation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        iv.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length])
            .diskCacheStrategy(DiskCacheStrategy.ALL).into(new DribbbleTarget(iv, false));

    iv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            iv.setTransitionName(iv.getResources().getString(R.string.transition_shot));
            iv.setBackgroundColor(ContextCompat.getColor(host, R.color.background_light));
            Intent intent = new Intent();
            intent.setClass(host, DribbbleShot.class);
            intent.putExtra(DribbbleShot.EXTRA_SHOT, shot);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(view, host.getString(R.string.transition_shot)),
                    Pair.create(view, host.getString(R.string.transition_shot_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
}

From source file:com.igniva.filemanager.utils.Futils.java

public void revealShow(final View view, boolean reveal) {

    if (reveal) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override/*  w  ww.ja va  2s. co  m*/
            public void onAnimationStart(Animator animation) {
                view.setVisibility(View.VISIBLE);
            }
        });
        animator.start();
    } else {

        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }
        });
        animator.start();

    }

}

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

private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder) {
    final int[] imageSize = shot.images.bestSize();
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override/*w w  w  . ja v a  2  s .co  m*/
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.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(2000);
                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();
                shot.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).fitCenter().override(imageSize[0], imageSize[1])
            .into(new DribbbleTarget(holder.image, false));
}

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   www . j  ava 2s .  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:io.plaidapp.ui.FeedAdapter.java

private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) {
    final int[] imageSize = shot.images.bestSize();
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override//www.  ja  v a  2 s .  c  o m
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                holder.image.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                final 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 :(
                        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.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length])
            .diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter().override(imageSize[0], imageSize[1])
            .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.showBadge(shot.animated);
    // need a unique transition name per shot, let's use it's url
    holder.image.setTransitionName(shot.html_url);
}