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

The following examples show how to use android.view.accessibility.AccessibilityEvent#setCurrentItemIndex() . 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: PLAAdapterView.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
	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());
		}
		event.setItemCount(getCount());
		event.setCurrentItemIndex(getSelectedItemPosition());
	}
       
	return populated;
}
 
Example 2
Source File: DialView.java    From android-BasicAccessibility with Apache License 2.0 5 votes vote down vote up
/**
 * This is where a View should populate outgoing accessibility events with its text content.
 * While this method is free to modify event attributes other than text content, doing so
 * should normally be performed in
 * {@link #onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent)}.
 * <p/>
 * <p>Note that the behavior of this method will typically vary, depending on the type of
 * accessibility event is passed into it. The allowed values also very, and are documented
 * in {@link android.view.accessibility.AccessibilityEvent}.
 * <p/>
 * <p>Typically, this is where you'll describe the state of your custom view. You may also
 * want to provide custom directions when the user has focused your view.
 *
 * @param event The accessibility event which to populate.
 */
// BEGIN_INCLUDE (on_populate_accessibility_event)
@Override
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    super.onPopulateAccessibilityEvent(event);

    // Detect what type of accessibility event is being passed in.
    int eventType = event.getEventType();

    // Common case: The user has interacted with our view in some way. State may or may not
    // have been changed. Read out the current status of the view.
    //
    // We also set some other metadata which is not used by TalkBack, but could be used by
    // other TTS engines.
    if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED ||
            eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        event.getText().add("Mode selected: " + Integer.toString(mActiveSelection + 1) + ".");
        event.setItemCount(SELECTION_COUNT);
        event.setCurrentItemIndex(mActiveSelection);
    }

    // When a user first focuses on our view, we'll also read out some simple instructions to
    // make it clear that this is an interactive element.
    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        event.getText().add("Tap to change.");
    }
}
 
Example 3
Source File: AdapterView.java    From Klyph with MIT License 5 votes vote down vote up
@TargetApi(14)
@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() );
}
 
Example 4
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 5
Source File: AdapterView.java    From android-tv-launcher with MIT License 5 votes vote down vote up
public void onInitializeAccessibilityEvent(AccessibilityEvent paramAccessibilityEvent) {
	super.onInitializeAccessibilityEvent(paramAccessibilityEvent);
	paramAccessibilityEvent.setScrollable(isScrollableForAccessibility());
	View localView = getSelectedView();
	if (localView != null)
		paramAccessibilityEvent.setEnabled(localView.isEnabled());
	paramAccessibilityEvent.setCurrentItemIndex(getSelectedItemPosition());
	paramAccessibilityEvent.setFromIndex(getFirstVisiblePosition());
	paramAccessibilityEvent.setToIndex(getLastVisiblePosition());
	paramAccessibilityEvent.setItemCount(getCount());
}
 
Example 6
Source File: IcsAdapterView.java    From zen4android 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: 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 8
Source File: PLA_ListView.java    From EverMemo 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 9
Source File: IcsAdapterView.java    From Libraries-for-Android-Developers 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 10
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 11
Source File: EcoGalleryAdapterView.java    From samples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    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());
        }
        event.setItemCount(getCount());
        event.setCurrentItemIndex(getSelectedItemPosition());
    }

    return populated;
}
 
Example 12
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 13
Source File: IcsAdapterView.java    From CSipSimple with GNU General Public License v3.0 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 14
Source File: ProgressBar.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @hide */
@Override
public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
    super.onInitializeAccessibilityEventInternal(event);
    event.setItemCount(mMax - mMin);
    event.setCurrentItemIndex(mProgress);
}
 
Example 15
Source File: IcsProgressBar.java    From zen4android 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 16
Source File: BrowserAccessibilityManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private void setAccessibilityEventListAttributes(AccessibilityEvent event,
        int currentItemIndex, int itemCount) {
    event.setCurrentItemIndex(currentItemIndex);
    event.setItemCount(itemCount);
}
 
Example 17
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 18
Source File: IcsProgressBar.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setItemCount(mMax);
    event.setCurrentItemIndex(mProgress);
}
 
Example 19
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 20
Source File: IcsProgressBar.java    From zhangshangwuda with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setItemCount(mMax);
    event.setCurrentItemIndex(mProgress);
}