0

I have a custom view that overrides dispatchHoverEvent() so it can implement some support for talkBack features, it has the following code for testing:

int action = event.getActionMasked();
    switch (action) {
        case MotionEvent.ACTION_HOVER_ENTER: {
            Log.d("dispatchHoverEvent", "ACTION_HOVER_ENTER x=" + x + " y=" + y);
            break;
        }
        case MotionEvent.ACTION_HOVER_MOVE: {
            Log.d("dispatchHoverEvent", "ACTION_HOVER_MOVE x=" + x + " y=" + y);
            break;
        }
        case MotionEvent.ACTION_HOVER_EXIT: {
            Log.d("dispatchHoverEvent", "ACTION_HOVER_EXIT x=" + x + " y=" + y);
            break;
        }
    }

The output for this after two gestures is (removed some ACTION_HOVER_MOVE log outputs):

D/dispatchHoverEvent: ACTION_HOVER_ENTER x=73.03711 y=413.70703
D/dispatchHoverEvent: ACTION_HOVER_MOVE x=79.0686 y=412.71094
D/dispatchHoverEvent: ACTION_HOVER_MOVE x=85.06714 y=412.71094
D/dispatchHoverEvent: ACTION_HOVER_MOVE x=93.07617 y=412.71094
D/dispatchHoverEvent: ACTION_HOVER_MOVE x=103.062744 y=412.71094
...
...
D/dispatchHoverEvent: ACTION_HOVER_MOVE x=203.15918 y=416.6953
D/dispatchHoverEvent: ACTION_HOVER_EXIT x=203.15918 y=416.6953
D/dispatchHoverEvent: ACTION_HOVER_ENTER x=73.03711 y=412.71094
D/dispatchHoverEvent: ACTION_HOVER_MOVE x=643.5571 y=413.70703
D/dispatchHoverEvent: ACTION_HOVER_EXIT x=643.5571 y=413.70703

The problem is the ACTION_HOVER_ENTER events, specifically the following enter event after a move and exit event. In api24+ the second hover enter event seems to repeat the previous hover enter event's coordinates (if the initial enter event is held for a few seconds). Sometimes it has the identical x, y values, or just one of them, but the actual enter event is not near either coordinate values. This is throwing off my handling of the accessibility events for the custom view.

If there are hover events that don't have ACTION_HOVER_MOVE it gives the predicted behaviour:

D/dispatchHoverEvent: ACTION_HOVER_ENTER x=98.08594 y=424.72266
D/dispatchHoverEvent: ACTION_HOVER_EXIT x=98.08594 y=424.72266
D/dispatchHoverEvent: ACTION_HOVER_ENTER x=442.3755 y=428.70703
D/dispatchHoverEvent: ACTION_HOVER_EXIT x=442.3755 y=428.70703

Is this a characteristics of how accessibility uses hover events? Is there any way to avoid this behaviour?

Only been able to test this on an emulator.

bluewhale
  • 181
  • 2
  • 9

1 Answers1

0

The reported locations for these events are from the system and it seems unavoidable. My code that handles these hover events was just not robust enough to deal with them. The solution was to making it able to deal with these hover enter events that report previous, old location.

bluewhale
  • 181
  • 2
  • 9