Java Code Examples for android.view.accessibility.AccessibilityEvent#TYPE_VIEW_FOCUSED

The following examples show how to use android.view.accessibility.AccessibilityEvent#TYPE_VIEW_FOCUSED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessibilityEventProcessor.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for {@link #shouldDropEvent} that handles events that automatically occur
 * immediately after a window state change.
 *
 * @param event The automatically generated event to consider retaining.
 * @return Whether to retain the event.
 */
private boolean shouldKeepAutomaticEvent(AccessibilityEvent event) {
  final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);

  // Don't drop focus events from EditTexts.
  if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
    AccessibilityNodeInfoCompat node = null;

    try {
      node = record.getSource();
      if (Role.getRole(node) == Role.ROLE_EDIT_TEXT) {
        return true;
      }
    } finally {
      AccessibilityNodeInfoUtils.recycleNodes(node);
    }
  }

  return false;
}
 
Example 2
Source File: TreeDebugNavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
@Override
public void onObserveAccessibilityEvent(AccessibilityEvent event) {
    AccessibilityNodeInfo source = event.getSource();
    if (source == null) {
        return;
    }
    boolean isNewWindow = false;
    if (mCurrentNode == null ||
            mCurrentNode.getWindowId() != source.getWindowId()) {
        isNewWindow = true;
    }
    int t = event.getEventType();
    boolean isInterestingEventType = false;
    if (t == AccessibilityEvent.TYPE_VIEW_SELECTED
            || t == AccessibilityEvent.TYPE_VIEW_FOCUSED
            || t == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED
            || t != AccessibilityEvent.TYPE_VIEW_HOVER_ENTER) {
        isInterestingEventType = true;
    }
    if (isNewWindow || isInterestingEventType) {
        setPendingNode(source);
    }
}
 
Example 3
Source File: InputFocusInterpreter.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) {
  switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_FOCUSED:
      handleViewInputFocusedEvent(event, eventId);
      break;
    case AccessibilityEvent.TYPE_VIEW_SELECTED:
      handleViewSelectedEvent(event, eventId);
      break;
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
      firstWindowFocusManager.registerWindowStateChangeEvent(event);
      break;
    default:
      break;
  }
}
 
Example 4
Source File: AccessibilityEventUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
public static int[] getAllEventTypes() {
  return new int[] {
    AccessibilityEvent.TYPE_ANNOUNCEMENT,
    AccessibilityEvent.TYPE_ASSIST_READING_CONTEXT,
    AccessibilityEvent.TYPE_GESTURE_DETECTION_END,
    AccessibilityEvent.TYPE_GESTURE_DETECTION_START,
    AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED,
    AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END,
    AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START,
    AccessibilityEvent.TYPE_TOUCH_INTERACTION_END,
    AccessibilityEvent.TYPE_TOUCH_INTERACTION_START,
    AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED,
    AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED,
    AccessibilityEvent.TYPE_VIEW_CLICKED,
    AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED,
    AccessibilityEvent.TYPE_VIEW_FOCUSED,
    AccessibilityEvent.TYPE_VIEW_HOVER_ENTER,
    AccessibilityEvent.TYPE_VIEW_HOVER_EXIT,
    AccessibilityEvent.TYPE_VIEW_LONG_CLICKED,
    AccessibilityEvent.TYPE_VIEW_SCROLLED,
    AccessibilityEvent.TYPE_VIEW_SELECTED,
    AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED,
    AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED,
    AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
    AccessibilityEvent.TYPE_WINDOWS_CHANGED,
    AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED,
    AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
  };
}
 
Example 5
Source File: PLA_AdapterView.java    From EverMemo with MIT License 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
	boolean populated = false;
	// This is an exceptional case which occurs when a window gets the
	// focus and sends a focus event via its focused child to announce
	// current focus/selection. AdapterView fires selection but not focus
	// events so we change the event type here.
	if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
		event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
	}

	// we send selection events only from AdapterView to avoid
	// generation of such event for each child
	View selectedView = getSelectedView();
	if (selectedView != null) {
		populated = selectedView.dispatchPopulateAccessibilityEvent(event);
	}

	if (!populated) {
		if (selectedView != null) {
			event.setEnabled(selectedView.isEnabled());
		}
		event.setItemCount(getCount());
		event.setCurrentItemIndex(getSelectedItemPosition());
	}

	return populated;
}
 
Example 6
Source File: PLAAdapterView.java    From Lay-s with MIT License 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
	boolean populated = false;
	// This is an exceptional case which occurs when a window gets the
	// focus and sends a focus event via its focused child to announce
	// current focus/selection. AdapterView fires selection but not focus
	// events so we change the event type here.
	if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
		event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
	}
       
	// we send selection events only from AdapterView to avoid
	// generation of such event for each child
	View selectedView = getSelectedView();
	if (selectedView != null) {
		populated = selectedView.dispatchPopulateAccessibilityEvent(event);
	}
       
	if (!populated) {
		if (selectedView != null) {
			event.setEnabled(selectedView.isEnabled());
		}
		event.setItemCount(getCount());
		event.setCurrentItemIndex(getSelectedItemPosition());
	}
       
	return populated;
}
 
Example 7
Source File: ProcessorCursorState.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) {
  switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
      // Keep track of the accessibility focused EditText.
      overlay.hide();
      saveFocusedNode(AccessibilityEventCompat.asRecord(event));
      break;
    case AccessibilityEvent.TYPE_VIEW_FOCUSED:
      // On pre Android O devices, double-tap on screen will interpreted as touch down and up
      // action at the center of the focused node, which might set cursor to the middle of text if
      // the text is long enough. TalkBack overrides the cursor position to be the end of the
      // field to avoid the confusion of cursor movement. See  for details.
      if (SHOULD_HANDLE_TOUCH_EVENT) {
        // Reset the EditText cursor because focusing will snap it to the middle.
        resetNodeCursor(AccessibilityEventCompat.asRecord(event), eventId);
      }
      break;
    case AccessibilityEvent.TYPE_VIEW_SCROLLED:
      // Hide the overlay so it doesn't interfere with scrolling.
      overlay.hide();
      break;
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START:
      if (SHOULD_HANDLE_TOUCH_EVENT) {
        // Show the overlay if the a11y-focused EditText is editing and we touch the screen.
        touchStart(event, eventId);
      }
      break;
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END:
      if (SHOULD_HANDLE_TOUCH_EVENT) {
        // Hide the overlay when we stop touching the screen.
        touchEnd(event, eventId);
      }
      break;
    default: // fall out
  }
}
 
Example 8
Source File: TextCursorManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) {
  if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED) {
    processTextSelectionChange(event);
  } else if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
    processViewInputFocused(event);
  }
}
 
Example 9
Source File: AutofillManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int getRelevantEventTypes(int relevantEventTypes) {
    return relevantEventTypes | AccessibilityEvent.TYPE_VIEW_FOCUSED
            | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED
            | AccessibilityEvent.TYPE_VIEW_CLICKED
            | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
}
 
Example 10
Source File: PLAAdapterView.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
	boolean populated = false;
	// This is an exceptional case which occurs when a window gets the
	// focus and sends a focus event via its focused child to announce
	// current focus/selection. AdapterView fires selection but not focus
	// events so we change the event type here.
	if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
		event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
	}
       
	// we send selection events only from AdapterView to avoid
	// generation of such event for each child
	View selectedView = getSelectedView();
	if (selectedView != null) {
		populated = selectedView.dispatchPopulateAccessibilityEvent(event);
	}
       
	if (!populated) {
		if (selectedView != null) {
			event.setEnabled(selectedView.isEnabled());
		}
		event.setItemCount(getCount());
		event.setCurrentItemIndex(getSelectedItemPosition());
	}
       
	return populated;
}
 
Example 11
Source File: EcoGalleryAdapterView.java    From samples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    boolean populated = false;
    // This is an exceptional case which occurs when a window gets the
    // focus and sends a focus event via its focused child to announce
    // current focus/selection. AdapterView fires selection but not focus
    // events so we change the event type here.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
    }

    // we send selection events only from AdapterView to avoid
    // generation of such event for each child
    View selectedView = getSelectedView();
    if (selectedView != null) {
        populated = selectedView.dispatchPopulateAccessibilityEvent(event);
    }

    if (!populated) {
        if (selectedView != null) {
            event.setEnabled(selectedView.isEnabled());
        }
        event.setItemCount(getCount());
        event.setCurrentItemIndex(getSelectedItemPosition());
    }

    return populated;
}
 
