Example usage for android.support.v4.view.accessibility AccessibilityRecordCompat getScrollY

List of usage examples for android.support.v4.view.accessibility AccessibilityRecordCompat getScrollY

Introduction

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

Prototype

public int getScrollY() 

Source Link

Document

Gets the scroll offset of the source top edge in pixels.

Usage

From source file:com.google.android.marvin.mytalkback.formatter.ScrollFormatter.java

/**
 * Returns a floating point value representing the scroll position of an
 * {@link AccessibilityEvent}. This value may be outside the range {0..1}.
 * If there's no valid way to obtain a position, this method returns 0.5.
 *
 * @param event The event from which to obtain the scroll position.
 * @return A floating point value representing the scroll position.
 */// w  w w  .  j  av  a2  s . c om
private float getScrollPosition(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final int itemCount = event.getItemCount();
    final int fromIndex = event.getFromIndex();

    // First, attempt to use (fromIndex / itemCount).
    if ((fromIndex >= 0) && (itemCount > 0)) {
        return (fromIndex / (float) itemCount);
    }

    final int scrollY = record.getScrollY();
    final int maxScrollY = record.getMaxScrollY();

    // Next, attempt to use (scrollY / maxScrollY). This will fail if the
    // getMaxScrollX() method is not available.
    if ((scrollY >= 0) && (maxScrollY > 0)) {
        return (scrollY / (float) maxScrollY);
    }

    // Finally, attempt to use (scrollY / itemCount).
    // TODO(alanv): Hack from previous versions -- is it still needed?
    if ((scrollY >= 0) && (itemCount > 0) && (scrollY <= itemCount)) {
        return (scrollY / (float) itemCount);
    }

    return 0.5f;
}

From source file:com.android.screenspeak.formatter.ScrollFormatter.java

/**
 * Returns a floating point value representing the scroll position of an
 * {@link AccessibilityEvent}. This value may be outside the range {0..1}.
 * If there's no valid way to obtain a position, this method returns 0.5.
 *
 * @param event The event from which to obtain the scroll position.
 * @return A floating point value representing the scroll position.
 *///w w w  .ja v a  2 s . c  o  m
private float getScrollPosition(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    final int itemCount = event.getItemCount();
    final int fromIndex = event.getFromIndex();

    // First, attempt to use (fromIndex / itemCount).
    if ((fromIndex >= 0) && (itemCount > 0)) {
        return (fromIndex / (float) itemCount);
    }

    final int scrollY = record.getScrollY();
    final int maxScrollY = record.getMaxScrollY();

    // Next, attempt to use (scrollY / maxScrollY). This will fail if the
    // getMaxScrollX() method is not available.
    if ((scrollY >= 0) && (maxScrollY > 0)) {
        return (scrollY / (float) maxScrollY);
    }

    // Finally, attempt to use (scrollY / itemCount).
    // TODO(AV): Hack from previous versions -- is it still needed?
    if ((scrollY >= 0) && (itemCount > 0) && (scrollY <= itemCount)) {
        return (scrollY / (float) itemCount);
    }

    return 0.5f;
}

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

/**
 * Returns a floating point value representing the scroll position of an
 * {@link AccessibilityEvent}. This value may be outside the range {0..1}.
 * If there's no valid way to obtain a position, this method returns 0.5.
 *
 * @param event The event from which to obtain the scroll position.
 * @return A floating point value representing the scroll position.
 *///from   ww w  . j  a  v a  2 s. c  om
private float getScrollPosition(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    final int itemCount = event.getItemCount();
    final int fromIndex = event.getFromIndex();

    // First, attempt to use (fromIndex / itemCount).
    if ((fromIndex >= 0) && (itemCount > 0)) {
        return (fromIndex / (float) itemCount);
    }

    final int scrollY = record.getScrollY();
    final int maxScrollY = record.getMaxScrollY();

    // Next, attempt to use (scrollY / maxScrollY). This will fail if the
    // getMaxScrollX() method is not available.
    if ((scrollY >= 0) && (maxScrollY > 0)) {
        return (scrollY / (float) maxScrollY);
    }

    // Finally, attempt to use (scrollY / itemCount).
    // TODO: Hack from previous versions -- is it still needed?
    if ((scrollY >= 0) && (itemCount > 0) && (scrollY <= itemCount)) {
        return (scrollY / (float) itemCount);
    }

    return 0.5f;
}

