Exemple #1
0
    public void run() {
      synchronized (mAccessibilityLock) {
        if (mCodeMatcher == null) {
          mCodeMatcher = mControlCodes.matcher(mAccessibilityBuffer);
        } else {
          mCodeMatcher.reset(mAccessibilityBuffer);
        }

        // Strip all control codes out.
        mAccessibilityBuffer = new StringBuffer(mCodeMatcher.replaceAll(" "));

        // Apply Backspaces using backspace character sequence
        int i = mAccessibilityBuffer.indexOf(BACKSPACE_CODE);
        while (i != -1) {
          mAccessibilityBuffer =
              mAccessibilityBuffer.replace(i == 0 ? 0 : i - 1, i + BACKSPACE_CODE.length(), "");
          i = mAccessibilityBuffer.indexOf(BACKSPACE_CODE);
        }

        if (mAccessibilityBuffer.length() > 0) {
          AccessibilityEvent event =
              AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
          event.setFromIndex(0);
          event.setAddedCount(mAccessibilityBuffer.length());
          event.getText().add(mAccessibilityBuffer);

          sendAccessibilityEventUnchecked(event);
          mAccessibilityBuffer.setLength(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));
    }
  }