Example 12
Source File: DigitsEditText.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
        // Since we're replacing the text every time we add or remove a
        // character, only read the difference. (issue 5337550)
        final int added = event.getAddedCount();
        final int removed = event.getRemovedCount();
        final int length = event.getBeforeText().length();
        if (added > removed) {
            event.setRemovedCount(0);
            event.setAddedCount(1);
            event.setFromIndex(length);
        } else if (removed > added) {
            event.setRemovedCount(1);
            event.setAddedCount(0);
            event.setFromIndex(length - 1);
        } else {
            return;
        }
    } else if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
        // The parent EditText class lets tts read "edit box" when this View
        // has a focus, which
        // confuses users on app launch (issue 5275935).
        return;
    }
    super.sendAccessibilityEventUnchecked(event);
}
 
Example 13
Source File: TextEntryProvider.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
public void handleAccessibilityEvent(AccessibilityEvent event, AccessibilityNodeInfo rootNode){

        switch (event.getEventType()) {
            case AccessibilityEvent.TYPE_VIEW_FOCUSED:
                onViewFocused(event, rootNode);
                break;
            case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
                onViewTextChanged(event);
                break;
            default:
                break;
        }

    }
 
Example 14
Source File: UIActionProvider.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
public void handleAccessibilityEvent(AccessibilityEvent event, AccessibilityNodeInfo rootNode){
    int eventType = event.getEventType();
    if (eventType == AccessibilityEvent.TYPE_VIEW_CLICKED
            || eventType == AccessibilityEvent.TYPE_VIEW_LONG_CLICKED
            || eventType == AccessibilityEvent.TYPE_VIEW_FOCUSED
            || eventType == AccessibilityEvent.TYPE_VIEW_SELECTED) {
        AccEvent accEvent = new AccEvent(event, rootNode);
        accEvent.setFieldValue(AccEvent.SOURCE_NODE, event.getSource());
        this.output(accEvent);
    }
}
 
Example 15
Source File: AccessibilityEventUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
public static String typeToString(int eventType) {
  switch (eventType) {
    case AccessibilityEvent.TYPE_ANNOUNCEMENT:
      return "TYPE_ANNOUNCEMENT";
    case AccessibilityEvent.TYPE_ASSIST_READING_CONTEXT:
      return "TYPE_ASSIST_READING_CONTEXT";
    case AccessibilityEvent.TYPE_GESTURE_DETECTION_END:
      return "TYPE_GESTURE_DETECTION_END";
    case AccessibilityEvent.TYPE_GESTURE_DETECTION_START:
      return "TYPE_GESTURE_DETECTION_START";
    case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
      return "TYPE_NOTIFICATION_STATE_CHANGED";
    case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END:
      return "TYPE_TOUCH_EXPLORATION_GESTURE_END";
    case AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START:
      return "TYPE_TOUCH_EXPLORATION_GESTURE_START";
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END:
      return "TYPE_TOUCH_INTERACTION_END";
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START:
      return "TYPE_TOUCH_INTERACTION_START";
    case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
      return "TYPE_VIEW_ACCESSIBILITY_FOCUSED";
    case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED:
      return "TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED";
    case AccessibilityEvent.TYPE_VIEW_CLICKED:
      return "TYPE_VIEW_CLICKED";
    case AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED:
      return "TYPE_VIEW_CONTEXT_CLICKED";
    case AccessibilityEvent.TYPE_VIEW_FOCUSED:
      return "TYPE_VIEW_FOCUSED";
    case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER:
      return "TYPE_VIEW_HOVER_ENTER";
    case AccessibilityEvent.TYPE_VIEW_HOVER_EXIT:
      return "TYPE_VIEW_HOVER_EXIT";
    case AccessibilityEvent.TYPE_VIEW_LONG_CLICKED:
      return "TYPE_VIEW_LONG_CLICKED";
    case AccessibilityEvent.TYPE_VIEW_SCROLLED:
      return "TYPE_VIEW_SCROLLED";
    case AccessibilityEvent.TYPE_VIEW_SELECTED:
      return "TYPE_VIEW_SELECTED";
    case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
      return "TYPE_VIEW_TEXT_CHANGED";
    case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED:
      return "TYPE_VIEW_TEXT_SELECTION_CHANGED";
    case AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY:
      return "TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY";
    case AccessibilityEvent.TYPE_WINDOWS_CHANGED:
      return "TYPE_WINDOWS_CHANGED";
    case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
      return "TYPE_WINDOW_CONTENT_CHANGED";
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
      return "TYPE_WINDOW_STATE_CHANGED";
    default:
      return "(unhandled)";
  }
}
 
