Highlighting the current shortcut
When the user gazes at a shortcut, it should be able to indicate that it is selectable. In the next section, we'll wire it up to highlight the selected item and to actually launch the corresponding app.
The trick here is to determine which slot is in front of the user. To highlight it, we'll brighten the text color.
Let's write a helper method to determine which slot is currently in the gaze, based on the headOffset
variable (which was calculated from the head yaw angle). Add the getSlot
method to the OverlayView
class:
public int getSlot() { int slotOffset = shortcutWidth/2 - headOffset; slotOffset /= shortcutWidth; if(slotOffset < 0) slotOffset = 0; if(slotOffset >= shortcuts.size()) slotOffset = shortcuts.size() - 1; return slotOffset; }
One half of the shortcutWidth
value is added to the headOffset
value, so we detect gazing at the center of the shortcut. Then, we add the negative...