Example usage for android.view.animation Animation startNow

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

Introduction

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

Prototype

public void startNow() 

Source Link

Document

Convenience method to start the animation at the current time in milliseconds.

Usage

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   w  ww.  j  av  a2  s.  c  o 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/*  www.j  a  v  a2 s .c o 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:com.app.jdy.ui.LoginActivity.java

/**
 * /*from   w  w w .j  a  va  2s .com*/
 * @author Owater
 * @createtime 2015-1-13 ?6:05:11
 * @Decription ??
 * 
 */
public void intiAnimation() {
    // 
    // Animation translateAnimation = AnimationUtils.loadAnimation(this,
    // R.anim.translate_username);
    Animation translateAnimation1 = new TranslateAnimation(0, 0, 3000, 0);
    translateAnimation1.setDuration(1200);// ?
    // username_message.startAnimation(translateAnimation1);

    Animation translateAnimation2 = new TranslateAnimation(0, 0, 3000, 0);
    translateAnimation2.setDuration(1400);// ?
    // password_message.startAnimation(translateAnimation2);

    Animation translateAnimation3 = new TranslateAnimation(0, 0, 3000, 0);
    translateAnimation3.setDuration(1600);// ?
    sumbitLogin.startAnimation(translateAnimation3);
    loginOther.startAnimation(translateAnimation3);
    loginWeixin.startAnimation(translateAnimation3);

    Animation translateAnimation4 = new TranslateAnimation(0, 0, 3000, 0);
    translateAnimation4.setDuration(1800);// ?
    find_password.startAnimation(translateAnimation4);
    regirster.startAnimation(translateAnimation4);

    // ??
    // Animation animation =AnimationUtils.loadAnimation(this,
    // R.anim.animation_image_logo);
    Animation animation = new AlphaAnimation(0F, 1.0F);
    animation.setDuration(5000);
    // logoImage.startAnimation(animation);
    animation.startNow();

    /*
     * Animation scaleAnimation = new ScaleAnimation(1.0f, 1.0f, 4.0f, 1.0f,
     * Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 1.0f);
     * scaleAnimation.setDuration(2000);
     * logoImage.startAnimation(scaleAnimation); scaleAnimation.startNow();
     */
}

From source file:com.dbeginc.dbweather.utils.animations.widgets.RainFallView.java

@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
    super.onSizeChanged(width, height, oldWidth, oldHeight);
    SecureRandom random = new SecureRandom();
    Interpolator interpolator = new LinearInterpolator();

    mRainFlakeCount = Math.max(width, height) / 20;
    coords = new int[mRainFlakeCount][];
    drawables.clear();//from ww w  .  j  av  a2 s . c  o  m
    for (int i = 0; i < mRainFlakeCount; i++) {
        Animation animation = new TranslateAnimation(0, height / 10 - random.nextInt(height / 5), 0,
                height + 30);
        animation.setDuration(10 * height + random.nextInt(5 * height));
        animation.setRepeatCount(-1);
        animation.initialize(10, 10, 10, 10);
        animation.setInterpolator(interpolator);

        coords[i] = new int[] { random.nextInt(width - 30), -30 };

        drawables.add(new AnimateDrawable(mRainDrop, animation));
        animation.setStartOffset(random.nextInt(20 * height));
        animation.startNow();
        int y;
        y = random.nextInt(2);
        if (y == 0) {
            drawables.add(new AnimateDrawable(mRainDrop, animation));
        } else {
            drawables.add(new AnimateDrawable(mRainDrop));
        }
    }
}

From source file:com.dbeginc.dbweather.utils.animations.widgets.SnowFallView.java

@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
    super.onSizeChanged(width, height, oldWidth, oldHeight);
    Random random = new SecureRandom();
    Interpolator interpolator = new LinearInterpolator();

    snow_flake_count = Math.max(width, height) / 20;
    coords = new int[snow_flake_count][];
    drawables.clear();/*from w  ww.j  av a2s.c  o  m*/
    for (int i = 0; i < snow_flake_count; i++) {
        Animation animation = new TranslateAnimation(0, height / 10 - random.nextInt(height / 5), 0,
                height + 30);
        animation.setDuration(10 * height + random.nextInt(5 * height));
        animation.setRepeatCount(-1);
        animation.initialize(10, 10, 10, 10);
        animation.setInterpolator(interpolator);

        coords[i] = new int[] { random.nextInt(width - 30), -30 };

        drawables.add(new AnimateDrawable(snow_flake, animation));
        animation.setStartOffset(random.nextInt(20 * height));
        animation.startNow();
        int y;
        y = random.nextInt(2);
        if (y == 0) {
            drawables.add(new AnimateDrawable(snow_flake, animation));
        } else {
            drawables.add(new AnimateDrawable(snow_flake));
        }
    }
}