Touchpad¶
The touchpad on Iristick smart glasses is used to navigate through the widgets
when the heads-up display mirrors the content of the phone screen.
This behavior can be overridden to process touch events manually.
There are two kinds of touch events: simple gestures and precise finger
movements.
In both cases, the app has to call the
Headset.registerTouchEventCallback
method.
This is best done in the onResume
method.
@Override
protected void onResume() {
super.onResume();
Headset headset = IristickApp.getHeadset();
if (headset != null) {
headset.registerTouchEventCallback(new TouchEvent.Callback() {
@Override
public void onTouchEvent(@NonNull TouchEvent event) {
/* Process the touch event here:
* event.getGestureCode() returns the simple gesture that was
* recognized, or TouchEvent.GESTURE_NONE if none;
* event.getMotionEvent() returns the precise motion data or
* null if such data is not available.
*/
}
}, null);
}
}
By default, registering a touchpad callback disables the default navigation
system which allows users to interact with on-screen widgets.
There is one exception though: swiping down will continue triggering a "back"
action for consistency with other apps. To override this behavior, pass
additional flags to registerCallback
.
You can unregister the callback with the
Headset.unregisterTouchEventCallback()
method to stop
receiving touch events.
Attention
Always unregister touch callbacks in your activity's onPause()
to give
control back to the default navigation system.
Example code
The Touchpad Example provided in the SDK package provides an example on how to use the Touchpad API. It shows the gestures that were made on the touchpad. It also enables the user to move a drawing cursor on the main phone display by moving a finger over the touchpad.
Simple interaction via gestures¶
The touchpad of the Iristick smart glasses can distinguish between several specific gestures. The following gestures are recognized:
- Single tap: the user briefly touches the touchpad;
- Double tap: the user taps twice in quick succession;
- Long tap: similar to a single tap, but held for a longer time;
- Swipe forward: the user swipes their finger over the touchpad from the back towards the front, away from their ear;
- Swipe backward: the user swipes their finger over the touchpad from the front towards the back, towards their ear;
- Swipe down: the user swipes their finger over the touchpad in a downward motion;
Use the getGestureCode()
method to determine which gesture,
if any, was performed.
Precise control with MotionEvents¶
Some use cases require more precise, fluid or continuous control. For these
cases, the touch event contains a MotionEvent
object,
describing the exact finger movement over the touchpad.
The X and Y coordinates of the motion events represent the
current absolute position of the finger on the touchpad with (0, 0)
located
at the bottom left corner of the touchpad near the ear and (1, 1)
located at
the upper right corner near the front of the glasses.
The action of the motion events describe what the finger is currently doing with the touchpad. The following actions are supported:
ACTION_DOWN
: the finger has started touching the touchpad;ACTION_MOVE
: the finger continues to touch the touchpad;ACTION_UP
: the finger is lifted from the touchpad;ACTION_HOVER_MOVE
: a gesture is recognized after the finger was lifted from the touchpad. You will most probably want to ignore any event with this action.