Example usage for android.view View setAnimation

List of usage examples for android.view View setAnimation

Introduction

In this page you can find the example usage for android.view View setAnimation.

Prototype

public void setAnimation(Animation animation) 

Source Link

Document

Sets the next animation to play for this view.

Usage

From source file:Main.java

public static void showEmpty(Activity activity, boolean show, View emptyView) {
    Animation anim = AnimationUtils.loadAnimation(activity,
            show ? android.R.anim.fade_in : android.R.anim.fade_out);
    if (show && (emptyView.getVisibility() == View.GONE || emptyView.getVisibility() == View.INVISIBLE)) {
        emptyView.setAnimation(anim);
        emptyView.setVisibility(View.VISIBLE);
    } else if (!show && emptyView.getVisibility() == View.VISIBLE) {
        emptyView.setAnimation(anim);//w ww.j  a va  2s .  c  o m
        emptyView.setVisibility(View.GONE);
    }
}

From source file:Main.java

public static void setAlphaAnimation(View v, int time, int repeatCount, int startOffset) {
    AlphaAnimation myAnimation_Alpha = new AlphaAnimation(0f, 1.0f);
    myAnimation_Alpha.setDuration(time);
    myAnimation_Alpha.setRepeatCount(repeatCount);
    myAnimation_Alpha.setStartOffset(startOffset);
    v.setAnimation(myAnimation_Alpha);
}

From source file:Main.java

public static void showEmpty(Context activity, boolean show, View emptyView) {
    if (emptyView != null) {

        Animation anim = AnimationUtils.loadAnimation(activity,
                show ? android.R.anim.fade_in : android.R.anim.fade_out);
        if (show && (emptyView.getVisibility() == View.GONE || emptyView.getVisibility() == View.INVISIBLE)) {
            emptyView.setAnimation(anim);
            emptyView.setVisibility(View.VISIBLE);
        } else if (!show && emptyView.getVisibility() == View.VISIBLE) {
            emptyView.setAnimation(anim);
            emptyView.setVisibility(View.GONE);
        }//from  w  ww  .j  a v  a2  s. c o m
    }
}

From source file:Main.java

public static void addAnimation(View view, Animation animation, boolean first) {
    Animation previousAnimation = view.getAnimation();
    if (previousAnimation == null || previousAnimation.getClass() == animation.getClass()) {
        if (animation.getStartTime() == Animation.START_ON_FIRST_FRAME)
            view.startAnimation(animation);
        else/*from   www.j a  va2s .co m*/
            view.setAnimation(animation);
        return;
    }

    if (!(previousAnimation instanceof AnimationSet)) {
        AnimationSet newSet = new AnimationSet(false);
        newSet.addAnimation(previousAnimation);
        previousAnimation = newSet;
    }

    // Remove old of same type
    //
    AnimationSet set = (AnimationSet) previousAnimation;
    for (int i = 0; i < set.getAnimations().size(); i++) {
        Animation anim = set.getAnimations().get(i);
        if (anim.getClass() == animation.getClass()) {
            set.getAnimations().remove(i);
            break;
        }
    }

    // Add this (first if it is a scale animation ,else at end)
    if (animation instanceof ScaleAnimation || first) {
        set.getAnimations().add(0, animation);
    } else {
        set.getAnimations().add(animation);
    }

    animation.startNow();
    view.setAnimation(set);
}

From source file:Main.java

static void addAnimation(View view, Animation animation, boolean first) {
    Animation previousAnimation = view.getAnimation();
    if (previousAnimation == null || previousAnimation.getClass() == animation.getClass()) {
        if (animation.getStartTime() == Animation.START_ON_FIRST_FRAME)
            view.startAnimation(animation);
        else//from ww  w .  j  a v a  2  s. c  om
            view.setAnimation(animation);
        return;
    }

    if (!(previousAnimation instanceof AnimationSet)) {
        AnimationSet newSet = new AnimationSet(false);
        newSet.addAnimation(previousAnimation);
        previousAnimation = newSet;
    }

    // Remove old of same type
    //
    AnimationSet set = (AnimationSet) previousAnimation;
    for (int i = 0; i < set.getAnimations().size(); i++) {
        Animation anim = set.getAnimations().get(i);
        if (anim.getClass() == animation.getClass()) {
            set.getAnimations().remove(i);
            break;
        }
    }

    // Add this (first if it is a scale animation ,else at end)
    if (animation instanceof ScaleAnimation || first) {
        set.getAnimations().add(0, animation);
    } else {
        set.getAnimations().add(animation);
    }

    animation.startNow();
    view.setAnimation(set);
}

