Example usage for android.view.accessibility AccessibilityNodeInfo getText

List of usage examples for android.view.accessibility AccessibilityNodeInfo getText

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityNodeInfo getText.

Prototype

public CharSequence getText() 

Source Link

Document

Gets the text of this node.

Usage

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void toSignIn() {
    AccessibilityNodeInfo mAccessibilityNodeInfo = this.getRootInActiveWindow();
    if (mAccessibilityNodeInfo == null)
        return;//from ww w .  j a  va  2 s  .c om
    List<AccessibilityNodeInfo> mEdPhoneNodes = mAccessibilityNodeInfo
            .findAccessibilityNodeInfosByViewId(PHONE_ID);
    if (mEdPhoneNodes == null || mEdPhoneNodes.isEmpty())
        return;
    isChecking = true;
    AccessibilityNodeInfo mEdPhoneNode = mEdPhoneNodes.get(0);
    CharSequence mCharSequence = mEdPhoneNode.getText();

    if (mCharSequence != null && !mCharSequence.toString().equals(targetCheckInAcount.getAccount())) {
        mEdPhoneNode.performAction(AccessibilityNodeInfo.ACTION_FOCUS);//?
        Rect mRect = new Rect();
        mEdPhoneNode.getBoundsInScreen(mRect);
        doShellCmdInputTap(mRect.right - 10, mRect.centerY());
        setTextToView(mEdPhoneNode, "");
        setTextToView(mEdPhoneNode, targetCheckInAcount.getAccount());
    }

    List<AccessibilityNodeInfo> mEdPasswordNodes = mAccessibilityNodeInfo
            .findAccessibilityNodeInfosByViewId(PASSWORD_ID);
    if (mEdPasswordNodes == null)
        return;
    AccessibilityNodeInfo mEdPasswordNode = mEdPasswordNodes.get(0);
    CharSequence mCharSequencePassword = mEdPasswordNode.getText();
    setTextToView(mEdPasswordNode, "");
    setTextToView(mEdPasswordNode, targetCheckInAcount.getPassword());

    /*?*/
    inputClick(BUTTON_ID);
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 * AccessibilityNodeInfo  ?webView //from   ww  w.  ja  v a2 s  . c o m
 *  
 *
 * @param target
 * @param accessibilityNodeInfo
 * @return
 */
private AccessibilityNodeInfo recurseFindByText(String target, AccessibilityNodeInfo accessibilityNodeInfo) {

    if (accessibilityNodeInfo != null && accessibilityNodeInfo.getChildCount() == 0) {
        if ((target.equals(accessibilityNodeInfo.getText())
                || target.equals(accessibilityNodeInfo.getContentDescription())))
            return accessibilityNodeInfo;
        else
            return null;
    } else {
        if (accessibilityNodeInfo == null)
            return null;

        for (int i = 0; i < accessibilityNodeInfo.getChildCount(); i++) {
            AccessibilityNodeInfo child = accessibilityNodeInfo.getChild(i);
            AccessibilityNodeInfo isTaget = recurseFindByText(target, child);
            if (isTaget == null)
                continue;
            else
                return isTaget;
        }
        return null;
    }
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 * AccessibilityNodeInfo  ?webView /*  w  w w  .j  a  va2s  .  c  o  m*/
 * List
 * ? ???target??
 *
 * @param target
 * @param accessibilityNodeInfo
 * @return
 */
private void recurseFindByTextToList(String target, AccessibilityNodeInfo accessibilityNodeInfo,
        @NonNull List<AccessibilityNodeInfo> mInfos) {

    if (accessibilityNodeInfo != null && accessibilityNodeInfo.getChildCount() == 0) {

        if (((accessibilityNodeInfo.getText() != null
                && accessibilityNodeInfo.getText().toString().contains(target))
                || (accessibilityNodeInfo.getContentDescription() != null
                        && accessibilityNodeInfo.getContentDescription().toString().contains(target)))) {
            mInfos.add(accessibilityNodeInfo);
            return;
        } else
            return;
    } else {
        if (accessibilityNodeInfo == null)
            return;

        for (int i = 0; i < accessibilityNodeInfo.getChildCount(); i++) {
            AccessibilityNodeInfo child = accessibilityNodeInfo.getChild(i);
            recurseFindByTextToList(target, child, mInfos);
        }
        return;
    }
}

From source file:lewa.support.v7.widget.SwitchCompat.java

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    if (Build.VERSION.SDK_INT >= 14) {
        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(SwitchCompat.class.getName());
        CharSequence switchText = isChecked() ? mTextOn : mTextOff;
        if (!TextUtils.isEmpty(switchText)) {
            CharSequence oldText = info.getText();
            if (TextUtils.isEmpty(oldText)) {
                info.setText(switchText);
            } else {
                StringBuilder newText = new StringBuilder();
                newText.append(oldText).append(' ').append(switchText);
                info.setText(newText);/* ww w  .  j a v a2  s .  c o m*/
            }
        }
    }
}

From source file:android.support.v7.widget.SwitchCompat.java

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    if (Build.VERSION.SDK_INT >= 14) {
        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME);
        CharSequence switchText = isChecked() ? mTextOn : mTextOff;
        if (!TextUtils.isEmpty(switchText)) {
            CharSequence oldText = info.getText();
            if (TextUtils.isEmpty(oldText)) {
                info.setText(switchText);
            } else {
                StringBuilder newText = new StringBuilder();
                newText.append(oldText).append(' ').append(switchText);
                info.setText(newText);//from  w w  w.  ja v a  2s  .  c  o  m
            }
        }
    }
}