From source file:com.android.screenspeak.eventprocessor.ProcessorFocusAndSingleTap.java

private void handleViewScrolled(AccessibilityEvent event, AccessibilityRecordCompat record) {
    AccessibilityNodeInfoCompat source = null;

    int movingDirection;
    boolean wasScrollAction = false;
    if (mActionScrolledNode != null) {
        source = record.getSource();//w  ww  .  jav  a  2s  . co m
        if (source == null)
            return;
        if (source.equals(mActionScrolledNode)) {
            movingDirection = getScrollActionDirection(mLastScrollAction);
            wasScrollAction = mLastScrollAction != 0;
            clearScrollAction();
        } else {
            movingDirection = getScrollDirection(event);
        }
    } else {
        movingDirection = getScrollDirection(event);
    }

    followScrollEvent(source, record, movingDirection, wasScrollAction);

    mLastScrollFromIndex = record.getFromIndex();
    mLastScrollToIndex = record.getToIndex();
    mLastScrollX = record.getScrollX();
    mLastScrollY = record.getScrollY();

    tryFocusCachedRecord();
}

From source file:com.android.talkback.eventprocessor.ProcessorFocusAndSingleTap.java

private void handleViewScrolled(AccessibilityEvent event, AccessibilityRecordCompat record) {
    AccessibilityNodeInfoCompat source = null;

    @TraversalStrategy.SearchDirectionOrUnknown
    int direction;
    boolean wasScrollAction;
    if (mActionScrolledNode != null) {
        source = record.getSource();/*  www.ja  va2 s  .  c o m*/
        if (source == null)
            return;
        if (source.equals(mActionScrolledNode)) {
            direction = mLastScrollDirection;
            wasScrollAction = true;
            clearScrollAction();
        } else {
            direction = getScrollDirection(event);
            wasScrollAction = false;
        }
    } else {
        direction = getScrollDirection(event);
        wasScrollAction = false;
    }

    followScrollEvent(source, record, direction, wasScrollAction);

    mLastScrollFromIndex = record.getFromIndex();
    mLastScrollToIndex = record.getToIndex();
    mLastScrollX = record.getScrollX();
    mLastScrollY = record.getScrollY();

    tryFocusCachedRecord();
}

From source file:com.android.screenspeak.formatter.EventSpeechRule.java

/**
 * Returns the value of a given <code>property</code> of an <code>event</code>.
 *
 * @param property The property/* ww  w .  ja  v  a 2s  .c o m*/
 * @param event The event.
 * @return the value.
 */
