Java Code Examples for android.view.accessibility.AccessibilityEvent#getRecordCount()

The following examples show how to use android.view.accessibility.AccessibilityEvent#getRecordCount() . 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: peService.java    From styT with Apache License 2.0 6 votes vote down vote up
/**
 * 描述:验证是否现在是在聊天页面,可以进行抢红包处理
 * 作者:卜俊文
 * 邮箱:[email protected]
 * 日期:2017/11/3 上午11:52
 *
 * @param event
 */

public boolean invalidEnvelopeUi(AccessibilityEvent event) {

    //判断类名是否是聊天页面
    if (!QQConstant.QQ_IM_CHAT_ACTIVITY.equals(event.getClassName().toString())) {
        return true;
    }

    //判断页面中的元素是否有点击拆开的文本,有就返回可以进行查询了
    int recordCount = event.getRecordCount();
    if (recordCount > 0) {
        for (int i = 0; i < recordCount; i++) {
            AccessibilityRecord record = event.getRecord(i);
            if (record == null) {
                break;
            }
            List<CharSequence> text = record.getText();
            if (text != null && text.size() > 0 && text.contains(QQConstant.QQ_CLICK_TAKE_APART)) {
                //如果文本中有点击拆开的字眼,就返回可以进行查询了
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: OversecAccessibilityService.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
private void sendScrapeSubtreeMessages(AccessibilityEvent arg0) {
    sendScrapeSubtreeMessage(arg0.getSource(), null);
    int n = arg0.getRecordCount();
    for (int i = 0; i < n; i++) {
        sendScrapeSubtreeMessage(arg0.getRecord(i).getSource(), null);
    }
}
 
Example 3
Source File: OversecAccessibilityService.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
private void sendRefreshNodeMessages(AccessibilityEvent arg0) {
    sendRefreshNodeMessage(arg0.getSource());
    int n = arg0.getRecordCount();
    for (int i = 0; i < n; i++) {
        sendRefreshNodeMessage(arg0.getRecord(i).getSource());
    }
}
 
Example 4
Source File: OversecAccessibilityService.java    From oversec with GNU General Public License v3.0 4 votes vote down vote up
private static String eventToString(AccessibilityEvent ev) {
    StringBuilder builder = new StringBuilder();
    builder.append("EventType: ").append(AccessibilityEvent.eventTypeToString(ev.getEventType()));
    //builder.append("; EventTime: ").append(ev.getEventTime());
    builder.append("; PackageName: ").append(ev.getPackageName());
    builder.append("; ClassName: ").append(ev.getClassName());
    // builder.append("; MovementGranularity: ").append(ev.getMovementGranularity());
    builder.append("; Action: ").append(ev.getAction());
    builder.append("; ContentChangeTypes: ");//.append(ev.getContentChangeTypes());


    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        int cct = 0;
        cct = ev.getContentChangeTypes();
        boolean hasCONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = ((cct & AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION) == AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION);
        boolean hasCONTENT_CHANGE_TYPE_SUBTREE = ((cct & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE);
        boolean hasCONTENT_CHANGE_TYPE_TEXT = ((cct & AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT) == AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT);
        boolean hasCONTENT_CHANGE_TYPE_UNDEFINED = ((cct & AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) == AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);


        if (hasCONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION) {
            builder.append(" DESCRIPTION,");
        }
        if (hasCONTENT_CHANGE_TYPE_SUBTREE) {
            builder.append(" SUBTREE,");
        }
        if (hasCONTENT_CHANGE_TYPE_TEXT) {
            builder.append(" TEXT,");
        }
        if (hasCONTENT_CHANGE_TYPE_UNDEFINED) {
            builder.append(" UNDEFINED,");
        }

        builder.append("\n");
    } else {
        builder.append("[ContentChangeType Not available on SDK " + android.os.Build.VERSION.SDK_INT);
    }

    builder.append("  Record X:");
    builder.append(recordToString(ev));
    if (true) {
        builder.append("\n");
        //builder.append("; sourceWindowId: ").append(mSourceWindowId);
        //if (mSourceNode != null) {
        //    builder.append("; mSourceNodeId: ").append(mSourceNode.getSourceNodeId());
        //}
        for (int i = 0; i < ev.getRecordCount(); i++) {
            final AccessibilityRecord record = ev.getRecord(i);
            builder.append("  Record ");
            builder.append(i);
            builder.append(":");
            builder.append(recordToString(record));

            builder.append("\n");
        }
    } else {
        builder.append("; recordCount: ").append(ev.getRecordCount());
    }
    return builder.toString();
}
 
Example 5
Source File: AccessibilityEventCompatIcs.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static int getRecordCount(AccessibilityEvent event) {
    return event.getRecordCount();
}
 
Example 6
Source File: AccessibilityEventCompatIcs.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static int getRecordCount(AccessibilityEvent event) {
    return event.getRecordCount();
}
 
Example 7
Source File: AccessibilityEventCompatIcs.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static int getRecordCount(AccessibilityEvent event) {
    return event.getRecordCount();
}
 
Example 8
Source File: AccessibilityEventCompatIcs.java    From guideshow with MIT License 4 votes vote down vote up
public static int getRecordCount(AccessibilityEvent event) {
    return event.getRecordCount();
}
 
Example 9
Source File: TaskBackService.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Processes an AccessibilityEvent, by traversing the View's tree and
 * putting together a message to speak to the user.
 */
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (!mTextToSpeechInitialized) {
        Log.e(LOG_TAG, "Text-To-Speech engine not ready.  Bailing out.");
        return;
    }

    // This AccessibilityNodeInfo represents the view that fired the
    // AccessibilityEvent. The following code will use it to traverse the
    // view hierarchy, using this node as a starting point.
    //
    // NOTE: Every method that returns an AccessibilityNodeInfo may return null,
    // because the explored window is in another process and the
    // corresponding View might be gone by the time your request reaches the
    // view hierarchy.
    AccessibilityNodeInfo source = event.getSource();
    if (source == null) {
        return;
    }

    // Grab the parent of the view that fired the event.
    AccessibilityNodeInfo rowNode = getListItemNodeInfo(source);
    if (rowNode == null) {
        return;
    }

    // Using this parent, get references to both child nodes, the label and the checkbox.
    AccessibilityNodeInfo labelNode = rowNode.getChild(0);
    if (labelNode == null) {
        rowNode.recycle();
        return;
    }

    AccessibilityNodeInfo completeNode = rowNode.getChild(1);
    if (completeNode == null) {
        rowNode.recycle();
        return;
    }

    // Determine what the task is and whether or not it's complete, based on
    // the text inside the label, and the state of the check-box.
    if (rowNode.getChildCount() < 2 || !rowNode.getChild(1).isCheckable()) {
        rowNode.recycle();
        return;
    }

    CharSequence taskLabel = labelNode.getText();
    final boolean isComplete = completeNode.isChecked();

    String completeStr = null;
    if (isComplete) {
        completeStr = getString(R.string.task_complete);
    } else {
        completeStr = getString(R.string.task_not_complete);
    }

    String taskStr = getString(R.string.task_complete_template, taskLabel, completeStr);
    StringBuilder utterance = new StringBuilder(taskStr);

    // The custom ListView added extra context to the event by adding an
    // AccessibilityRecord to it. Extract that from the event and read it.
    final int records = event.getRecordCount();
    for (int i = 0; i < records; i++) {
        AccessibilityRecord record = event.getRecord(i);
        CharSequence contentDescription = record.getContentDescription();
        if (!TextUtils.isEmpty(contentDescription )) {
            utterance.append(SEPARATOR);
            utterance.append(contentDescription);
        }
    }

    // Announce the utterance.
    mTts.speak(utterance.toString(), TextToSpeech.QUEUE_FLUSH, null);
    Log.d(LOG_TAG, utterance.toString());
}