-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced UserInteraction utility class (for html mapper internal pu…
…rposes)
- Loading branch information
Showing
7 changed files
with
129 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...gwt/src/main/java/dev/webfx/kit/mapper/peers/javafxgraphics/gwt/html/UserInteraction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.webfx.kit.mapper.peers.javafxgraphics.gwt.html; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Bruno Salmon | ||
*/ | ||
public final class UserInteraction { | ||
|
||
private static int USER_INTERACTIONS_COUNT = 0; | ||
private static boolean IS_USER_INTERACTING; | ||
private static final List<Runnable> NEXT_USER_INTERACTION_RUNNABLES = new ArrayList<>(); | ||
private static boolean NEXT_USER_INTERACTION_RUNNABLE_REQUIRES_TOUCH_EVENT_DEFAULT; | ||
public static void setUserInteracting(boolean on) { | ||
IS_USER_INTERACTING = on; | ||
if (on) { | ||
USER_INTERACTIONS_COUNT++; | ||
if (!NEXT_USER_INTERACTION_RUNNABLES.isEmpty()) { | ||
for (Iterator<Runnable> it = NEXT_USER_INTERACTION_RUNNABLES.iterator(); it.hasNext(); ) { | ||
it.next().run(); | ||
it.remove(); | ||
} | ||
NEXT_USER_INTERACTION_RUNNABLE_REQUIRES_TOUCH_EVENT_DEFAULT = false; | ||
} | ||
} | ||
} | ||
|
||
public static boolean isUserInteracting() { | ||
return IS_USER_INTERACTING; | ||
} | ||
|
||
public static boolean hasUserNotInteractedYet() { | ||
return USER_INTERACTIONS_COUNT == 0; | ||
} | ||
|
||
public static boolean nextUserRunnableRequiresTouchEventDefault() { | ||
return NEXT_USER_INTERACTION_RUNNABLE_REQUIRES_TOUCH_EVENT_DEFAULT; | ||
} | ||
|
||
public static void runOnNextUserInteraction(Runnable runnable) { | ||
runOnNextUserInteraction(runnable, false); | ||
} | ||
|
||
public static void runOnNextUserInteraction(Runnable runnable, boolean requireTouchEventDefault) { | ||
NEXT_USER_INTERACTION_RUNNABLES.add(runnable); | ||
if (requireTouchEventDefault) { | ||
NEXT_USER_INTERACTION_RUNNABLE_REQUIRES_TOUCH_EVENT_DEFAULT = true; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters