/** * A {@linkplain View.OnClickListener click listener} that debounces multiple clicks posted in the * same frame. A click on one button disables all buttons for that frame. */ publicabstractclassDebouncingOnClickListenerimplementsView.OnClickListener{ private static final Runnable ENABLE_AGAIN = () -> enabled = true; private static final Handler MAIN = new Handler(Looper.getMainLooper());
// Post to the main looper directly rather than going through the view. // Ensure that ENABLE_AGAIN will be executed, avoid static field {@link #enabled} // staying in false state. MAIN.post(ENABLE_AGAIN);