Example usage for android.view View getTouchDelegate

List of usage examples for android.view View getTouchDelegate

Introduction

In this page you can find the example usage for android.view View getTouchDelegate.

Prototype

public TouchDelegate getTouchDelegate() 

Source Link

Document

Gets the TouchDelegate for this View.

Usage

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

/**
 * Determines if the supplied {@link View} has any retrievable listeners that might qualify the
 * view to be important for accessibility purposes.
 * <p>/*from  w  w w. j  av a2s  .co  m*/
 * NOTE: This method tries to behave like the hidden {@code View#hasListenersForAccessibility()}
 * method, but cannot retrieve several of the listeners.
 *
 * @param view The {@link View} to evaluate
 * @return {@code true} if any of the retrievable listeners on {@code view} might qualify it to be
 *         important for accessibility purposes.
 */
private static boolean hasListenersForAccessibility(View view) {
    if (view == null) {
        return false;
    }

    boolean result = false;
    // Ideally, here we check for...
    // TouchDelegate
    result |= view.getTouchDelegate() != null;

    // OnKeyListener, OnTouchListener, OnGenericMotionListener, OnHoverListener, OnDragListener
    // aren't accessible to us.
    return result;
}

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

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

    // API 16+ properties
    this.scrollable = AT_16 ? fromView.isScrollContainer() : null;

    // API 11+ properties
    this.backgroundDrawableColor = (AT_11 && (fromView != null)
            && (fromView.getBackground() instanceof ColorDrawable))
                    ? ((ColorDrawable) fromView.getBackground()).getColor()
                    : null;//from  w  w  w. ja v  a2  s .  c  o m

    // Base properties
    this.visibleToUser = ViewAccessibilityUtils.isVisibleToUser(fromView);
    this.className = fromView.getClass().getName();
    this.accessibilityClassName = null;
    this.packageName = fromView.getContext().getPackageName();
    this.resourceName = (fromView.getId() != View.NO_ID)
            ? ViewAccessibilityUtils.getResourceNameForView(fromView)
            : null;
    this.contentDescription = SpannableString.valueOf(fromView.getContentDescription());
    this.enabled = fromView.isEnabled();
    if (fromView instanceof TextView) {
        TextView textView = (TextView) fromView;
        // Hint text takes precedence if no text is present.
        CharSequence text = textView.getText();
        if (TextUtils.isEmpty(text)) {
            text = textView.getHint();
        }
        this.text = SpannableString.valueOf(text);
        this.textSize = textView.getTextSize();
        this.textColor = textView.getCurrentTextColor();
        this.typefaceStyle = (textView.getTypeface() != null) ? textView.getTypeface().getStyle() : null;
    } else {
        this.text = null;
        this.textSize = null;
        this.textColor = null;
        this.typefaceStyle = null;
    }

    this.importantForAccessibility = ViewAccessibilityUtils.isImportantForAccessibility(fromView);
    this.clickable = fromView.isClickable();
    this.longClickable = fromView.isLongClickable();
    this.focusable = fromView.isFocusable();
    this.editable = ViewAccessibilityUtils.isViewEditable(fromView);
    this.canScrollForward = (ViewCompat.canScrollVertically(fromView, 1)
            || ViewCompat.canScrollHorizontally(fromView, 1));
    this.canScrollBackward = (ViewCompat.canScrollVertically(fromView, -1)
            || ViewCompat.canScrollHorizontally(fromView, -1));
    this.checkable = (fromView instanceof Checkable);
    this.checked = (fromView instanceof Checkable) ? ((Checkable) fromView).isChecked() : null;
    this.hasTouchDelegate = (fromView.getTouchDelegate() != null);

    // There may be subtle differences between the bounds from a View instance compared to that of
    // its AccessibilityNodeInfo. The latter uses a @hide getBoundsOnScreen method, which clips to
    // parent bounds.
    android.graphics.Rect tempRect = new android.graphics.Rect();
    if (fromView.getGlobalVisibleRect(tempRect)) {
        this.boundsInScreen = new Rect(tempRect);
    } else {
        this.boundsInScreen = null;
    }
    this.nonclippedHeight = fromView.getHeight();
    this.nonclippedWidth = fromView.getWidth();
}