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

The following examples show how to use android.view.accessibility.AccessibilityEvent#TYPE_VIEW_SELECTED . 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: 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 2
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 3
Source File: DefaultTimeBar.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
        event.getText().add(getProgressText());
    }
    event.setClassName(ACCESSIBILITY_CLASS_NAME);
}
 
Example 4
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 5
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 6
Source File: EdxRatingBar.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
        final Map<String, CharSequence> map = new HashMap<>();
        map.put("rating", String.valueOf((int) getRating()));
        map.put("num_of_stars", String.valueOf(getNumStars()));
        event.setContentDescription(ResourceUtil.getFormattedString(getResources(),
                R.string.rating_bar_selection, map));
    }
}
 
Example 7
Source File: DialView.java    From android-BasicAccessibility with Apache License 2.0 5 votes vote down vote up
/**
 * This is where a View should populate outgoing accessibility events with its text content.
 * While this method is free to modify event attributes other than text content, doing so
 * should normally be performed in
 * {@link #onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent)}.
 * <p/>
 * <p>Note that the behavior of this method will typically vary, depending on the type of
 * accessibility event is passed into it. The allowed values also very, and are documented
 * in {@link android.view.accessibility.AccessibilityEvent}.
 * <p/>
 * <p>Typically, this is where you'll describe the state of your custom view. You may also
 * want to provide custom directions when the user has focused your view.
 *
 * @param event The accessibility event which to populate.
 */
// BEGIN_INCLUDE (on_populate_accessibility_event)
@Override
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    super.onPopulateAccessibilityEvent(event);

    // Detect what type of accessibility event is being passed in.
    int eventType = event.getEventType();

    // Common case: The user has interacted with our view in some way. State may or may not
    // have been changed. Read out the current status of the view.
    //
    // We also set some other metadata which is not used by TalkBack, but could be used by
    // other TTS engines.
    if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED ||
            eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        event.getText().add("Mode selected: " + Integer.toString(mActiveSelection + 1) + ".");
        event.setItemCount(SELECTION_COUNT);
        event.setCurrentItemIndex(mActiveSelection);
    }

    // When a user first focuses on our view, we'll also read out some simple instructions to
    // make it clear that this is an interactive element.
    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        event.getText().add("Tap to change.");
    }
}
 
Example 8
Source File: EditProtocol.java    From ans-android-sdk with GNU General Public License v3.0 4 votes vote down vote up
public BaseViewVisitor readEventBinding(JSONObject source,
                                        BaseViewVisitor.OnEventListener listener)
        throws BadInstructionsException {
    try {
        final String eventID = source.getString("event_id");
        final String eventType = source.getString("event_type");
        String matchType = null;
        if (source.has("match_text")) {
            matchType = source.getString("match_text");
            if (InternalAgent.isEmpty(matchType)) {
                matchType = null;
            }
        }
        final JSONArray pathDesc = source.getJSONArray("path");
        final List<Pathfinder.PathElement> path = readPath(pathDesc, mResourceIds);

        if (path.size() == 0) {
            throw new InapplicableInstructionsException("event '" + eventID + "' will not " +
                    "be bound to any element in the UI.");
        }

        if ("click".equals(eventType)) {
            return new BaseViewVisitor.AddAccessibilityEventVisitor(
                    path,
                    AccessibilityEvent.TYPE_VIEW_CLICKED,
                    eventID,
                    matchType,
                    listener
            );
        } else if ("selected".equals(eventType)) {
            return new BaseViewVisitor.AddAccessibilityEventVisitor(
                    path,
                    AccessibilityEvent.TYPE_VIEW_SELECTED,
                    eventID,
                    matchType,
                    listener
            );
        } else if ("text_changed".equals(eventType)) {
            return new BaseViewVisitor.AddTextChangeListener(path, eventID, matchType,
                    listener);
        } else if ("detected".equals(eventType)) {
            return new BaseViewVisitor.ViewDetectorVisitor(path, eventID, matchType, listener);
        } else {
            throw new BadInstructionsException("can't track event type \"" +
                    eventType + "\"");
        }
    } catch (final JSONException e) {
        throw new BadInstructionsException("Can't interpret instructions due to " +
                "JSONException", e);
    }
}
 
Example 9
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 10
Source File: AccessibilityEventProcessor.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether the device should drop this event. Caches notifications if necessary.
 *
 * @param event The current event.
 * @return {@code true} if the event should be dropped.
 */
private boolean shouldDropEvent(AccessibilityEvent event) {
  // Always drop null events.
  if (event == null) {
    return true;
  }

  // Always drop events if the service is suspended.
  if (!TalkBackService.isServiceActive()) {
    return true;
  }

  // If touch exploration is enabled, drop automatically generated events
  // that are sent immediately after a window state change... unless we
  // decide to keep the event.
  if (AccessibilityManagerCompat.isTouchExplorationEnabled(accessibilityManager)
      && ((event.getEventType() & AUTOMATIC_AFTER_STATE_CHANGE) != 0)
      && ((event.getEventTime() - lastWindowStateChanged) < DELAY_AUTO_AFTER_STATE)
      && !shouldKeepAutomaticEvent(event)) {
    LogUtils.v(TAG, "Drop event after window state change");
    return true;
  }

  // Some view-selected events are spurious if sent immediately after a focused event.
  if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED
      && !shouldKeepViewSelectedEvent(event)) {
    LogUtils.v(TAG, "Drop selected event after focused event");
    return true;
  }

  boolean isPhoneRinging =
      voiceActionMonitor != null
          && voiceActionMonitor.getCurrentCallState() == TelephonyManager.CALL_STATE_RINGING;

  // Sometimes the dialer's window-state-changed event gets sent right before the
  // TelephonyManager transitions to CALL_STATE_RINGING, so we need to check isDialerEvent().
  isPhoneRinging |= isDialerEvent(event);

  if (ringerModeAndScreenMonitor != null
      && !ringerModeAndScreenMonitor.isScreenOn()
      && !isPhoneRinging) {
    boolean isNotification = AccessibilityEventUtils.isNotificationEvent(event);
    if (!speakWhenScreenOff) {
      // If the user doesn't allow speech when the screen is
      // off, drop the event immediately.
      LogUtils.v(TAG, "Drop event due to screen state and user pref");
      return true;
    } else if (!isNotification) {
      // If the user allows speech when the screen is off, drop
      // all non-notification events.
      LogUtils.v(TAG, "Drop non-notification event due to screen state");
      return true;
    }
  }

  final boolean canInterruptRadialMenu =
      AccessibilityEventUtils.eventMatchesAnyType(event, MASK_EVENT_TYPES_INTERRUPT_RADIAL_MENU);
  final boolean silencedByRadialMenu =
      (service.getMenuManager().isMenuShowing() && !canInterruptRadialMenu);

  // Don't speak events that cannot interrupt the radial menu, if showing
  if (silencedByRadialMenu) {
    LogUtils.v(TAG, "Drop event due to radial menu state");
    return true;
  }

  final int touchscreenState = service.getResources().getConfiguration().touchscreen;
  final boolean isTouchInteractionStateChange =
      AccessibilityEventUtils.eventMatchesAnyType(event, MASK_EVENT_TYPES_TOUCH_STATE_CHANGES);

  // Drop all events related to touch interaction state on devices that don't support touch.
  return (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange;
}