Example usage for android.view.animation Animation setDuration

List of usage examples for android.view.animation Animation setDuration

Introduction

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

Prototype

public void setDuration(long durationMillis) 

Source Link

Document

How long this animation should last.

Usage

From source file:Main.java

public static void animCollapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override// w  ww  .  java  2 s  .c  o m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

public static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override// www . j a va  2  s .c o m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration(1000);
    // a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

public static Animation getCollapseViewAnimation(final View view, int duration) {
    final int initialHeight = view.getMeasuredHeight();

    Animation animation = new Animation() {
        @Override//from   ww  w  .  j  a  va 2s .  c  om
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                view.setVisibility(View.GONE);
            } else {
                view.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                view.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setDuration(duration);
    return animation;
}

From source file:Main.java

public static void collapse(final View v, boolean isHalf) {
    final int initialHeight = v.getMeasuredHeight();

    remainHeigt = 0;//w w w  .  ja va 2s. co m
    if (isHalf) {
        remainHeigt = initialHeight / 2;
    } else {
        remainHeigt = initialHeight;
    }

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (remainHeigt * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void fadeScaleBubble(final View... views) {
    if (views == null || views.length == 0)
        return;/*from  w  ww  .j a  v a  2s.  co m*/
    for (final View v : views) {
        if (v == null || v.getVisibility() != View.VISIBLE)
            continue;
        Animation animation = new AlphaAnimation(1f, 0f);
        animation.setDuration(150);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                v.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        v.startAnimation(animation);
    }

}

From source file:com.appassit.common.Utils.java

/**
 * ??/*from   w w  w  .  jav  a2 s  . co  m*/
 * 
 * @return
 */
public static LayoutAnimationController getLayoutAnimation() {
    AnimationSet set = new AnimationSet(true);

    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(50);
    set.addAnimation(animation);

    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(100);
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
    return controller;
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void hideCopyBubble(final Activity context) {
    try {/*  w ww  . ja v a 2 s .c o  m*/
        if (context == null)
            return;
        if (copy == null)
            return;
        final RelativeLayout root = (RelativeLayout) context.findViewById(R.id.main_layout);
        if (copy.getVisibility() == View.VISIBLE) {
            Animation animation = new AlphaAnimation(1f, 0f);
            animation.setDuration(150);
            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    root.removeView(copy);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            copy.startAnimation(animation);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static Animation slideIn(View view, int from) {
    view.setVisibility(View.VISIBLE);
    Animation anim;
    switch (from) {
    case DIRECTION_LEFT:
        anim = new TranslateAnimation(-view.getWidth(), 0, 0, 0);
        break;// w  w w.j  av  a2 s  . com
    case DIRECTION_RIGHT:
        anim = new TranslateAnimation(view.getWidth(), 0, 0, 0);
        break;
    case DIRECTION_UP:
        anim = new TranslateAnimation(0, 0, -view.getHeight(), 0);
        break;
    case DIRECTION_DOWN:
        anim = new TranslateAnimation(0, 0, view.getHeight(), 0);
        break;
    default:
        throw new IllegalArgumentException(Integer.toString(from));
    }
    anim.setDuration(500);
    view.startAnimation(anim);
    return anim;
}

From source file:Main.java

public static void collapse(final View view, final AnimationListener animationListener) {
    if (view == null) {
        return;//from   w ww . j  a  v a  2s  . c  o m
    }

    final int initialHeight = view.getMeasuredHeight();

    final Animation animation = new Animation() {
        @Override
        protected void applyTransformation(final float interpolatedTime, final Transformation t) {
            if (interpolatedTime == 1) {
                view.setVisibility(View.GONE);
            } else {
                setHeight(view, initialHeight - (int) (initialHeight * interpolatedTime));
                view.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setDuration(ANIMATION_DURATION);
    // return animation;
    if (animationListener != null) {
        animation.setAnimationListener(animationListener);
    }
    view.startAnimation(animation);
}

From source file:Main.java

public static void collapse(final View v, int duration) {

    //check if view already gone
    if (v.getVisibility() == View.GONE)
        return;/*w w w  .  j a  va 2 s  . c  om*/

    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration(duration);
    v.startAnimation(a);
}