ListenerΒΆ

Listener Class Reference

The Listener class defines a set of callback functions that you can override in a subclass to respond to events dispatched by the Controller object. More...

Public Member Functions

 Listener ()
 Constructs a Listener object. More...
 
void onConnect (Controller arg0)
 Called when the Controller object connects to the Leap Motion software and the Leap Motion hardware device is plugged in, or when this Listener object is added to a Controller that is already connected. More...
 
void onDeviceChange (Controller arg0)
 Called when a Leap Motion controller is plugged in, unplugged, or the device changes state. More...
 
void onDeviceFailure (Controller arg0)
 Called when a Leap Motion controller device is plugged into the client computer, but fails to operate properly. More...
 
void onDisconnect (Controller arg0)
 Called when the Controller object disconnects from the Leap Motion software or the Leap Motion hardware is unplugged. More...
 
void onExit (Controller arg0)
 Called when this Listener object is removed from the Controller or the Controller instance is destroyed. More...
 
void onFocusGained (Controller arg0)
 Called when this application becomes the foreground application. More...
 
void onFocusLost (Controller arg0)
 Called when this application loses the foreground focus. More...
 
void onFrame (Controller arg0)
 Called when a new frame of hand and finger tracking data is available. More...
 
void onImages (Controller arg0)
 Called when new images are available. More...
 
void onInit (Controller arg0)
 Called once, when this Listener object is newly added to a Controller. More...
 
void onLogMessage (Controller arg0, MessageSeverity severity, long timestamp, String msg)
 Called when the service emits a log message to report an error, warning, or status change. More...
 
void onServiceChange (Controller arg0)
 Called when the Leap Motion service is paused or resumed or when a controller policy is changed. More...
 
void onServiceConnect (Controller arg0)
 Called when the Leap Motion daemon/service connects to your application Controller. More...
 
void onServiceDisconnect (Controller arg0)
 Called if the Leap Motion daemon/service disconnects from your application Controller. More...
 

Detailed Description

The Listener class defines a set of callback functions that you can override in a subclass to respond to events dispatched by the Controller object.

To handle Leap Motion events, create an instance of a Listener subclass and assign it to the Controller instance. The Controller calls the relevant Listener callback function when an event occurs, passing in a reference to itself. You do not have to implement callbacks for events you do not want to handle.

The Controller object calls these Listener functions from a thread created by the Leap Motion library, not the thread used to create or set the Listener instance.

Since
1.0

Constructor & Destructor Documentation

Listener ( )

Constructs a Listener object.

Since
1.0

Member Function Documentation

void onConnect ( Controller  arg0)

Called when the Controller object connects to the Leap Motion software and the Leap Motion hardware device is plugged in, or when this Listener object is added to a Controller that is already connected.

When this callback is invoked, Controller::isServiceConnected is true, Controller::devices() is not empty, and, for at least one of the Device objects in the list, Device::isStreaming() is true.

