Example usage for android.animation Animator setDuration

List of usage examples for android.animation Animator setDuration

Introduction

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

Prototype

public abstract Animator setDuration(long duration);

Source Link

Document

Sets the duration of the animation.

Usage

From source file:com.google.samples.apps.iosched.util.LPreviewUtilsBase.java

public void setOrAnimatePlusCheckIcon(final ImageView imageView, boolean isCheck, boolean allowAnimate) {
    final int imageResId = isCheck ? R.drawable.add_schedule_button_icon_checked
            : R.drawable.add_schedule_button_icon_unchecked;

    if (imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();/*  ww  w  . j  a v a2  s  . co m*/
            imageView.setAlpha(1f);
        }
    }

    if (allowAnimate && isCheck) {
        int duration = mActivity.getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        outAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:fr.paug.droidcon.util.LPreviewUtilsBase.java

public void setOrAnimatePlusCheckIcon(final ImageView imageView, boolean isCheck, boolean allowAnimate,
        int resIdChecked) {

    final int imageResId = isCheck ? resIdChecked : R.drawable.add_schedule_button_icon_unchecked;

    if (imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();//  w  w w.ja  va2 s.  co m
            imageView.setAlpha(1f);
        }
    }

    if (allowAnimate && isCheck) {
        int duration = mActivity.getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        outAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.unipiazza.material2stepslogin.fragments.SecondStepFragment.java

private void createReveal(final View myView) {

    // get the center for the clipping circle
    int cx = (myView.getWidth()) / 2;
    int cy = (myView.getHeight()) / 2;

    // get the final radius for the clipping circle
    int finalRadius = Math.max(myView.getWidth(), myView.getHeight());

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Animator animator = android.view.ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0,
                finalRadius);//from ww  w.  j a  v  a  2s .com
        animator.setDuration(800);
        animator.start();
    } else {
        SupportAnimator animator = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.setDuration(800);
        animator.start();
    }
}

From source file:com.sysdata.widget.accordion.ExpandedViewHolder.java

private Animator createExpandingAnimator(ArrowItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(newView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 0, 255));
    backgroundAnimator.setDuration(duration);

    final AnimatorSet animatorSet;
    if (arrow != null) {
        final View oldArrow = oldHolder.arrow;
        final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
        final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
        ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
        ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
        final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;

        arrow.setTranslationY(arrowTranslationY);
        arrow.setVisibility(View.VISIBLE);

        final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f)
                .setDuration(duration);//from w w w  . j  a  v a2  s .c  o  m
        arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

        animatorSet = new AnimatorSet();
        animatorSet.playTogether(backgroundAnimator, boundsAnimator, arrowAnimation);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                AnimatorUtils.startDrawableAnimation(arrow);
            }
        });
    } else {
        animatorSet = new AnimatorSet();
        animatorSet.playTogether(backgroundAnimator, boundsAnimator);
    }

    return animatorSet;
}

From source file:ooo.oxo.apps.materialize.SearchPanelController.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Animator makeSearchPanelAnimator(boolean reverse) {
    int width = container.getWidth();

    int centerX = container.getRight() + container.getPaddingRight()
            - resources.getDimensionPixelOffset(R.dimen.reveal_right) / 4 * 3;

    int centerY = container.getHeight() / 2;

    Animator animator = ViewAnimationUtils.createCircularReveal(container, centerX, centerY,
            reverse ? width : 0, reverse ? 0 : width);

    animator.setInterpolator(new FastOutSlowInInterpolator());

    animator.setDuration(resources.getInteger(android.R.integer.config_mediumAnimTime));

    return animator;
}

From source file:com.truizlop.fabreveallayout.FABRevealLayout.java

private void setupAnimationParams(Animator animator) {
    animator.setInterpolator(INTERPOLATOR);
    animator.setDuration(ANIMATION_DURATION);
}

From source file:com.sysdata.widget.accordion.ExpandedViewHolder.java

private Animator createCollapsingAnimator(ArrowItemViewHolder newHolder, long duration) {
    if (arrow != null) {
        arrow.setVisibility(View.INVISIBLE);
    }/*from   w w w. jav  a 2s  .  c  om*/

    final View oldView = itemView;
    final View newView = newHolder.itemView;

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(oldView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 255, 0));
    backgroundAnimator.setDuration(duration);

    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(oldView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(backgroundAnimator, boundsAnimator);
    return animatorSet;
}

From source file:com.chrynan.guitartuner.PitchFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Animator unreveal(final float x, final float y) {
    Animator anim = ViewAnimationUtils.createCircularReveal(getView(), (int) x, (int) y,
            (float) Math.hypot(viewRoot.getWidth(), viewRoot.getHeight()), 0);
    anim.setInterpolator(new AccelerateInterpolator(0.5f));
    anim.setDuration(500);
    return anim;//ww  w .  ja va  2s  .co m
}

From source file:com.example.toolbardemo.Fragment.CircularRevealFragment.java

