Detecting inactivity for your (kiosk) application
When developing a kiosk application we usually need to reset it's state after some period of inactivity.
InactivityService — used to notify our context that it's inactive for a certain amount of time:
package mvcs.service
{
import configs.AppConfig;
import mvcs.SignalBus;
import mvcs.view.IContextView;
import com.inreflected.events.InactivityEvent;
import com.inreflected.ui.managers.InactivityManager;
import flash.display.InteractiveObject;
/**
* @author Pavel fljot
*/
[Inject]
public class InactivityService
{
[Inject]
public var signalBus:SignalBus;
private var inactivityManager:InactivityManager;
public function InactivityService(contextView:IContextView)
{
inactivityManager = new InactivityManager(contextView as InteractiveObject, AppConfig.INACTIVITY_DELAY);
inactivityManager.addEventListener(InactivityEvent.INACTIVE, inactivityManager_inactiveHandler);
}
public function start():void
{
inactivityManager.start();
}
public function stop():void
{
inactivityManager.stop();
}
private function inactivityManager_inactiveHandler(event:InactivityEvent):void
{
signalBus.inactive.dispatch();
}
}
}
[Inject] in front of class is used for constructor injection to pass our contextView as IContextView (interface that works just as a marker). Don't forget to add IContextView implementation for context view and map it in application context, for example:
injector.mapValue(IContextView, contextView);
I prefer to use SignalBus over separate signal classes (less code to write, easier to develop since I'm not forced to map signal class to something). AppConfig.INACTIVITY_DELAY is a constant — delay in milliseconds, e.g. 1000 * 60 * 15 for 15 minutes.
So you obviously map inactivity notification to some RestartCommand in your application context:
signalCommandMap.mapSignal(signalBus.inactive, RestartCommand);
In my StartupCompleteCommand (executed when app is completely ready to be started) I inject and start my InactivityService:
CONFIG::Release
{
// ...
inactivityService.start();
}
InactivityManager is a small utility that actually tracks a set
of events (MouseEvents and KeyborardEvents by default) from a
certain scope (InteractiveObject), code on github gist:
https://gist.github.com/5befaff062292b6512c7
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Ondina D.F. closed this discussion on 12 Dec, 2011 12:17 PM.