From source file:org.mariotaku.multivalueswitch.library.MultiValueSwitch.java

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME);
        CharSequence switchText = getEntry(getCheckedPosition());
        if (!TextUtils.isEmpty(switchText)) {
            CharSequence oldText = info.getText();
            if (TextUtils.isEmpty(oldText)) {
                info.setText(switchText);
            } else {
                StringBuilder newText = new StringBuilder();
                newText.append(oldText).append(' ').append(switchText);
                info.setText(newText);//from  w  ww. j av  a 2  s  .  c  o  m
            }
        }
    }
}

From source file:com.google.android.apps.common.testing.accessibility.framework.uielement.ViewHierarchyElement.java

ViewHierarchyElement(int id, @Nullable ViewHierarchyElement parent, AccessibilityNodeInfo fromInfo) {
    // Bookkeeping
    this.id = id;
    this.parentId = (parent != null) ? parent.getId() : null;

    // API 18+ properties
    this.resourceName = AT_18 ? fromInfo.getViewIdResourceName() : null;
    this.editable = AT_18 ? fromInfo.isEditable() : null;

    // API 16+ properties
    this.visibleToUser = AT_16 ? fromInfo.isVisibleToUser() : null;

    // Base properties
    this.className = fromInfo.getClassName();
    this.packageName = fromInfo.getPackageName();
    this.accessibilityClassName = fromInfo.getClassName();
    this.contentDescription = SpannableString.valueOf(fromInfo.getContentDescription());
    this.text = SpannableString.valueOf(fromInfo.getText());
    this.importantForAccessibility = true;
    this.clickable = fromInfo.isClickable();
    this.longClickable = fromInfo.isLongClickable();
    this.focusable = fromInfo.isFocusable();
    this.scrollable = fromInfo.isScrollable();
    this.canScrollForward = ((fromInfo.getActions() & AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) != 0);
    this.canScrollBackward = ((fromInfo.getActions() & AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) != 0);
    this.checkable = fromInfo.isCheckable();
    this.checked = fromInfo.isChecked();
    this.hasTouchDelegate = false; /* Touch delegates are not considered by AccessibilityServices */
    android.graphics.Rect tempRect = new android.graphics.Rect();
    fromInfo.getBoundsInScreen(tempRect);
    this.boundsInScreen = new Rect(tempRect);
    this.nonclippedHeight = null; /* AccessibilityServices cannot discover nonclipped dimensions */
    this.nonclippedWidth = null; /* AccessibilityServices cannot discover nonclipped dimensions */
    this.textSize = null;
    this.textColor = null;
    this.backgroundDrawableColor = null;
    this.typefaceStyle = null;
    this.enabled = fromInfo.isEnabled();
}

From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    if (Build.VERSION.SDK_INT >= 14) {
        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(SmoothSwitch.class.getName());
        CharSequence switchText = isChecked() ? mTextOn : mTextOff;
        if (!TextUtils.isEmpty(switchText)) {
            CharSequence oldText = info.getText();
            if (TextUtils.isEmpty(oldText)) {
                info.setText(switchText);
            } else {
                StringBuilder newText = new StringBuilder();
                newText.append(oldText).append(' ').append(switchText);
                info.setText(newText);/* w  w  w  .  j  a  v a 2s .  c om*/
            }
        }
    }
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 *
 *///from w  w  w.j  a  va2 s  .c o m
public void recycle(AccessibilityNodeInfo info, String target, boolean isClickSelft) {
    int temp = 0;
    if (info != null && info.getChildCount() == 0) {
        if (info.getContentDescription() != null && info.getContentDescription().toString().equals(target)
                && isClickSelft) {

            String content = info.getContentDescription().toString();
            info.performAction(AccessibilityNodeInfo.ACTION_CLICK);
            if (content.equals(AFTER_WORK))
                handleIt(info);
            else if (content.equals(GO_TO_WORK))
                handleGoToWork(info);
            return;
        }
        if (info.getText() != null) {
            if (target.equals(info.getText().toString())) {
                if (isClickSelft) {
                    info.performAction(AccessibilityNodeInfo.ACTION_CLICK);
                    return;
                }
                AccessibilityNodeInfo parent = info.getParent();
                while (parent != null) {
                    if (parent.isClickable()) {
                        parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
                        break;
                    }
                    parent = parent.getParent();
                }
            }

        }
    } else {

        for (int i = 0; info != null && i < info.getChildCount(); i++) {
            if (info.getChild(i) != null) {
                temp = i;
                recycle(info.getChild(i), target, isClickSelft);
            }
        }
    }
}