Java Code Examples for androidx.core.view.accessibility.AccessibilityEventCompat#TYPE_VIEW_SCROLLED

The following examples show how to use androidx.core.view.accessibility.AccessibilityEventCompat#TYPE_VIEW_SCROLLED . 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: SliderPager.java    From Android-Image-Slider with Apache License 2.0 6 votes vote down vote up
@SuppressLint("WrongConstant")
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    // Dispatch scroll events from this SliderPager.
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED) {
        return super.dispatchPopulateAccessibilityEvent(event);
    }

    // Dispatch all other accessibility events from the current page.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            final ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem
                    && child.dispatchPopulateAccessibilityEvent(event)) {
                return true;
            }
        }
    }

    return false;
}
 
Example 2
Source File: CustomViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    // Dispatch scroll events from this ViewPager.
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED) {
        return super.dispatchPopulateAccessibilityEvent(event);
    }

    // Dispatch all other accessibility events from the current page.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            final ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem
                    && child.dispatchPopulateAccessibilityEvent(event)) {
                return true;
            }
        }
    }

    return false;
}
 
Example 3
Source File: CustomViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(host, event);
    event.setClassName(CustomViewPager.class.getName());
    final AccessibilityRecordCompat recordCompat =
            AccessibilityEventCompat.asRecord(event);
    recordCompat.setScrollable(canScroll());
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED
            && mAdapter != null) {
        recordCompat.setItemCount(mAdapter.getCount());
        recordCompat.setFromIndex(mCurItem);
        recordCompat.setToIndex(mCurItem);
    }
}
 
Example 4
Source File: ScrollFeedbackManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
private boolean shouldIgnoreEvent(AccessibilityEvent event) {
  switch (event.getEventType()) {
    case AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
    case AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED:
      return true;
    case AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED:
    case AccessibilityEventCompat.TYPE_VIEW_SCROLLED:
      return shouldIgnoreWindowContentChangedOrViewScrolledEvent(event);
    default:
      return false;
  }
}
 
Example 5
Source File: ScrollFeedbackManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the event is a duplicate of the previous event, or the event is triggered by
 * auto-scroll.
 *
 * @param event The event from which information about the scroll position will be retrieved
 * @return {@code true} if the event is a duplicate of the previous event, or triggered by
 *     auto-scroll
 */
protected boolean isDuplicateScrollEventOrAutoScroll(AccessibilityEvent event) {
  int eventType = event.getEventType();
  if ((eventType != AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED)
      && (eventType != AccessibilityEventCompat.TYPE_VIEW_SCROLLED)) {
    return false;
  }

  final int fromIndex = event.getFromIndex() + 1;
  final int itemCount = event.getItemCount();
  if (itemCount <= 0 || fromIndex <= 0) {
    return true;
  }

  EventId eventId;
  try {
    eventId = new EventId(event);
  } catch (Exception e) {
    return true;
  }

  final Integer cachedFromIndex = cachedFromValues.get(eventId);
  final Integer cachedItemCount = cachedItemCounts.get(eventId);

  if ((cachedFromIndex != null)
      && (cachedFromIndex == fromIndex)
      && (cachedItemCount != null)
      && (cachedItemCount == itemCount)) {
    // The from index hasn't changed, which means the event is coming
    // from a re-layout or resize and should not be spoken.
    return true;
  }

  // The behavior of put() for an existing key is unspecified, so we can't
  // recycle the old or new key nodes.
  cachedFromValues.put(eventId, fromIndex);
  cachedItemCounts.put(eventId, itemCount);

  return false;
}