List of usage examples for android.support.v4.view.accessibility AccessibilityRecordCompat getFromIndex
public int getFromIndex()
From source file:com.google.android.marvin.mytalkback.ProcessorFocusAndSingleTap.java
/** * Attempts to place focus on the {@code event}'s selected item. *//* w ww .j a va 2 s.co m*/ private boolean setFocusFromViewSelected(AccessibilityEvent event, AccessibilityRecordCompat record) { AccessibilityNodeInfoCompat source = null; AccessibilityNodeInfoCompat child = null; try { source = record.getSource(); if (source == null) { return false; } final int index = (record.getCurrentItemIndex() - record.getFromIndex()); if ((index < 0) || (index >= source.getChildCount())) { return false; } child = source.getChild(index); if (child == null) { return false; } if (!AccessibilityNodeInfoUtils.isTopLevelScrollItem(mService, child)) { return false; } return tryFocusing(child); } finally { AccessibilityNodeInfoUtils.recycleNodes(source, child); } }
From source file:com.android.screenspeak.eventprocessor.ProcessorFocusAndSingleTap.java
/** * @param record the AccessbilityRecord for the event * @param isViewFocusedEvent true if the event is TYPE_VIEW_FOCUSED, otherwise it is * TYPE_VIEW_SELECTED.//from w w w.j ava 2s . co m */ private boolean setFocusOnView(AccessibilityRecordCompat record, boolean isViewFocusedEvent) { AccessibilityNodeInfoCompat source = null; AccessibilityNodeInfoCompat existing = null; AccessibilityNodeInfoCompat child = null; try { source = record.getSource(); if (source == null) { return false; } if (record.getItemCount() > 0) { final int index = (record.getCurrentItemIndex() - record.getFromIndex()); if (index >= 0 && index < source.getChildCount()) { child = source.getChild(index); if (child != null) { if (AccessibilityNodeInfoUtils.isTopLevelScrollItem(child) && tryFocusing(child)) { return true; } } } } if (!isViewFocusedEvent) { return false; } // Logic below is only specific to TYPE_VIEW_FOCUSED event // Try focusing the source node. if (tryFocusing(source)) { return true; } // If we fail and the source node already contains focus, abort. existing = source.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY); if (existing != null) { return false; } // If we fail to focus a node, perhaps because it is a focusable // but non-speaking container, we should still attempt to place // focus on a speaking child within the container. child = AccessibilityNodeInfoUtils.searchFromBfs(source, AccessibilityNodeInfoUtils.FILTER_SHOULD_FOCUS); return child != null && tryFocusing(child); } finally { AccessibilityNodeInfoUtils.recycleNodes(source, existing, child); } }
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();/*from w w w. j a v a 2 s. c om*/ 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();/* w w w. ja va 2s . 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.google.android.marvin.mytalkback.ProcessorFocusAndSingleTap.java
private void handleViewScrolled(AccessibilityEvent event, AccessibilityRecordCompat record) { mLastViewScrolledEvent = event.getEventTime(); final AccessibilityNodeInfoCompat source = record.getSource(); if (source == null) { LogUtils.log(this, Log.ERROR, "Drop scroll with no source node"); return;//from ww w . j a v a 2s. c o m } // Only move focus if we've already seen the source. if (source.equals(mLastScrollSource)) { final boolean isMovingForward = (mLastScrollAction == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) || (event.getFromIndex() > mLastScrollFromIndex) || (event.getToIndex() > mLastScrollToIndex); final boolean wasScrollAction = (mLastScrollAction != 0); mHandler.followScrollDelayed(source, isMovingForward, wasScrollAction); // Performing a scroll action results in smooth scrolling, which may // send multiple events spaced at least 100ms apart. mHandler.clearScrollActionDelayed(); } else { setScrollActionImmediately(0); } if (mLastScrollSource != null) { mLastScrollSource.recycle(); } mLastScrollSource = source; mLastScrollFromIndex = record.getFromIndex(); mLastScrollToIndex = record.getToIndex(); }