public void onConnect (Controller controller){
System.out.println("Connected");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.0
void onDeviceChange ( Controller  arg0)

Called when a Leap Motion controller is plugged in, unplugged, or the device changes state.

State changes include entering or leaving robust mode and low resource mode. Note that there is no direct way to query whether the device is in these modes, although you can use Controller::isLightingBad() to check if there are environmental IR lighting problems.

public void onDeviceChange (Controller controller){
System.out.println("Device changed");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.2
void onDeviceFailure ( Controller  arg0)

Called when a Leap Motion controller device is plugged into the client computer, but fails to operate properly.

Get the list containing all failed devices using Controller::failedDevices(). The members of this list provide the device pnpID and reason for failure.

public void onDeviceFailure (Controller controller)
{
System.out.println ("A device was plugged in, but failed.");
FailedDeviceList badDevices = controller.failedDevices();
}
Parameters
controllerThe Controller object invoking this callback function.
Since
3.0
void onDisconnect ( Controller  arg0)

Called when the Controller object disconnects from the Leap Motion software or the Leap Motion hardware is unplugged.

The controller can disconnect when the Leap Motion device is unplugged, the user shuts the Leap Motion software down, or the Leap Motion software encounters an unrecoverable error.

public void onDisconnect (Controller controller){
System.out.println("Disconnected");
}

Note: When you launch a Leap-enabled application in a debugger, the Leap Motion library does not disconnect from the application. This is to allow you to step through code without losing the connection because of time outs.

Parameters
controllerThe Controller object invoking this callback function.
Since
1.0
void onExit ( Controller  arg0)

Called when this Listener object is removed from the Controller or the Controller instance is destroyed.

public void onExit (Controller controller){
System.out.println("Exited");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.0
void onFocusGained ( Controller  arg0)

Called when this application becomes the foreground application.

Only the foreground application receives tracking data from the Leap Motion Controller. This function is only called when the controller object is in a connected state.

public void onFocusGained (Controller controller){
System.out.println("Focus gained");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.0
void onFocusLost ( Controller  arg0)

Called when this application loses the foreground focus.

Only the foreground application receives tracking data from the Leap Motion Controller. This function is only called when the controller object is in a connected state.

public void onFocusLost (Controller controller){
System.out.println("Focus lost");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.0
void onFrame ( Controller  arg0)

Called when a new frame of hand and finger tracking data is available.

Access the new frame data using the Controller::frame() function.

public void onFrame (Controller controller){
System.out.println("New Frame");
Frame frame = controller.frame ();
}

Note, the Controller skips any pending onFrame events while your onFrame handler executes. If your implementation takes too long to return, one or more frames can be skipped. The Controller still inserts the skipped frames into the frame history. You can access recent frames by setting the history parameter when calling the Controller::frame() function. You can determine if any pending onFrame events were skipped by comparing the ID of the most recent frame with the ID of the last received frame.

Parameters
controllerThe Controller object invoking this callback function.
Since
1.0
void onImages ( Controller  arg0)

Called when new images are available.

Access the new frame data using the Controller::images() function.

public void onImages (Controller controller){
System.out.println("New images available");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
2.2.1
void onInit ( Controller  arg0)

Called once, when this Listener object is newly added to a Controller.

public void onInit (Controller controller){
System.out.println("Initialized");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.0
void onLogMessage ( Controller  arg0,
MessageSeverity  severity,
long  timestamp,
String  msg 
)

Called when the service emits a log message to report an error, warning, or status change.

Log message text is provided as ASCII-encoded english.

Parameters
controllerThe Controller object invoking this callback function.
severityThe severity of the error, if known.
timestampThe timestamp of the error in microseconds. (Use Controller::now() - timestamp to compute the age of the message.)
msgThe log message.
Since
3.0
void onServiceChange ( Controller  arg0)

Called when the Leap Motion service is paused or resumed or when a controller policy is changed.

The service can change states because the computer user changes settings in the Leap Motion Control Panel application or because an application connected to the service triggers a change. Any application can pause or unpause the service, but only runtime policy changes you make apply to your own application.

public void onServiceChange (Controller controller)
{
System.out.println ("Service state change.");
}

You can query the pause state of the controller with Controller::isPaused(). You can check the state of those policies you are interested in with Controller::isPolicySet().

Parameters
controllerThe Controller object invoking this callback function.
Since
3.0
void onServiceConnect ( Controller  arg0)

Called when the Leap Motion daemon/service connects to your application Controller.

public void onServiceConnect (Controller controller){
System.out.println("Service connected");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.2
void onServiceDisconnect ( Controller  arg0)

Called if the Leap Motion daemon/service disconnects from your application Controller.

Normally, this callback is not invoked. It is only called if some external event or problem shuts down the service or otherwise interrupts the connection.

public void onServiceDisconnect (Controller controller){
System.out.println("Service connection lost");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.2