Skip to content

Instantly share code, notes, and snippets.

@broady
Created July 1, 2014 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save broady/8229e0a2a00cc8282b1a to your computer and use it in GitHub Desktop.
Save broady/8229e0a2a00cc8282b1a to your computer and use it in GitHub Desktop.
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
public class Debouncer extends Handler implements Runnable {
private final Runnable mRunnable;
private final long mDelay;
public Debouncer(long delay, Runnable runnable) {
mRunnable = runnable;
mDelay = delay;
}
public Debouncer(long delay, Looper looper, Runnable runnable) {
super(looper);
mRunnable = runnable;
mDelay = delay;
}
@Override
public void run() {
removeMessages(0);
sendEmptyMessageDelayed(0, mDelay);
}
@Override
public void handleMessage(Message msg) {
post(mRunnable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment