Example usage for android.os Handler postAtTime

List of usage examples for android.os Handler postAtTime

Introduction

In this page you can find the example usage for android.os Handler postAtTime.

Prototype

public final boolean postAtTime(Runnable r, long uptimeMillis) 

Source Link

Document

Causes the Runnable r to be added to the message queue, to be run at a specific time given by uptimeMillis.

Usage

From source file:Main.java

/**
 * Starts an AnimationDrawable animation at the specified point in the future.
 * @param handler The Handler for the Activity in which the animation will run.
 * @param drawable The AnimationDrawable that will have its animation started.
 * @param millisFromNow The number of milliseconds to wait before starting this animation. 
 *//*from   w w  w.  j a v  a 2 s . co m*/
public static void startAnimationInFuture(final Handler handler, final AnimationDrawable drawable,
        long millisFromNow) {
    handler.postAtTime(new Runnable() {
        @Override
        public void run() {
            drawable.start();
        }
    }, SystemClock.uptimeMillis() + millisFromNow);
}

From source file:Main.java

/**
 * Replaces an ImageView's background AnimationDrawable with the specified resource id in the
 * future. Calls start() on the AnimationDrawable once it has been replaced. 
 * @param handler The Handler for the Activity in which the animation will run.
 * @param imageView An ImageView that has a background that can be casted to AnimationDrawable.
 * @param animationResourceId The animation's resource id.
 * @param color The color to apply to the AnimationDrawable. 
 * @param millisFromNow The number of milliseconds to wait before replacing the animation. 
 *//*from  w ww  .  jav a2s.  c  o m*/
public static void replaceAnimationInFuture(final Handler handler, final ImageView imageView,
        final int animationResourceId, final int color, long millisFromNow) {
    handler.postAtTime(new Runnable() {
        @Override
        public void run() {
            imageView.setBackgroundResource(animationResourceId);
            imageView.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            ((AnimationDrawable) (imageView.getBackground())).start();
        }
    }, SystemClock.uptimeMillis() + millisFromNow);
}