Example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat getPackageName

List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat getPackageName

Introduction

In this page you can find the example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat getPackageName.

Prototype

public CharSequence getPackageName() 

Source Link

Document

Gets the package this node comes from.

Usage

From source file:com.google.android.marvin.utils.AutomationUtils.java

/**
 * Returns whether a node matches the class specified by
 * {@code className} and exactly match the text or content description
 * specified by {@code text}.//from  w  ww.ja v  a2s .c  o  m
 */
private static boolean nodeMatchesFilter(Context context, AccessibilityNodeInfoCompat node,
        CharSequence referenceClassName, String findText) {
    final ClassLoadingManager loader = ClassLoadingManager.getInstance();
    final CharSequence nodeClass = node.getClassName();
    final CharSequence nodePackage = node.getPackageName();

    if (!loader.checkInstanceOf(context, nodeClass, nodePackage, referenceClassName)) {
        return false;
    }

    final CharSequence nodeText = node.getText();
    if (TextUtils.equals(findText, nodeText)) {
        return true;
    }

    final CharSequence nodeDesc = node.getContentDescription();
    if (TextUtils.equals(findText, nodeDesc)) {
        return true;
    }

    return false;
}

From source file:com.android.utils.WebInterfaceUtils.java

private static boolean isNodeFromFirefox(AccessibilityNodeInfoCompat node) {
    if (node == null) {
        return false;
    }// w w  w. j  ava  2  s . co m

    final String packageName = node.getPackageName() != null ? node.getPackageName().toString() : "";
    return packageName.startsWith("org.mozilla.");
}

From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java

/**
 * Determines if the generating class of an
 * {@link AccessibilityNodeInfoCompat} matches a given {@link Class} by
 * type.//from   ww w  .  j a  v a 2  s . com
 *
 * @param node A sealed {@link AccessibilityNodeInfoCompat} dispatched by
 *            the accessibility framework.
 * @param referenceClass A {@link Class} to match by type or inherited type.
 * @return {@code true} if the {@link AccessibilityNodeInfoCompat} object
 *         matches the {@link Class} by type or inherited type,
 *         {@code false} otherwise.
 */
public static boolean nodeMatchesClassByType(Context context, AccessibilityNodeInfoCompat node,
        Class<?> referenceClass) {
    if ((node == null) || (referenceClass == null)) {
        return false;
    }

    // Attempt to take a shortcut.
    final CharSequence nodeClassName = node.getClassName();
    if (TextUtils.equals(nodeClassName, referenceClass.getName())) {
        return true;
    }

    final ClassLoadingManager loader = ClassLoadingManager.getInstance();
    final CharSequence appPackage = node.getPackageName();
    return loader.checkInstanceOf(context, nodeClassName, appPackage, referenceClass);
}

From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java

/**
 * Determines if the class of an {@link AccessibilityNodeInfoCompat} matches
 * a given {@link Class} by package and name.
 *
 * @param node A sealed {@link AccessibilityNodeInfoCompat} dispatched by
 *            the accessibility framework.
 * @param referenceClassName A class name to match.
 * @return {@code true} if the {@link AccessibilityNodeInfoCompat} matches
 *         the class name.//from  w w w.  j a v  a 2  s.co  m
 */
public static boolean nodeMatchesClassByName(Context context, AccessibilityNodeInfoCompat node,
        CharSequence referenceClassName) {
    if ((node == null) || (referenceClassName == null)) {
        return false;
    }

    // Attempt to take a shortcut.
    final CharSequence nodeClassName = node.getClassName();
    if (TextUtils.equals(nodeClassName, referenceClassName)) {
        return true;
    }

    final ClassLoadingManager loader = ClassLoadingManager.getInstance();
    final CharSequence appPackage = node.getPackageName();
    return loader.checkInstanceOf(context, nodeClassName, appPackage, referenceClassName);
}

From source file:com.googlecode.eyesfree.utils.ExploreByTouchHelper.java

/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * parent view populated with its virtual descendants.
 *
 * @return An {@link AccessibilityNodeInfoCompat} for the parent view.
 *//*www  .  j  a v  a  2s .c om*/
private AccessibilityNodeInfoCompat getNodeForHost() {
    // Since we don't want the parent to be focusable, but we can't remove
    // actions from a node, copy over the necessary fields.
    final AccessibilityNodeInfoCompat result = AccessibilityNodeInfoCompat.obtain(mHost);
    final AccessibilityNodeInfoCompat source = AccessibilityNodeInfoCompat.obtain(mHost);
    ViewCompat.onInitializeAccessibilityNodeInfo(mHost, source);

    // Copy over parent and screen bounds.
    source.getBoundsInParent(mTempParentRect);
    source.getBoundsInScreen(mTempScreenRect);
    result.setBoundsInParent(mTempParentRect);
    result.setBoundsInScreen(mTempScreenRect);

    // Set up the parent view, if applicable.
    final ViewParent parent = mHost.getParent();
    if (parent instanceof View) {
        result.setParent((View) parent);
    }

    // Populate the minimum required fields.
    result.setVisibleToUser(source.isVisibleToUser());
    result.setPackageName(source.getPackageName());
    result.setClassName(source.getClassName());

    // Add the fake root node.
    result.addChild(mHost, ROOT_ID);

    return result;
}

