示例#1
0
  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));
    }
  }
 @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());
 }