@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. CarouselAdapter 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 CarouselAdapter 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;
  }
  private static void populateEventFromJSON(AccessibilityEvent event, JSONObject message) {
    final JSONArray textArray = message.optJSONArray("text");
    if (textArray != null) {
      for (int i = 0; i < textArray.length(); i++) event.getText().add(textArray.optString(i));
    }

    event.setContentDescription(message.optString("description"));
    event.setEnabled(message.optBoolean("enabled", true));
    event.setChecked(message.optBoolean("checked"));
    event.setPassword(message.optBoolean("password"));
    event.setAddedCount(message.optInt("addedCount", -1));
    event.setRemovedCount(message.optInt("removedCount", -1));
    event.setFromIndex(message.optInt("fromIndex", -1));
    event.setItemCount(message.optInt("itemCount", -1));
    event.setCurrentItemIndex(message.optInt("currentItemIndex", -1));
    event.setBeforeText(message.optString("beforeText"));
    if (Versions.feature14Plus) {
      event.setToIndex(message.optInt("toIndex", -1));
      event.setScrollable(message.optBoolean("scrollable"));
      event.setScrollX(message.optInt("scrollX", -1));
      event.setScrollY(message.optInt("scrollY", -1));
    }
    if (Versions.feature15Plus) {
      event.setMaxScrollX(message.optInt("maxScrollX", -1));
      event.setMaxScrollY(message.optInt("maxScrollY", -1));
    }
  }
  /**
   * 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);
  }
 @Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
   super.onInitializeAccessibilityEvent(event);
   event.setScrollable(isScrollableForAccessibility());
   View selectedView = getSelectedView();
   if (selectedView != null) {
     event.setEnabled(selectedView.isEnabled());
   }
   event.setCurrentItemIndex(getSelectedItemPosition());
   event.setFromIndex(getFirstVisiblePosition());
   event.setToIndex(getLastVisiblePosition());
   event.setItemCount(getCount());
 }
 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;
   }
 }
 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;
  }