private Object getPropertyValue(Context context, String property, AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);

    if (property == null) {
        throw new IllegalArgumentException("Unknown property : " + property);
    }

    // TODO(AV): Don't do so many string comparisons here.
    switch (property) {
    case PROPERTY_EVENT_TYPE:
        return event.getEventType();
    case PROPERTY_PACKAGE_NAME:
        return event.getPackageName();
    case PROPERTY_CLASS_NAME:
        return event.getClassName();
    case PROPERTY_CLASS_NAME_STRICT:
        return event.getClassName();
    case PROPERTY_TEXT:
        return AccessibilityEventUtils.getEventAggregateText(event);
    case PROPERTY_BEFORE_TEXT:
        return event.getBeforeText();
    case PROPERTY_CONTENT_DESCRIPTION:
        return event.getContentDescription();
    case PROPERTY_CONTENT_DESCRIPTION_OR_TEXT:
        return AccessibilityEventUtils.getEventTextOrDescription(event);
    case PROPERTY_NODE_DESCRIPTION_OR_FALLBACK:
        return getNodeDescriptionOrFallback(event);
    case PROPERTY_EVENT_TIME:
        return event.getEventTime();
    case PROPERTY_ITEM_COUNT:
        return event.getItemCount();
    case PROPERTY_CURRENT_ITEM_INDEX:
        return event.getCurrentItemIndex();
    case PROPERTY_FROM_INDEX:
        return event.getFromIndex();
    case PROPERTY_TO_INDEX:
        return record.getToIndex();
    case PROPERTY_SCROLLABLE:
        return record.isScrollable();
    case PROPERTY_SCROLL_X:
        return record.getScrollX();
    case PROPERTY_SCROLL_Y:
        return record.getScrollY();
    case PROPERTY_RECORD_COUNT:
        return AccessibilityEventCompat.getRecordCount(event);
    case PROPERTY_CHECKED:
        return event.isChecked();
    case PROPERTY_ENABLED:
        return event.isEnabled();
    case PROPERTY_FULL_SCREEN:
        return event.isFullScreen();
    case PROPERTY_PASSWORD:
        return event.isPassword();
    case PROPERTY_ADDED_COUNT:
        return event.getAddedCount();
    case PROPERTY_REMOVED_COUNT:
        return event.getRemovedCount();
    case PROPERTY_VERSION_CODE:
        return PackageManagerUtils.getVersionCode(context, event.getPackageName());
    case PROPERTY_VERSION_NAME:
        return PackageManagerUtils.getVersionName(context, event.getPackageName());
    case PROPERTY_PLATFORM_RELEASE:
        return Build.VERSION.RELEASE;
    case PROPERTY_PLATFORM_SDK:
        return Build.VERSION.SDK_INT;
    default:
        throw new IllegalArgumentException("Unknown property : " + property);
    }
}

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

/**
 * Returns the value of a given <code>property</code> of an <code>event</code>.
 *
 * @param property The property//from   w  w  w. ja  v a 2s  .  c  o m
 * @param event The event.
 * @return the value.
 */
private Object getPropertyValue(Context context, String property, AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);

    if (property == null) {
        throw new IllegalArgumentException("Unknown property : " + property);
    }

    // TODO: Don't do so many string comparisons here.
    switch (property) {
    case PROPERTY_EVENT_TYPE:
        return event.getEventType();
    case PROPERTY_PACKAGE_NAME:
        return event.getPackageName();
    case PROPERTY_CLASS_NAME:
        return event.getClassName();
    case PROPERTY_CLASS_NAME_STRICT:
        return event.getClassName();
    case PROPERTY_TEXT:
        return AccessibilityEventUtils.getEventAggregateText(event);
    case PROPERTY_BEFORE_TEXT:
        return event.getBeforeText();
    case PROPERTY_CONTENT_DESCRIPTION:
        return event.getContentDescription();
    case PROPERTY_CONTENT_DESCRIPTION_OR_TEXT:
        return AccessibilityEventUtils.getEventTextOrDescription(event);
    case PROPERTY_NODE_DESCRIPTION_OR_FALLBACK:
        return getNodeDescriptionOrFallback(event);
    case PROPERTY_EVENT_TIME:
        return event.getEventTime();
    case PROPERTY_ITEM_COUNT:
        return event.getItemCount();
    case PROPERTY_CURRENT_ITEM_INDEX:
        return event.getCurrentItemIndex();
    case PROPERTY_FROM_INDEX:
        return event.getFromIndex();
    case PROPERTY_TO_INDEX:
        return record.getToIndex();
    case PROPERTY_SCROLLABLE:
        return record.isScrollable();
    case PROPERTY_SCROLL_X:
        return record.getScrollX();
    case PROPERTY_SCROLL_Y:
        return record.getScrollY();
    case PROPERTY_RECORD_COUNT:
        return AccessibilityEventCompat.getRecordCount(event);
    case PROPERTY_CHECKED:
        return event.isChecked();
    case PROPERTY_ENABLED:
        return event.isEnabled();
    case PROPERTY_FULL_SCREEN:
        return event.isFullScreen();
    case PROPERTY_PASSWORD:
        return event.isPassword();
    case PROPERTY_ADDED_COUNT:
        return event.getAddedCount();
    case PROPERTY_REMOVED_COUNT:
        return event.getRemovedCount();
    case PROPERTY_VERSION_CODE:
        return PackageManagerUtils.getVersionCode(context, event.getPackageName());
    case PROPERTY_VERSION_NAME:
        return PackageManagerUtils.getVersionName(context, event.getPackageName());
    case PROPERTY_PLATFORM_RELEASE:
        return Build.VERSION.RELEASE;
    case PROPERTY_PLATFORM_SDK:
        return Build.VERSION.SDK_INT;
    default:
        throw new IllegalArgumentException("Unknown property : " + property);
    }
}

