Added in API level 33

TouchInteractionController


class TouchInteractionController
kotlin.Any
   ↳ 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 android.R.attr#canRequestTouchExplorationMode as well.

Summary

Nested classes
abstract

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

Constants
static Int

The state where the user is not touching the screen.

static Int

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

static Int

The state where the user is dragging with two fingers.

static Int

The state where the user is explicitly exploring the screen.

static Int

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

Public methods
Int

Int

Int

Unit

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

Unit

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

Unit

Adds the specified callback to the list of callbacks.

Unit

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

Unit
requestDragging(pointerId: Int)

If AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE and AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE

Unit

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

Returns a string representation of the specified state.

Unit

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

Boolean

Unregisters the specified callback.

Constants

STATE_CLEAR

Added in API level 33
static val STATE_CLEAR: Int

The state where the user is not touching the screen.

Value: 0

STATE_DELEGATING

Added in API level 33
static val STATE_DELEGATING: Int

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

Value: 4

STATE_DRAGGING

Added in API level 33
static val STATE_DRAGGING: Int

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.

Value: 3

STATE_TOUCH_EXPLORING

Added in API level 33
static val STATE_TOUCH_EXPLORING: Int

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

Value: 2

STATE_TOUCH_INTERACTING

Added in API level 33
static val STATE_TOUCH_INTERACTING: Int

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

Value: 1

Public methods

getDisplayId

Added in API level 33
fun getDisplayId(): Int
Return
Int the display id associated with this controller.

getMaxPointerCount

Added in API level 33
fun getMaxPointerCount(): Int
Return
Int the maximum number of pointers that this display will accept.

registerCallback

Added in API level 33
fun registerCallback(
    executor: Executor?,
    callback: TouchInteractionController.Callback
): Unit

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
callback TouchInteractionController.Callback: the callback to add, must be non-null
executor Executor?: the executor for this callback, or null to execute on the service's main thread

requestTouchExploration

Added in API level 33
fun requestTouchExploration(): Unit

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
static fun stateToString(state: Int): String

Returns a string representation of the specified state.

Return
String This value cannot be null.

unregisterAllCallbacks

Added in API level 33
fun unregisterAllCallbacks(): Unit

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

unregisterCallback

Added in API level 33
fun unregisterCallback(callback: TouchInteractionController.Callback): Boolean

Unregisters the specified callback.

Parameters
callback TouchInteractionController.Callback: the callback to remove, must be non-null
Return
Boolean true if the callback was removed, false otherwise