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.chrynan.guitartuner.PitchFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void circularReveal(final float x, final float y) {
    if (x != -1 && y != -1) {
        float finalRadius = (float) Math.hypot(viewRoot.getWidth(), viewRoot.getHeight());
        Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, (int) x, (int) y, 0, finalRadius);
        //viewRoot.setBackgroundColor(getActivity().getResources().getColor(R.color.white));
        anim.setInterpolator(new DecelerateInterpolator(2f));
        anim.setDuration(1000);
        anim.start();// w  w w . ja  v  a 2s.c o  m
    }
}

From source file:tech.salroid.filmy.fragment.FullReadFragment.java

@Nullable
@Override/*from w  w  w.  j a  v  a 2s.  co m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.read_full_layout, container, false);
    ButterKnife.bind(this, view);

    crossButton.setOnClickListener(this);

    // To run the animation as soon as the view is layout in the view hierarchy we add this
    // listener and remove it
    // as soon as it runs to prevent multiple animations if the view changes bounds
    view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            v.removeOnLayoutChangeListener(this);

            int cx = getArguments().getInt("cx");
            int cy = getArguments().getInt("cy");

            // get the hypothenuse so the radius is from one corner to the other
            int radius = (int) Math.hypot(right, bottom);

            Animator reveal;

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius);
                reveal.setInterpolator(new DecelerateInterpolator(2f));
                reveal.setDuration(1000);
                reveal.start();
            }

        }
    });

    return view;
}

From source file:com.android.clear.reminder.ItemAnimator.java

@Override
public boolean animateRemove(final ViewHolder holder) {
    endAnimation(holder);/* www.  j  a  va 2s.  c o m*/

    final float prevAlpha = holder.itemView.getAlpha();

    final Animator removeAnimator = ObjectAnimator.ofFloat(holder.itemView, View.ALPHA, 0f);
    removeAnimator.setDuration(getRemoveDuration());
    removeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            dispatchRemoveStarting(holder);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animator.removeAllListeners();
            mAnimators.remove(holder);
            holder.itemView.setAlpha(prevAlpha);
            dispatchRemoveFinished(holder);
        }
    });
    mRemoveAnimatorsList.add(removeAnimator);
    mAnimators.put(holder, removeAnimator);
    return true;
}

From source file:com.google.samples.apps.iosched.ui.SearchActivity.java

/**
 * On Lollipop+ perform a circular animation (a contracting circular mask) when hiding the
 * search panel./*  w ww  .ja  va2  s .co m*/
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void doExitAnim() {
    final View searchPanel = findViewById(R.id.search_panel);
    // Center the animation on the top right of the panel i.e. near to the search button which
    // launched this screen. The starting radius therefore is the diagonal distance from the top
    // right to the bottom left
    int revealRadius = (int) Math
            .sqrt(Math.pow(searchPanel.getWidth(), 2) + Math.pow(searchPanel.getHeight(), 2));
    // Animating the radius to 0 produces the contracting effect
    Animator shrink = ViewAnimationUtils.createCircularReveal(searchPanel, searchPanel.getRight(),
            searchPanel.getTop(), revealRadius, 0f);
    shrink.setDuration(200L);
    shrink.setInterpolator(
            AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in));
    shrink.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            searchPanel.setVisibility(View.INVISIBLE);
            ActivityCompat.finishAfterTransition(SearchActivity.this);
        }
    });
    shrink.start();

    // We also animate out the translucent background at the same time.
    findViewById(R.id.scrim).animate().alpha(0f).setDuration(200L).setInterpolator(
            AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in))
            .start();
}

From source file:tech.salroid.filmy.fragment.AllTrailerFragment.java

@Nullable
@Override//from   w  ww. j a  v a2s.  com
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    nightMode = sp.getBoolean("dark", false);

    View view = inflater.inflate(R.layout.all_trailer_layout, container, false);
    ButterKnife.bind(this, view);

    if (!nightMode)
        allThemeLogic();
    else {
        nightModeLogic();
    }

    crossButton.setOnClickListener(this);

    // To run the animation as soon as the view is layout in the view hierarchy we add this
    // listener and remove it
    // as soon as it runs to prevent multiple animations if the view changes bounds
    view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            v.removeOnLayoutChangeListener(this);

            int cx = getArguments().getInt("cx");
            int cy = getArguments().getInt("cy");

            // get the hypothenuse so the radius is from one corner to the other
            int radius = (int) Math.hypot(right, bottom);

            Animator reveal;

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius);
                reveal.setInterpolator(new DecelerateInterpolator(2f));
                reveal.setDuration(1000);
                reveal.start();
            }

        }
    });

    init(view);

    return view;
}

From source file:com.google.samples.apps.iosched.ui.SearchActivity.java

