TouchInteractionController


public final class TouchInteractionController
extends Object

java.lang.Object
   ↳ android.accessibilityservice.TouchInteractionController


This class allows a service to handle touch exploration and the detection of specialized accessibility gestures. The service receives motion events and can match those motion events against the gestures it supports. The service can also request the framework enter three other states of operation for the duration of this interaction. Upon entering any of these states the framework will take over and the service will not receive motion events until the start of a new interaction. The states are as follows:

  • The service can tell the framework that this interaction is touch exploration. The user is trying to explore the screen rather than manipulate it. The framework will then convert the motion events to hover events to support touch exploration.
  • The service can tell the framework that this interaction is a dragging interaction where two fingers are used to execute a one-finger gesture such as scrolling the screen. The service must specify which of the two fingers should be passed through to rest of the input pipeline.
  • Finally, the service can request that the framework delegate this interaction, meaning pass it through to the rest of the input pipeline as-is.
When AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE is enabled, this controller will receive all motion events received by the framework for the specified display when not touch-exploring or delegating. If the service classifies this interaction as touch exploration or delegating the framework will stop sending motion events to the service for the duration of this interaction. If the service classifies this interaction as a dragging interaction the framework will send motion events to the service to allow the service to determine if the interaction still qualifies as dragging or if it has become a delegating interaction. If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE is disabled this controller will not receive any motion events because touch interactions are being passed through to the input pipeline unaltered. Note that AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE requires setting R.attr.canRequestTouchExplorationMode as well.

Summary

Nested classes

interface TouchInteractionController.Callback

callbacks allow services to receive motion events and state change updates. 

Constants

int STATE_CLEAR

The state where the user is not touching the screen.

int STATE_DELEGATING

The user is performing a gesture which is being passed through to the input pipeline as-is.

int STATE_DRAGGING

The state where the user is dragging with two fingers.

int STATE_TOUCH_EXPLORING

The state where the user is explicitly exploring the screen.

int STATE_TOUCH_INTERACTING

The state where the user is touching the screen and the service is receiving motion events.

Public methods

int getDisplayId()
int getMaxPointerCount()
int getState()
void performClick()

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

void performLongClickAndStartDrag()

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

void registerCallback(Executor executor, TouchInteractionController.Callback callback)

Adds the specified callback to the list of callbacks.

void requestDelegating()

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

void requestDragging(int pointerId)

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

void requestTouchExploration()

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE is enabled and at least one callback has been added for this display this function tells the framework to initiate touch exploration.

static String stateToString(int state)

Returns a string representation of the specified state.

void unregisterAllCallbacks()

Removes all callbacks and returns control of touch interactions to the framework.

boolean unregisterCallback(TouchInteractionController.Callback callback)

Unregisters the specified callback.

Inherited methods

Constants

STATE_CLEAR

Added in API level 33
public static final int STATE_CLEAR

The state where the user is not touching the screen.

Constant Value: 0 (0x00000000)

STATE_DELEGATING

Added in API level 33
public static final int STATE_DELEGATING

The user is performing a gesture which is being passed through to the input pipeline as-is. The service is not receiving motion events.

Constant Value: 4 (0x00000004)

STATE_DRAGGING

Added in API level 33
public static final int STATE_DRAGGING

The state where the user is dragging with two fingers. The service is not receiving motion events. The selected finger is being dispatched to the rest of the input pipeline to execute the drag.

Constant Value: 3 (0x00000003)

STATE_TOUCH_EXPLORING

Added in API level 33
public static final int STATE_TOUCH_EXPLORING

The state where the user is explicitly exploring the screen. The service is not receiving motion events.

Constant Value: 2 (0x00000002)

STATE_TOUCH_INTERACTING

Added in API level 33
public static final int STATE_TOUCH_INTERACTING

The state where the user is touching the screen and the service is receiving motion events.

Constant Value: 1 (0x00000001)

Public methods

getDisplayId

Added in API level 33
public int getDisplayId ()

Returns
int the display id associated with this controller.

getMaxPointerCount

Added in API level 33
public int getMaxPointerCount ()

Returns
int the maximum number of pointers that this display will accept.

getState

Added in API level 33
public int getState ()

Returns
int the current state of this controller.

performLongClickAndStartDrag

public void performLongClickAndStartDrag ()

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

registerCallback

Added in API level 33
public void registerCallback (Executor executor, 
                TouchInteractionController.Callback callback)

Adds the specified callback to the list of callbacks. The callback will run using on the specified Executor', or on the service's main thread if the Executor is null.

Parameters
executor Executor: the executor for this callback, or null to execute on the service's main thread

callback TouchInteractionController.Callback: the callback to add, must be non-null

requestDragging

public void requestDragging (int pointerId)

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

Parameters
pointerId int

requestTouchExploration

Added in API level 33
public void requestTouchExploration ()

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE is enabled and at least one callback has been added for this display this function tells the framework to initiate touch exploration. Touch exploration will continue for the duration of this interaction.

stateToString

Added in API level 33
public static String stateToString (int state)

Returns a string representation of the specified state.

Parameters
state int

Returns
String This value cannot be null.

unregisterAllCallbacks

Added in API level 33
public void unregisterAllCallbacks ()

Removes all callbacks and returns control of touch interactions to the framework.

unregisterCallback

Added in API level 33
public boolean unregisterCallback (TouchInteractionController.Callback callback)

Unregisters the specified callback.

Parameters
callback TouchInteractionController.Callback: the callback to remove, must be non-null

Returns
boolean true if the callback was removed, false otherwise