Skip to content

Instantly share code, notes, and snippets.

@Aracem
Forked from rocboronat/RippleDelayedRunner.java
Last active August 29, 2015 14:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aracem/da92e21f50dcd2374023 to your computer and use it in GitHub Desktop.
Save Aracem/da92e21f50dcd2374023 to your computer and use it in GitHub Desktop.
package com.fewlaps.android.quitnow.base.customview;
import android.os.Handler;
import android.view.View;
/**
* A simple way to call the common new Handler().postDelayed(..., time);
* to show the Ripple animation completely and then run a Runnable. This class
* have to be used like a {@link android.view.View.OnClickListener}
*
* Created by Roc Boronat on 12/12/2014.
* Edited by Marcos Trujillo on 02/02/2015.
*/
public class RippleDelayedRunner implements View.OnClickListener {
public static final long DEFAULT_DELAY = 200;
Runnable runnable;
long delay = DEFAULT_DELAY;
public RippleDelayedRunner(Runnable runnable) {
this.runnable = runnable;
}
public RippleDelayedRunner(Runnable runnable, long delay) {
this.runnable = runnable;
this.delay = delay;
}
@Override
public void onClick(View view) {
runDelayed(runnable, SupportVersion.lollipop() ? delay : 0);
}
public static void runDelayed(Runnable runnable, long delay) {
new Handler().postDelayed(runnable, delay);
}
public static void runDelayed(Runnable runnable) {
new Handler().postDelayed(runnable, DEFAULT_DELAY);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment