Search code examples
androidaccessibilityseekbartalkback

Using SeekBar and OnSeekBarChangeListener with Android TalkBack service enabled


I'm in a need of recognizing that the user has ended the seekbar progress change using the onStopTrackingTouch callback method from the OnSeekBarChangeListener interface.

This works fine whenever the seekbar progress change action is triggered in the normal touch mode, however when having the TalkBack service enabled I'm no longer able to detect this event (the callback is not fired). This is kind of expected (since the progress change with accessibility service enabled does not involve any screen-touch action), as the documentation states the following:

/**
 * Notification that the user has finished a touch gesture. Clients may want to use this
 * to re-enable advancing the seekbar.
 * @param seekBar The SeekBar in which the touch gesture began
 */
void onStopTrackingTouch(SeekBar seekBar);

In such case I'm afraid I need to extract the logic I have in this method to be located somewhere else and call it conditionally (depending on the TalkBack service being enabled) from the onProgressChanged method, eg.

if (accessibilityManager.isEnabled && accessibilityManager.isTouchExplorationEnabled) {
    fireTheAction()
}

I'm not happy to use this if-statement every time. Is there any way to force the TalkBack service to call this method?


Solution

  • Unfortunately, there is no other option documented, so the way to follow is to check manually whether the action has been invoked by the user and if the accessibility service is enabled.

    public void onProgressChanged(SeekBar b, int progress, boolean fromUser) {
        if (!fromUser) return;
        // some logic
    
        if (accessibilityManager.isEnabled && accessibilityManager.isTouchExplorationEnabled) {
            fireTheAction();
        }
    }