From source file:com.google.android.marvin.mytalkback.formatter.EventSpeechRule.java

/**
 * Returns the value of a given <code>property</code> of an <code>event</code>.
 *
 * @param property The property/*from  ww w  . j a  v a 2 s.  c  o  m*/
 * @param event The event.
 * @return the value.
 */
private Object getPropertyValue(Context context, String property, AccessibilityEvent event) {
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);

    // TODO(alanv): Don't do so many string comparisons here.
    if (PROPERTY_EVENT_TYPE.equals(property)) {
        return event.getEventType();
    } else if (PROPERTY_PACKAGE_NAME.equals(property)) {
        return event.getPackageName();
    } else if (PROPERTY_CLASS_NAME.equals(property)) {
        return event.getClassName();
    } else if (PROPERTY_CLASS_NAME_STRICT.equals(property)) {
        return event.getClassName();
    } else if (PROPERTY_TEXT.equals(property)) {
        return AccessibilityEventUtils.getEventAggregateText(event);
    } else if (PROPERTY_BEFORE_TEXT.equals(property)) {
        return event.getBeforeText();
    } else if (PROPERTY_CONTENT_DESCRIPTION.equals(property)) {
        return event.getContentDescription();
    } else if (PROPERTY_CONTENT_DESCRIPTION_OR_TEXT.equals(property)) {
        return AccessibilityEventUtils.getEventTextOrDescription(event);
    } else if (PROPERTY_NODE_DESCRIPTION_OR_FALLBACK.equals(property)) {
        return getNodeDescriptionOrFallback(event);
    } else if (PROPERTY_EVENT_TIME.equals(property)) {
        return event.getEventTime();
    } else if (PROPERTY_ITEM_COUNT.equals(property)) {
        return event.getItemCount();
    } else if (PROPERTY_CURRENT_ITEM_INDEX.equals(property)) {
        return event.getCurrentItemIndex();
    } else if (PROPERTY_FROM_INDEX.equals(property)) {
        return event.getFromIndex();
    } else if (PROPERTY_TO_INDEX.equals(property)) {
        return record.getToIndex();
    } else if (PROPERTY_SCROLLABLE.equals(property)) {
        return record.isScrollable();
    } else if (PROPERTY_SCROLL_X.equals(property)) {
        return record.getScrollX();
    } else if (PROPERTY_SCROLL_Y.equals(property)) {
        return record.getScrollY();
    } else if (PROPERTY_RECORD_COUNT.equals(property)) {
        return AccessibilityEventCompat.getRecordCount(event);
    } else if (PROPERTY_CHECKED.equals(property)) {
        return event.isChecked();
    } else if (PROPERTY_ENABLED.equals(property)) {
        return event.isEnabled();
    } else if (PROPERTY_FULL_SCREEN.equals(property)) {
        return event.isFullScreen();
    } else if (PROPERTY_PASSWORD.equals(property)) {
        return event.isPassword();
    } else if (PROPERTY_ADDED_COUNT.equals(property)) {
        return event.getAddedCount();
    } else if (PROPERTY_REMOVED_COUNT.equals(property)) {
        return event.getRemovedCount();
    } else if (PROPERTY_VERSION_CODE.equals(property)) {
        return PackageManagerUtils.getVersionCode(context, event.getPackageName());
    } else if (PROPERTY_VERSION_NAME.equals(property)) {
        return PackageManagerUtils.getVersionName(context, event.getPackageName());
    } else if (PROPERTY_PLATFORM_RELEASE.equals(property)) {
        return Build.VERSION.RELEASE;
    } else if (PROPERTY_PLATFORM_SDK.equals(property)) {
        return Build.VERSION.SDK_INT;
    } else {
        throw new IllegalArgumentException("Unknown property : " + property);
    }
}