Java Code Examples for android.view.animation.Animation#startNow()

The following examples show how to use android.view.animation.Animation#startNow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlothActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
@Override
protected void onSizeChanged(int width, int height, int oldw, int oldh) {
    super.onSizeChanged(width, height, oldw, oldh);
    Random random = new Random();
    Interpolator interpolator = new LinearInterpolator();

    money_count = Math.max(width, height) / 30;
    coords = new int[money_count][];
    drawables.clear();
    for (int i = 0; i < money_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), -80 };

        drawables.add(new AnimateDrawable(money_sign, animation));
        animation.setStartOffset(random.nextInt(20 * height));
        animation.startNow();
    }
}
 
Example 2
Source File: AnimateDrawables.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public SampleView(Context context) {
    super(context);
    setFocusable(true);
    setFocusableInTouchMode(true);

    Drawable dr = context.getResources().getDrawable(R.drawable.beach);
    dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());

    Animation an = new TranslateAnimation(0, 100, 0, 200);
    an.setDuration(2000);
    an.setRepeatCount(-1);
    an.initialize(10, 10, 10, 10);

    mDrawable = new AnimateDrawable(dr, an);
    an.startNow();
}
 
Example 3
Source File: AnimationHelpers.java    From ripple with GNU General Public License v3.0 5 votes vote down vote up
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
            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);
}
 
Example 4
Source File: UIHelpers.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
public static void addAnimation(View view, Animation animation, boolean first)
{
	Animation previousAnimation = view.getAnimation();
	if (previousAnimation == null || previousAnimation.getClass() == animation.getClass())
	{
		view.startAnimation(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);
}