/**
 * On Lollipop+ perform a circular reveal animation (an expanding circular mask) when showing
 * the search panel.//from ww  w .ja  v  a  2 s. com
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void doEnterAnim() {
    // Fade in a background scrim as this is a floating window. We could have used a
    // translucent window background but this approach allows us to turn off window animation &
    // overlap the fade with the reveal animation  making it feel snappier.
    View scrim = findViewById(R.id.scrim);
    scrim.animate().alpha(1f).setDuration(500L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in))
            .start();

    // Next perform the circular reveal on the search panel
    final View searchPanel = findViewById(R.id.search_panel);
    if (searchPanel != null) {
        // We use a view tree observer to set this up once the view is measured & laid out
        searchPanel.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                searchPanel.getViewTreeObserver().removeOnPreDrawListener(this);
                // As the height will change once the initial suggestions are delivered by the
                // loader, we can't use the search panels height to calculate the final radius
                // so we fall back to it's parent to be safe
                int revealRadius = ((ViewGroup) searchPanel.getParent()).getHeight();
                // Center the animation on the top right of the panel i.e. near to the
                // search button which launched this screen.
                Animator show = ViewAnimationUtils.createCircularReveal(searchPanel, searchPanel.getRight(),
                        searchPanel.getTop(), 0f, revealRadius);
                show.setDuration(250L);
                show.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                        android.R.interpolator.fast_out_slow_in));
                show.start();
                return false;
            }
        });
    }
}

From source file:systems.soapbox.ombuds.client.ui.omb.SearchActivity.java

/**
 * On Lollipop+ perform a circular reveal animation (an expanding circular mask) when showing
 * the search panel.// w  ww .  ja  v a2 s  . co  m
 *
 * Support CircularReveal :
 * https://github.com/ozodrukh/CircularReveal
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void doEnterAnim() {
    // Fade in a background scrim as this is a floating window. We could have used a
    // translucent window background but this approach allows us to turn off window animation &
    // overlap the fade with the reveal animation  making it feel snappier.
    View scrim = findViewById(R.id.scrim);
    scrim.animate().alpha(1f).setDuration(500L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in))
            .start();

    // Next perform the circular reveal on the search panel
    final View searchPanel = findViewById(R.id.search_panel);
    if (searchPanel != null) {
        // We use a view tree observer to set this up once the view is measured & laid out
        searchPanel.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                searchPanel.getViewTreeObserver().removeOnPreDrawListener(this);
                // As the height will change once the initial suggestions are delivered by the
                // loader, we can't use the search panels height to calculate the final radius
                // so we fall back to it's parent to be safe
                int revealRadius = ((ViewGroup) searchPanel.getParent()).getHeight();
                // Center the animation on the top right of the panel i.e. near to the
                // search button which launched this screen.
                Animator show = ViewAnimationUtils.createCircularReveal(searchPanel, searchPanel.getRight(),
                        searchPanel.getTop(), 0f, revealRadius);
                show.setDuration(350L);
                show.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                        android.R.interpolator.fast_out_slow_in));
                show.start();
                return false;
            }
        });
    }
}

From source file:com.fairphone.fplauncher3.Folder.java

private static Animator setupAlphaAnimator(final View v, final float startAlpha, final float endAlpha,
        final long duration, final long startDelay) {
    v.setAlpha(startAlpha);/*  www  .j  ava  2 s.  c  o  m*/
    Animator animator = LauncherAnimUtils.ofFloat(v, "alpha", startAlpha, endAlpha);
    animator.setDuration(duration);
    animator.setStartDelay(startDelay);
    animator.setInterpolator(new LogDecelerateInterpolator(60, 0));
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // in low power mode the animation doesn't play, so set the end value here
            v.setAlpha(endAlpha);
        }
    });

    return animator;
}

From source file:liam.franco.selene.activities.MainActivity.java

private void animateCloseBottomFabSheet() {
    if (bottomFabBar != null && bottomFabBar.getVisibility() == View.VISIBLE) {
        final int[] xy = ViewUtils.viewCoordinates(fab);

        Animator animator = ViewAnimationUtils.createCircularReveal(bottomFabBar,
                (xy[0] + (fab.getMeasuredWidth() >> 1)), -bottomFabBar.getHeight(),
                Math.max(bottomFabBar.getWidth(), bottomFabBar.getHeight()), 0);
        animator.setDuration(500);
        animator.setStartDelay(500);/*  w  w w.  ja  va 2s .co m*/
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (fab != null) {
                    fab.setVisibility(View.VISIBLE);
                }
                if (bottomFabBar != null) {
                    bottomFabBar.setVisibility(View.INVISIBLE);
                }
            }
        });
        animator.start();
    }
}

From source file:com.example.android.saddacampus.MainActivity.java

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void circleReveal(int viewID, int posFromRight, boolean containsOverflow, final boolean isShow) {
    final View myView = findViewById(viewID);

    int width = myView.getWidth();

    if (posFromRight > 0)
        width -= (posFromRight/*from w  ww .j  a  v  a  2s .com*/
                * getResources().getDimensionPixelSize(R.dimen.abc_action_button_min_width_material))
                - (getResources().getDimensionPixelSize(R.dimen.abc_action_button_min_width_material) / 2);
    if (containsOverflow)
        width -= getResources().getDimensionPixelSize(R.dimen.abc_action_button_min_width_overflow_material);

    int cx = width;
    int cy = myView.getHeight() / 2;

    Animator anim;
    if (isShow)
        anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, (float) width);
    else
        anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, (float) width, 0);

    anim.setDuration((long) 220);

    // make the view invisible when the animation is done
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!isShow) {
                super.onAnimationEnd(animation);
                myView.setVisibility(View.INVISIBLE);
            }
        }
    });

    // make the view visible and start the animation
    if (isShow)
        myView.setVisibility(View.VISIBLE);

    // start the animation
    anim.start();

}