Android AccessibilityEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AccessibilityEvent class.

This code example shows how to use the following methods:getEventType, getText, setAddedCount, setBeforeText, setFromIndex
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        if (!accessibilityExtensions()) 
            return super.dispatchPopulateAccessibilityEvent(event);
        cursorTrackingEnabled = false;
        boolean result = super.dispatchPopulateAccessibilityEvent(event);
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
            if (isFocused()) {
                event.getText().clear();
                event.getText().add(getText().subSequence(selectionStart, selectionStart + selectionLength));
            } 
            event.setAddedCount(selectionLength);
            event.setRemovedCount(0);
            event.setFromIndex(0);
            event.setBeforeText(null);
            result = true;
        } 
        cursorTrackingEnabled =true;
        return result;
    } 
 
8
CodeRank
This code example shows how to use the following methods:getEventType, getAddedCount, getBeforeText, getRemovedCount, setAddedCount
        return ret;
    } 
 
    @Override 
    public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
            // Since we're replacing the text every time we add or remove a 
            // character, only read the difference. (issue 5337550) 
            final int added = event.getAddedCount();
            final int removed = event.getRemovedCount();
            final int length = event.getBeforeText().length();
            if (added > removed) {
                event.setRemovedCount(0);
                event.setAddedCount(1);
                event.setFromIndex(length);
            } else if (removed > added) {
                event.setRemovedCount(1);
                event.setAddedCount(0);
                event.setFromIndex(length - 1);
            } else { 

9
CodeRank
This code example shows how to use the following methods:setClassName, setCurrentItemIndex, setEnabled, setFromIndex, setItemCount
    } 
 
    @SuppressLint("NewApi") 
    @Override 
    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());
    } 
 
    @SuppressLint("NewApi") 
    @Override 
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
8
CodeRank
This code example shows how to use the following methods:appendRecord
            // Add a record for the entire layout since its content is somehow small. 
            // The event comes from a leaf view that is interacted with. 
            AccessibilityEvent record = AccessibilityEvent.obtain();
            onInitializeAccessibilityEvent(record);
            dispatchPopulateAccessibilityEvent(record);
            event.appendRecord(record);
            return true; 
        } 
        return false; 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:setCurrentItemIndex, setEnabled, setFromIndex, setItemCount, setScrollable
    } 
 
    @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());
    } 
 
    private boolean isScrollableForAccessibility() { 
        T adapter = getAdapter();
        if (adapter != null) {
            final int itemCount = adapter.getCount();
7
CodeRank
This code example shows how to use the following methods:appendRecord
    public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
        if (super.onRequestSendAccessibilityEvent(child, event)) {
            AccessibilityEvent record = AccessibilityEvent.obtain();
            onInitializeAccessibilityEvent(record);
            dispatchPopulateAccessibilityEvent(record);
            event.appendRecord(record);
            return true; 
        } 
        return false; 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:setPackageName, setClassName, setContentDescription, setEnabled
        return handled;
    } 
 
    @Override 
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        event.setClassName(getClass().getName());
        event.setPackageName(getContext().getPackageName());
        event.setEnabled(true);
        event.setContentDescription(getContentDescription());
        return true; 
    } 
 
    /** 
     * Sets the content description for this item, used for accessibility. 
     */ 
    private void populateContentDescription() { 
        if (!TextUtils.isEmpty(mSubject)) {
            setContentDescription(sSubjectDescription + mSubject);
        } else { 
            setContentDescription(sSubjectEmptyDescription);
7
CodeRank
This code example shows how to use the following methods:getEventType, getText
    // Overridden callback methods to provide accessible exploration means. 
 
    @Override 
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        boolean result = super.dispatchPopulateAccessibilityEvent(event);
        if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
            event.getText().clear();
            event.getText().add(getText().subSequence(0, Math.min(getText().length(), AccessibilityEvent.MAX_TEXT_LENGTH)));
            result = true;
        } 
        return result;
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:setChecked, setEnabled, setPassword, setScrollable
    } 
 
    @CalledByNative 
    private void setAccessibilityEventBooleanAttributes(AccessibilityEvent event,
            boolean checked, boolean enabled, boolean password, boolean scrollable) {
        event.setChecked(checked);
        event.setEnabled(enabled);
        event.setPassword(password);
        event.setScrollable(scrollable);
    } 
 
    @CalledByNative 
    private void setAccessibilityEventClassName(AccessibilityEvent event, String className) {
        event.setClassName(className);
    } 
 
    @CalledByNative 
    private void setAccessibilityEventListAttributes(AccessibilityEvent event,
            int currentItemIndex, int itemCount) {
        event.setCurrentItemIndex(currentItemIndex);
7
CodeRank
This code example shows how to use the following methods:getEventType, setEventType, setCurrentItemIndex, setEnabled, setItemCount
		boolean populated = false;
		// This is an exceptional case which occurs when a window gets the 
		// focus and sends a focus event via its focused child to announce 
		// current focus/selection. AdapterView fires selection but not focus 
		// events so we change the event type here. 
		if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
			event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
		} 
 
		// we send selection events only from AdapterView to avoid 
		// generation of such event for each child 
		View selectedView = getSelectedView();
		if (selectedView != null) {
			populated = selectedView.dispatchPopulateAccessibilityEvent(event);
		} 
 
		if (!populated) {
			if (selectedView != null) {
				event.setEnabled(selectedView.isEnabled());
			} 

7
CodeRank

Related Android AccessibilityEvent Questions & Answers:

See Code Examples for Android AccessibilityEvent Methods: