Java Code Examples for android.view.accessibility.AccessibilityEvent#setItemCount()

The following examples show how to use android.view.accessibility.AccessibilityEvent#setItemCount() . 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: PagedView.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
private void sendScrollAccessibilityEvent() {
    AccessibilityManager am =
            (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (am.isEnabled()) {
        AccessibilityEvent ev =
                AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_SCROLLED);
        ev.setItemCount(getChildCount());
        ev.setFromIndex(mCurrentPage);
        ev.setToIndex(getNextPage());

        final int action;
        if (getNextPage() >= mCurrentPage) {
            action = AccessibilityNodeInfo.ACTION_SCROLL_FORWARD;
        } else {
            action = AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD;
        }

        ev.setAction(action);
        sendAccessibilityEventUnchecked(ev);
    }
}
 
Example 2
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
private void sendScrollAccessibilityEvent() {
    AccessibilityManager am =
            (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (am.isEnabled()) {
        AccessibilityEvent ev =
                AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_SCROLLED);
        ev.setItemCount(getChildCount());
        ev.setFromIndex(mCurrentPage);
        ev.setToIndex(getNextPage());

        final int action;
        if (getNextPage() >= mCurrentPage) {
            action = AccessibilityNodeInfo.ACTION_SCROLL_FORWARD;
        } else {
            action = AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD;
        }

        ev.setAction(action);
        sendAccessibilityEventUnchecked(ev);
    }
}
 
Example 3
Source File: PLAListView.java    From Lay-s with MIT License 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    boolean populated = super.dispatchPopulateAccessibilityEvent(event);

    // If the item count is less than 15 then subtract disabled items from the count and
    // position. Otherwise ignore disabled items.
    if (!populated) {
        int itemCount = 0;
        int currentItemIndex = getSelectedItemPosition();

        ListAdapter adapter = getAdapter();
        if (adapter != null) {
            final int count = adapter.getCount();
            if (count < 15) {
                for (int i = 0; i < count; i++) {
                    if (adapter.isEnabled(i)) {
                        itemCount++;
                    } else if (i <= currentItemIndex) {
                        currentItemIndex--;
                    }
                }
            } else {
                itemCount = count;
            }
        }

        event.setItemCount(itemCount);
        event.setCurrentItemIndex(currentItemIndex);
    }

    return populated;
}
 
Example 4
Source File: CoolViewPager.java    From CoolViewPager with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(host, event);
    event.setClassName(CoolViewPager.class.getName());
    event.setScrollable(canScroll());
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED && mAdapter != null) {
        event.setItemCount(mAdapter.getCount());
        event.setFromIndex(mCurItem);
        event.setToIndex(mCurItem);
    }
}
 
Example 5
Source File: PLAListView.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    boolean populated = super.dispatchPopulateAccessibilityEvent(event);

    // If the item count is less than 15 then subtract disabled items from the count and
    // position. Otherwise ignore disabled items.
    if (!populated) {
        int itemCount = 0;
        int currentItemIndex = getSelectedItemPosition();

        ListAdapter adapter = getAdapter();
        if (adapter != null) {
            final int count = adapter.getCount();
            if (count < 15) {
                for (int i = 0; i < count; i++) {
                    if (adapter.isEnabled(i)) {
                        itemCount++;
                    } else if (i <= currentItemIndex) {
                        currentItemIndex--;
                    }
                }
            } else {
                itemCount = count;
            }
        }

        event.setItemCount(itemCount);
        event.setCurrentItemIndex(currentItemIndex);
    }

    return populated;
}
 
Example 6
Source File: IcsAdapterView.java    From android-apps with MIT License 5 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setScrollable(isScrollableForAccessibility());
    View selectedView = getSelectedView();
    if (selectedView != null) {
        event.setEnabled(selectedView.isEnabled());
    }
    event.setCurrentItemIndex(getSelectedItemPosition());
    event.setFromIndex(getFirstVisiblePosition());
    event.setToIndex(getLastVisiblePosition());
    event.setItemCount(getCount());
}
 
Example 7
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@CalledByNative
private void setAccessibilityEventSelectionAttrs(AccessibilityEvent event,
        int fromIndex, int addedCount, int itemCount, String text) {
    event.setFromIndex(fromIndex);
    event.setAddedCount(addedCount);
    event.setItemCount(itemCount);
    event.getText().add(text);
}
 
Example 8
Source File: AdapterView.java    From letv with Apache License 2.0 5 votes vote down vote up
@TargetApi(14)
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setClassName(AdapterView.class.getName());
    event.setScrollable(isScrollableForAccessibility());
    View selectedView = getSelectedView();
    if (selectedView != null) {
        event.setEnabled(selectedView.isEnabled());
    }
    event.setCurrentItemIndex(getSelectedItemPosition());
    event.setFromIndex(getFirstVisiblePosition());
    event.setToIndex(getLastVisiblePosition());
    event.setItemCount(getCount());
}
 
Example 9
Source File: DayPickerView.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setItemCount(-1);
}
 
Example 10
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private void finishGranularityMove(String text, boolean extendSelection,
        int itemStartIndex, int itemEndIndex, boolean forwards) {
    if (mNativeObj == 0) return;

    // Prepare to send both a selection and a traversal event in sequence.
    AccessibilityEvent selectionEvent = buildAccessibilityEvent(mAccessibilityFocusId,
            AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED);
    if (selectionEvent == null) return;
    AccessibilityEvent traverseEvent = buildAccessibilityEvent(mAccessibilityFocusId,
            AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY);
    if (traverseEvent == null) {
        selectionEvent.recycle();
        return;
    }

    // Update the cursor or selection based on the traversal. If it's an editable
    // text node, set the real editing cursor too.
    if (forwards) {
        mSelectionEndIndex = itemEndIndex;
    } else {
        mSelectionEndIndex = itemStartIndex;
    }
    if (!extendSelection) {
        mSelectionStartIndex = mSelectionEndIndex;
    }
    if (nativeIsEditableText(mNativeObj, mAccessibilityFocusId)
            && nativeIsFocused(mNativeObj, mAccessibilityFocusId)) {
        nativeSetSelection(mNativeObj, mAccessibilityFocusId,
                mSelectionStartIndex, mSelectionEndIndex);
    }

    // The selection event's "from" and "to" indices are just a cursor at the focus
    // end of the movement, or a selection if extendSelection is true.
    selectionEvent.setFromIndex(mSelectionStartIndex);
    selectionEvent.setToIndex(mSelectionStartIndex);
    selectionEvent.setItemCount(text.length());

    // The traverse event's "from" and "to" indices surround the item (e.g. the word,
    // etc.) with no whitespace.
    traverseEvent.setFromIndex(itemStartIndex);
    traverseEvent.setToIndex(itemEndIndex);
    traverseEvent.setItemCount(text.length());
    traverseEvent.setMovementGranularity(mSelectionGranularity);
    traverseEvent.setContentDescription(text);

    // The traverse event needs to set its associated action that triggered it.
    if (forwards) {
        traverseEvent.setAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
    } else {
        traverseEvent.setAction(
                AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
    }

    mView.requestSendAccessibilityEvent(mView, selectionEvent);
    mView.requestSendAccessibilityEvent(mView, traverseEvent);
}
 
Example 11
Source File: IcsProgressBar.java    From android-apps with MIT License 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setItemCount(mMax);
    event.setCurrentItemIndex(mProgress);
}
 
Example 12
Source File: DayPickerView.java    From date_picker_converter with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(@NonNull AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setItemCount(-1);
}
 
Example 13
Source File: DayPickerView.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
@Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setItemCount(-1);
}
 
Example 14
Source File: PagingDayPickerView.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
@Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setItemCount(-1);
}
 
Example 15
Source File: ToolbarProgressBar.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setCurrentItemIndex((int) (mTargetProgress * 100));
    event.setItemCount(100);
}
 
Example 16
Source File: ToolbarProgressBar.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setCurrentItemIndex((int) (mTargetProgress * 100));
    event.setItemCount(100);
}
 
Example 17
Source File: DayPickerView.java    From MaterialDateTimePicker with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(@NonNull AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setItemCount(-1);
}
 
Example 18
Source File: DayPickerView.java    From PersianDateRangePicker with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(@NonNull AccessibilityEvent event) {
  super.onInitializeAccessibilityEvent(event);
  event.setItemCount(-1);
}
 
Example 19
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@CalledByNative
private void setAccessibilityEventListAttributes(AccessibilityEvent event,
        int currentItemIndex, int itemCount) {
    event.setCurrentItemIndex(currentItemIndex);
    event.setItemCount(itemCount);
}
 
Example 20
Source File: DayPickerView.java    From StyleableDateTimePicker with MIT License 4 votes vote down vote up
@Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setItemCount(-1);
}