/**
   * Sends the specified text to the {@link AccessibilityManager} to be spoken.
   *
   * @param view The source view.
   * @param text The text to speak.
   */
  public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
      Log.e(TAG, "Attempted to speak when accessibility was disabled!");
      return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
      event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
      Log.e(TAG, "Failed to obtain ViewParent in announceForAccessibility");
      return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
  }
Example #2
0
  public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    event.setClassName(getClass().getName());
    event.setPackageName(mContext.getPackageName());

    LayoutParams params = getWindow().getAttributes();
    boolean isFullScreen =
        (params.width == LayoutParams.MATCH_PARENT) && (params.height == LayoutParams.MATCH_PARENT);
    event.setFullScreen(isFullScreen);

    return false;
  }
Example #3
0
 private static void sendDirectAccessibilityEvent(int eventType, JSONObject message) {
   final AccessibilityEvent accEvent = AccessibilityEvent.obtain(eventType);
   accEvent.setClassName(GeckoAccessibility.class.getName());
   accEvent.setPackageName(GeckoAppShell.getContext().getPackageName());
   populateEventFromJSON(accEvent, message);
   AccessibilityManager accessibilityManager =
       (AccessibilityManager)
           GeckoAppShell.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
   try {
     accessibilityManager.sendAccessibilityEvent(accEvent);
   } catch (IllegalStateException e) {
     // Accessibility is off.
   }
 }
 @Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
   if (Build.VERSION.SDK_INT >= 14) {
     if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
       // Action mode started
       event.setSource(this);
       event.setClassName(getClass().getName());
       event.setPackageName(getContext().getPackageName());
       event.setContentDescription(mTitle);
     } else {
       super.onInitializeAccessibilityEvent(event);
     }
   }
 }
Example #5
0
 private void trySendAccessibilityEvent() {
   AccessibilityManager accessibilityManager =
       AccessibilityManager.getInstance(mView.getContext());
   if (!accessibilityManager.isEnabled()) {
     return;
   }
   // treat toasts as notifications since they are used to
   // announce a transient piece of information to the user
   AccessibilityEvent event =
       AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
   event.setClassName(getClass().getName());
   event.setPackageName(mView.getContext().getPackageName());
   mView.dispatchPopulateAccessibilityEvent(event);
   accessibilityManager.sendAccessibilityEvent(event);
 }
 private AccessibilityEvent createEventForChild(int i, int j) {
   AccessibilityEvent accessibilityevent = AccessibilityEvent.obtain(j);
   accessibilityevent.setEnabled(true);
   accessibilityevent.setClassName(DEFAULT_CLASS_NAME);
   onPopulateEventForVirtualView(i, accessibilityevent);
   if (accessibilityevent.getText().isEmpty()
       && accessibilityevent.getContentDescription() == null) {
     throw new RuntimeException(
         "Callbacks must add text or a content description in populateEventForVirtualViewId()");
   } else {
     accessibilityevent.setPackageName(mView.getContext().getPackageName());
     AccessibilityEventCompat.asRecord(accessibilityevent).setSource(mView, i);
     return accessibilityevent;
   }
 }
  private void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
    AccessibilityManager manager = AccessibilityManager.getInstance(mContext);
    if (!manager.isEnabled()) {
      return;
    }

    AccessibilityEvent event =
        AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
    event.setPackageName(packageName);
    event.setClassName(Notification.class.getName());
    event.setParcelableData(notification);
    CharSequence tickerText = notification.tickerText;
    if (!TextUtils.isEmpty(tickerText)) {
      event.getText().add(tickerText);
    }

    manager.sendAccessibilityEvent(event);
  }
 public static void a(Snackbar paramSnackbar)
 {
   String str = b.getText().toString().trim();
   if (!TextUtils.isEmpty(str))
   {
     Context localContext = paramSnackbar.getContext();
     AccessibilityManager localAccessibilityManager = (AccessibilityManager)localContext.getSystemService("accessibility");
     if (localAccessibilityManager.isEnabled())
     {
       AccessibilityEvent localAccessibilityEvent = AccessibilityEvent.obtain(32);
       localAccessibilityEvent.setClassName(Snackbar.class.getName());
       localAccessibilityEvent.setPackageName(localContext.getPackageName());
       localAccessibilityEvent.getText().add(str);
       localAccessibilityEvent.setEnabled(true);
       paramSnackbar = c.getText().toString().trim();
       if (!TextUtils.isEmpty(paramSnackbar)) {
         localAccessibilityEvent.getText().add(paramSnackbar);
       }
       localAccessibilityManager.sendAccessibilityEvent(localAccessibilityEvent);
     }
   }
 }
  private AccessibilityEvent getEventForItem(T item, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final int virtualDescendantId = getIdForItem(item);

    // Ensure the client has good defaults.
    event.setEnabled(true);

    // Allow the client to populate the event.
    populateEventForItem(item, event);

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
      throw new RuntimeException(
          "You must add text or a content description in populateEventForItem()");
    }

    // Don't allow the client to override these properties.
    event.setClassName(item.getClass().getName());
    event.setPackageName(mParentView.getContext().getPackageName());
    record.setSource(mParentView, virtualDescendantId);

    return event;
  }