Package arez.dom
Class IdleStatus
java.lang.Object
arez.dom.IdleStatus
An Arez browser component that tracks when the user is idle. A user is considered idle if they have not
interacted with the browser for a specified amount of time. The component declares state that tracks when
the user is "idle". A user is considered idle if they have not interacted with the browser
for a specified amount of time.
Application code can observe the idle state via accessing isIdle().
Typically this is done in a tracking transaction such as those defined by autorun.
The "amount of time" is defined by the Observable value "timeout" accessible via
getTimeout() and mutable via setTimeout(long).
The "not interacted with the browser" is detected by listening for interaction
events on the browser. The list of events that the model listens for is controlled via
getEvents() and setEvents(Set). It should be noted that if
there is no observer observing the idle state then the model will remove listeners
so as not to have any significant performance impact.
A very simple example
import com.google.gwt.core.client.EntryPoint;
import akasha.Console;
import arez.Arez;
import arez.dom.IdleStatus;
public class IdleStatusExample
implements EntryPoint
{
public void onModuleLoad()
{
final IdleStatus idleStatus = IdleStatus.create();
Arez.context().autorun( () -> {
final String message = "Interaction Status: " + ( idleStatus.isIdle() ? "Idle" : "Active" );
Console.log( message );
} );
}
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic IdleStatuscreate()Create an instance of this model.static IdleStatuscreate(long timeout) Create an instance of this model.Return the set of events to listen to.abstract longReturn the time at which the last monitored event was received.abstract longReturn the duration for which no events should be received for the idle condition to be triggered.booleanisIdle()Return true if the user is idle.voidSpecify the set of events to listen to.abstract voidsetTimeout(long timeout) Set the timeout.
-
Method Details
-
create
Create an instance of this model.- Returns:
- an instance of IdleStatus.
-
create
Create an instance of this model.- Parameters:
timeout- the duration to after activity before becoming idle.- Returns:
- an instance of IdleStatus.
-
isIdle
Return true if the user is idle.- Returns:
- true if the user is idle, false otherwise.
-
getTimeout
Return the duration for which no events should be received for the idle condition to be triggered.- Returns:
- the timeout.
-
setTimeout
Set the timeout.- Parameters:
timeout- the timeout.
-
getEvents
Return the set of events to listen to.- Returns:
- the set of events.
-
setEvents
Specify the set of events to listen to. If the model is already active, the listeners will be updated to reflect the new events.- Parameters:
events- the set of events.
-
getLastActivityAt
Return the time at which the last monitored event was received.- Returns:
- the time at which the last event was received.
-