Example 16
Source File: AccessibilityEventProcessor.java    From talkback with Apache License 2.0 4 votes vote down vote up
public void onAccessibilityEvent(AccessibilityEvent event, EventId eventId) {

    if (testingListener != null) {
      testingListener.onAccessibilityEvent(event);
    }

    if ((dumpEventMask & event.getEventType()) != 0) {
      LogUtils.v(TAG, DUMP_EVENT_LOG_FORMAT, event);
    }

    if (shouldDropRefocusEvent(event)) {
      return;
    }

    if (shouldDropEvent(event)) {
      return;
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
      lastWindowStateChanged = SystemClock.uptimeMillis();
    }

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
        || event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
        || event.getEventType() == AccessibilityEvent.TYPE_WINDOWS_CHANGED) {
      service.setRootDirty(true);
    }

    // We need to save the last focused event so that we can filter out related selected events.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
      if (lastFocusedEvent != null) {
        lastFocusedEvent.recycle();
      }

      lastFocusedEvent = AccessibilityEvent.obtain(event);
    }

    if (AccessibilityEventUtils.eventMatchesAnyType(event, MASK_DELAYED_EVENT_TYPES)) {
      handler.postProcessEvent(event, eventId);
    } else {
      processEvent(event, eventId);
    }

    if (testingListener != null) {
      testingListener.afterAccessibilityEvent(event);
    }
  }
 
Example 17
Source File: AutofillManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public AccessibilityEvent onAccessibilityEvent(AccessibilityEvent event,
        boolean accessibilityEnabled, int relevantEventTypes) {
    final int type = event.getEventType();
    if (sVerbose) {
        // NOTE: this is waaay spammy, but that's life.
        Log.v(TAG, "onAccessibilityEvent(" + AccessibilityEvent.eventTypeToString(type)
                + "): virtualId="
                + AccessibilityNodeInfo.getVirtualDescendantId(event.getSourceNodeId())
                + ", client=" + getClient());
    }
    switch (type) {
        case AccessibilityEvent.TYPE_VIEW_FOCUSED: {
            synchronized (mLock) {
                if (mFocusedWindowId == event.getWindowId()
                        && mFocusedNodeId == event.getSourceNodeId()) {
                    return event;
                }
                if (mFocusedWindowId != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID
                        && mFocusedNodeId != AccessibilityNodeInfo.UNDEFINED_NODE_ID) {
                    notifyViewExited(mFocusedWindowId, mFocusedNodeId);
                    mFocusedWindowId = AccessibilityWindowInfo.UNDEFINED_WINDOW_ID;
                    mFocusedNodeId = AccessibilityNodeInfo.UNDEFINED_NODE_ID;
                    mFocusedBounds.set(0, 0, 0, 0);
                }
                final int windowId = event.getWindowId();
                final long nodeId = event.getSourceNodeId();
                if (notifyViewEntered(windowId, nodeId, mFocusedBounds)) {
                    mFocusedWindowId = windowId;
                    mFocusedNodeId = nodeId;
                }
            }
        } break;

        case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: {
            synchronized (mLock) {
                if (mFocusedWindowId == event.getWindowId()
                        && mFocusedNodeId == event.getSourceNodeId()) {
                    notifyValueChanged(event.getWindowId(), event.getSourceNodeId());
                }
            }
        } break;

        case AccessibilityEvent.TYPE_VIEW_CLICKED: {
            synchronized (mLock) {
                notifyViewClicked(event.getWindowId(), event.getSourceNodeId());
            }
        } break;

        case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: {
            final AutofillClient client = getClient();
            if (client != null) {
                synchronized (mLock) {
                    if (client.autofillClientIsFillUiShowing()) {
                        notifyViewEntered(mFocusedWindowId, mFocusedNodeId, mFocusedBounds);
                    }
                    updateTrackedViewsLocked();
                }
            }
        } break;
    }

    return accessibilityEnabled ? event : null;
}