Java Code Examples for android.view.accessibility.AccessibilityEvent#setFromIndex()
The following examples show how to use
android.view.accessibility.AccessibilityEvent#setFromIndex() .
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 |
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: StaggeredGridLayoutManager.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); if (getChildCount() > 0) { final View start = findFirstVisibleItemClosestToStart(false); final View end = findFirstVisibleItemClosestToEnd(false); if (start == null || end == null) { return; } final int startPos = getPosition(start); final int endPos = getPosition(end); if (startPos < endPos) { event.setFromIndex(startPos); event.setToIndex(endPos); } else { event.setFromIndex(endPos); event.setToIndex(startPos); } } }
Example 3
Source File: StaggeredGridLayoutManager.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); if (getChildCount() > 0) { final View start = findFirstVisibleItemClosestToStart(false); final View end = findFirstVisibleItemClosestToEnd(false); if (start == null || end == null) { return; } final int startPos = getPosition(start); final int endPos = getPosition(end); if (startPos < endPos) { event.setFromIndex(startPos); event.setToIndex(endPos); } else { event.setFromIndex(endPos); event.setToIndex(startPos); } } }
Example 4
Source File: NumberPicker.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Updates the view of this NumberPicker. If displayValues were specified in * the string corresponding to the index specified by the current value will * be returned. Otherwise, the formatter specified in {@link #setFormatter} * will be used to format the number. * * @return Whether the text was updated. */ private boolean updateInputTextView() { /* * If we don't have displayed values then use the current number else * find the correct value in the displayed values for the current * number. */ String text = (mDisplayedValues == null) ? formatNumber(mValue) : mDisplayedValues[mValue - mMinValue]; if (!TextUtils.isEmpty(text)) { CharSequence beforeText = mInputText.getText(); if (!text.equals(beforeText.toString())) { mInputText.setText(text); if (AccessibilityManager.getInstance(mContext).isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain( AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED); mInputText.onInitializeAccessibilityEvent(event); mInputText.onPopulateAccessibilityEvent(event); event.setFromIndex(0); event.setRemovedCount(beforeText.length()); event.setAddedCount(text.length()); event.setBeforeText(beforeText); event.setSource(NumberPicker.this, AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INPUT); requestSendAccessibilityEvent(NumberPicker.this, event); } return true; } } return false; }
Example 5
Source File: IcsAdapterView.java From Libraries-for-Android-Developers with MIT License | 5 votes |
@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 6
Source File: BrowserAccessibilityManager.java From 365browser with Apache License 2.0 | 5 votes |
@CalledByNative private void setAccessibilityEventSelectionAttrs(AccessibilityEvent event, int fromIndex, int toIndex, int itemCount, String text) { event.setFromIndex(fromIndex); event.setToIndex(toIndex); event.setItemCount(itemCount); event.getText().add(text); }
Example 7
Source File: YearPickerView.java From MaterialDateTimePicker with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) { event.setFromIndex(0); event.setToIndex(0); } }
Example 8
Source File: BrowserAccessibilityManager.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@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 9
Source File: YearPickerView.java From StyleableDateTimePicker with MIT License | 5 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) { event.setFromIndex(0); event.setToIndex(0); } }
Example 10
Source File: AdapterView.java From letv with Apache License 2.0 | 5 votes |
@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 11
Source File: LinearLayoutManager.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); if (getChildCount() > 0) { event.setFromIndex(findFirstVisibleItemPosition()); event.setToIndex(findLastVisibleItemPosition()); } }
Example 12
Source File: IcsAdapterView.java From zen4android with MIT License | 5 votes |
@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 13
Source File: BrowserAccessibilityManager.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@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 14
Source File: TokenCompleteTextView.java From TokenAutoComplete with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED) { CharSequence text = getTextForAccessibility(); event.setFromIndex(Selection.getSelectionStart(text)); event.setToIndex(Selection.getSelectionEnd(text)); event.setItemCount(text.length()); } }
Example 15
Source File: SliderPager.java From Android-Image-Slider with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { super.onInitializeAccessibilityEvent(host, event); event.setClassName(SliderPager.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 16
Source File: IcsAdapterView.java From android-apps with MIT License | 5 votes |
@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 17
Source File: IcsAdapterView.java From zhangshangwuda with Apache License 2.0 | 5 votes |
@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 18
Source File: YearPickerView.java From cathode with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) { event.setFromIndex(0); event.setToIndex(0); } }
Example 19
Source File: BrowserAccessibilityManager.java From 365browser with Apache License 2.0 | 4 votes |
@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 20
Source File: AutocompleteEditText.java From 365browser with Apache License 2.0 | 4 votes |
@Override public boolean commitText(CharSequence text, int newCursorPosition) { if (DEBUG) Log.i(TAG, "commitText: [%s]", text); Editable currentText = getText(); if (currentText == null) return super.commitText(text, newCursorPosition); int selectionStart = Selection.getSelectionStart(currentText); int selectionEnd = Selection.getSelectionEnd(currentText); int autocompleteIndex = currentText.getSpanStart(mAutocompleteSpan); // If the text being committed is a single character that matches the next character // in the selection (assumed to be the autocomplete text), we only move the text // selection instead clearing the autocomplete text causing flickering as the // autocomplete text will appear once the next suggestions are received. // // To be confident that the selection is an autocomplete, we ensure the selection // is at least one character and the end of the selection is the end of the // currently entered text. if (newCursorPosition == 1 && selectionStart > 0 && selectionStart != selectionEnd && selectionEnd >= currentText.length() && autocompleteIndex == selectionStart && text.length() == 1) { currentText.getChars(selectionStart, selectionStart + 1, mTempSelectionChar, 0); if (mTempSelectionChar[0] == text.charAt(0)) { // Since the text isn't changing, TalkBack won't read out the typed characters. // To work around this, explicitly send an accessibility event. crbug.com/416595 if (mAccessibilityManager != null && mAccessibilityManager.isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain( AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED); event.setFromIndex(selectionStart); event.setRemovedCount(0); event.setAddedCount(1); event.setBeforeText(currentText.toString().substring(0, selectionStart)); sendAccessibilityEventUnchecked(event); } setAutocompleteText(currentText.subSequence(0, selectionStart + 1), currentText.subSequence(selectionStart + 1, selectionEnd)); if (!mInBatchEditMode) { notifyAutocompleteTextStateChanged(false, false); } return true; } } boolean retVal = super.commitText(text, newCursorPosition); // Ensure the autocomplete span is removed if it is no longer valid after committing the // text. if (getText().getSpanStart(mAutocompleteSpan) >= 0) clearAutocompleteSpanIfInvalid(); return retVal; }