From source file:com.android.utils.ExploreByTouchHelper.java

/**
 * Constructs and returns an {@link AccessibilityNodeInfoCompat} for the
 * parent view populated with its virtual descendants.
 *
 * @return An {@link AccessibilityNodeInfoCompat} for the parent view.
 *///from w w  w . ja  v a2  s .  co  m
private AccessibilityNodeInfoCompat getNodeForHost() {
    // Since we don't want the parent to be focusable, but we can't remove
    // actions from a node, copy over the necessary fields.
    final AccessibilityNodeInfoCompat result = AccessibilityNodeInfoCompat.obtain(mHost);
    final AccessibilityNodeInfoCompat source = AccessibilityNodeInfoCompat.obtain(mHost);
    ViewCompat.onInitializeAccessibilityNodeInfo(mHost, source);

    // Copy over parent and screen bounds.
    source.getBoundsInParent(mTempParentRect);
    source.getBoundsInScreen(mTempScreenRect);
    result.setBoundsInParent(mTempParentRect);
    result.setBoundsInScreen(mTempScreenRect);

    // Set up the parent view, if applicable.
    final ViewParent parent = ViewCompat.getParentForAccessibility(mHost);
    if (parent instanceof View) {
        result.setParent((View) parent);
    }

    // Populate the minimum required fields.
    result.setVisibleToUser(source.isVisibleToUser());
    result.setPackageName(source.getPackageName());
    result.setClassName(source.getClassName());

    // Add the fake root node.
    result.addChild(mHost, ROOT_ID);

    return result;
}

From source file:com.android.talkback.formatter.TouchExplorationFormatter.java

/**
 * Populates utterance about window transition. We populate this feedback only when user is in
 * split screen mode to avoid verbosity of feedback.
 *///from w  w  w .jav a  2  s .c om
private void addWindowTransition(Utterance utterance, AccessibilityNodeInfoCompat announcedNode) {
    int windowId = announcedNode.getWindowId();
    if (windowId == mLastFocusedWindowId) {
        return;
    }

    int windowType = getWindowType(announcedNode);
    if (windowType != AccessibilityWindowInfoCompat.TYPE_APPLICATION
            && windowType != AccessibilityWindowInfoCompat.TYPE_SYSTEM) {
        return;
    }

    List<AccessibilityWindowInfo> windows = mService.getWindows();
    List<AccessibilityWindowInfo> applicationWindows = new ArrayList<>();
    for (AccessibilityWindowInfo window : windows) {
        if (window.getType() == AccessibilityWindowInfo.TYPE_APPLICATION) {
            if (window.getParent() == null) {
                applicationWindows.add(window);
            }
        }
    }

    // Provide window transition feedback only when user is in split screen mode or navigating
    // with keyboard. We consider user is in split screen mode if there are two none-parented
    // application windows.
    if (applicationWindows.size() != 2
            && mService.getInputModeManager().getInputMode() != InputModeManager.INPUT_MODE_KEYBOARD) {
        return;
    }

    WindowManager windowManager = new WindowManager(mService.isScreenLayoutRTL());
    windowManager.setWindows(windows);

    CharSequence title = null;
    if (!applicationWindows.isEmpty() && windowManager.isStatusBar(windowId)) {
        title = mService.getString(R.string.status_bar);
    } else if (!applicationWindows.isEmpty() && windowManager.isNavigationBar(windowId)) {
        title = mService.getString(R.string.navigation_bar);
    } else {
        title = mWindowTitlesMap.get(windowId);

        if (title == null && BuildCompat.isAtLeastN()) {
            for (AccessibilityWindowInfo window : windows) {
                if (window.getId() == windowId) {
                    title = window.getTitle();
                    break;
                }
            }
        }

        if (title == null) {
            title = mService.getApplicationLabel(announcedNode.getPackageName());
        }
    }

    int templateId = windowType == AccessibilityWindowInfo.TYPE_APPLICATION
            ? R.string.template_window_switch_application
            : R.string.template_window_switch_system;
    utterance.addSpoken(
            mService.getString(templateId, WindowManager.formatWindowTitleForFeedback(title, mService)));
}