/**
 * {@inheritDoc}//from w  w  w.  j  ava2 s .c o  m
 * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);
    tv1 = (TextView) getActivity().findViewById(R.id.textView1);
    tv2 = (TextView) getActivity().findViewById(R.id.textView2);
    tv3 = (TextView) getActivity().findViewById(R.id.textView3);
    tv4 = (TextView) getActivity().findViewById(R.id.textView4);
    tv1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Animator animator = ViewAnimationUtils.createCircularReveal(tv1, tv1.getWidth() / 2,
                    tv1.getHeight() / 2, tv1.getWidth(), 0);
            animator.setInterpolator(new AccelerateDecelerateInterpolator());
            animator.setDuration(1000);
            animator.start();
        }
    });
    tv2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Animator animator = ViewAnimationUtils.createCircularReveal(tv2, 0, 0, 0,
                    (float) Math.hypot(tv2.getWidth(), tv2.getHeight()));
            animator.setInterpolator(new AccelerateInterpolator());
            animator.setDuration(1000);
            animator.start();
        }
    });
    tv3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Animator animator = ViewAnimationUtils.createCircularReveal(tv3, tv3.getWidth() / 2,
                    tv3.getHeight() / 2, 0, tv3.getWidth());
            animator.setInterpolator(new AccelerateInterpolator());
            animator.setDuration(1000);
            animator.start();
        }
    });
    tv4.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Animator animator = ViewAnimationUtils.createCircularReveal(tv4, 0, 0,
                    (float) Math.hypot(tv4.getWidth(), tv4.getHeight()), 0);
            animator.setInterpolator(new AccelerateInterpolator());
            animator.setDuration(1000);
            animator.start();
        }
    });
}

From source file:com.rks.musicx.ui.adapters.SongListAdapter.java

@Override
public void onBindViewHolder(SongListAdapter.SongViewHolder holder, int position) {
    Song song = getItem(position);/*from  w w  w.ja  va2s . com*/
    if (layout == R.layout.song_list) {
        holder.SongTitle.setText(song.getTitle());
        holder.SongArtist.setText(song.getArtist());
        ArtworkUtils.ArtworkLoader(getContext(), 300, 600, song.getAlbum(), song.getAlbumId(), new palette() {
            @Override
            public void palettework(Palette palette) {

            }
        }, holder.SongArtwork);
        holder.menu.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_menu));
        Drawable drawable = holder.menu.getDrawable();
        int accentColor = Config.accentColor(getContext(), Helper.getATEKey(getContext()));
        if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) {
            drawable.setTint(Color.WHITE);
            holder.SongTitle.setTextColor(Color.WHITE);
            holder.SongArtist.setTextColor(ContextCompat.getColor(getContext(), R.color.darkthemeTextColor));
            holder.itemView.setBackgroundColor(storeChecked.get(position)
                    ? ContextCompat.getColor(getContext(), R.color.translucent_white_8p)
                    : Color.TRANSPARENT);
        } else {
            drawable.setTint(ContextCompat.getColor(getContext(), R.color.MaterialGrey));
            holder.SongTitle.setTextColor(Color.BLACK);
            holder.SongArtist.setTextColor(Color.DKGRAY);
            holder.itemView
                    .setBackgroundColor(storeChecked.get(position) ? Helper.getColorWithAplha(accentColor, 0.7f)
                            : Color.TRANSPARENT);
        }
    }
    if (layout == R.layout.detail_list) {
        holder.SongTitle.setText(song.getTitle());
        holder.SongArtist.setText(song.getArtist());
        holder.number.setText(position + 1 + ".");
        holder.menu.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_menu));
        Drawable drawable = holder.menu.getDrawable();
        if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) {
            drawable.setTint(Color.WHITE);
            holder.SongTitle.setTextColor(Color.WHITE);
            holder.number.setTextColor(Color.WHITE);
            holder.SongArtist.setTextColor(ContextCompat.getColor(getContext(), R.color.darkthemeTextColor));
        } else {
            drawable.setTint(ContextCompat.getColor(getContext(), R.color.MaterialGrey));
            holder.SongTitle.setTextColor(Color.BLACK);
            holder.number.setTextColor(Color.BLACK);
            holder.SongArtist.setTextColor(Color.DKGRAY);
        }
    }
    if (layout == R.layout.item_grid_view || layout == R.layout.recent_list) {
        int pos = holder.getAdapterPosition();
        if (lastpos < pos) {
            for (Animator animator : getAnimator(holder.songView)) {
                animator.setDuration(duration);
                animator.setInterpolator(interpolator);
                animator.start();
            }
        }
        holder.SongTitle.setText(song.getTitle());
        holder.SongArtist.setText(song.getArtist());
        ArtworkUtils.ArtworkLoader(getContext(), 300, 600, song.getAlbum(), song.getAlbumId(), new palette() {
            @Override
            public void palettework(Palette palette) {
                final int[] colors = Helper.getAvailableColor(getContext(), palette);
                holder.songView.setBackgroundColor(colors[0]);
                holder.SongTitle.setTextColor(Helper.getTitleTextColor(colors[0]));
                holder.SongArtist.setTextColor(Helper.getTitleTextColor(colors[0]));
                Helper.animateViews(getContext(), holder.itemView, colors[0]);
            }
        }, holder.songGridArtwork);
        holder.menu.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_menu));
        holder.menu.setVisibility(View.VISIBLE);
        Drawable drawable = holder.menu.getDrawable();
        if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) {
            drawable.setTint(Color.WHITE);
        }
    }
}