From source file:Main.java

public static void setFlickerAnimation(View v) {
    final Animation animation = new AlphaAnimation(1, 0); // Change alpha
    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter
                                                         // animation
                                                         // rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation
                                                  // infinitely
    animation.setRepeatMode(Animation.REVERSE); //
    v.setAnimation(animation);
}

From source file:Main.java

public static void toggleBottomView(View view, boolean isShow, int duration) {
    if (view != null) {
        float fromYDelta = 0;
        float toYDelta = 0;
        int visibility;

        if (isShow) {
            fromYDelta = view.getHeight();
            visibility = View.VISIBLE;
        } else {/*from   ww  w .j a va2s . c om*/
            toYDelta = view.getHeight();
            visibility = View.GONE;
        }

        if (fromYDelta == toYDelta) {
            setMeasureSpec(view);
            if (isShow) {
                fromYDelta = view.getMeasuredHeight();
            } else {
                toYDelta = view.getMeasuredHeight();
            }
        }

        view.setAnimation(translate(0, 0, fromYDelta, toYDelta, duration));
        view.setVisibility(visibility);
    }
}

From source file:Main.java

private static void scaleUpAni(View v) {
    /*if(scaleUpAni == null){
       scaleUpAni = new ScaleAnimation(SCALE_DOWN_VALUE, 1.0f, SCALE_DOWN_VALUE, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
       scaleUpAni.setDuration(SCALE_ANI_DURATION);
       scaleUpAni.setFillAfter(true);/*from www. j a  v a2 s.  co m*/
    }
                
    //v.startAnimation(scaleUpAni);
    v.setAnimation(scaleUpAni);
    scaleUpAni.startNow();*/

    //v.getAnimation().cancel();
    //v.getAnimation().reset();
    /*v.clearAnimation();
    v.clearFocus();*/

    /*v.clearAnimation();
    v.setAnimation(null);*/
    if (v.getAnimation() != null) {
        v.getAnimation().cancel();
        v.getAnimation().reset();
    }

    v.clearAnimation();
    v.setAnimation(null);

    /*v.animate().scaleX(1.0f);
    v.animate().scaleY(1.0f);
    v.animate().setDuration(SCALE_ANI_DURATION);
    v.animate().start();*/

    //v.setScaleX(1.0f);
    //v.setScaleY(1.0f);
}

From source file:Main.java

/**
 * Applies a fade in animation and set the visibility in
 * {@link View#VISIBLE}./*from  w ww.j ava 2  s  . c  o m*/
 * @param view view to animate.
 */
public static void fadeInView(final View view) {
    if (view.getVisibility() != View.VISIBLE) {
        cancelAnimation(view);
        view.setVisibility(View.VISIBLE);
        Animation animation = android.view.animation.AnimationUtils.loadAnimation(view.getContext(),
                android.R.anim.fade_in);
        animation.setFillEnabled(true);
        animation.setFillBefore(true);
        animation.setFillAfter(true);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                view.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        view.setAnimation(animation);
        animation.start();
    }
}

From source file:Main.java

/**
 * Applies a fade out animation and set the visibility in
 * {@link View#GONE}.//from w ww .j  a v a  2 s .  c o  m
 * @param view view to animate.
 */
public static void fadeOutView(final View view) {
    if (view.getVisibility() == View.VISIBLE) {
        cancelAnimation(view);
        Animation animation = android.view.animation.AnimationUtils.loadAnimation(view.getContext(),
                android.R.anim.fade_out);
        animation.setFillEnabled(true);
        animation.setFillBefore(true);
        animation.setFillAfter(true);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

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

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        view.setAnimation(animation);
        animation.start();
    }
}