Note: Use ViewCompat.addAccessibilityAction(View, CharSequence, AccessibilityViewCommand)
to register an action directly on the view.
Summary
Public methods
int
describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
boolean
equals (Object other)
Indicates whether some other object is "equal to" this one.
int
getId ()
Gets the id for this action.
CharSequence
getLabel ()
Gets the label for this action.
int
hashCode ()
Returns a hash code value for the object.
String
toString ()
Returns a string representation of the object.
void
writeToParcel (Parcel out, int flags)
Write data into a parcel.
Inherited methods
From class
java.lang.Object
Object
clone ()
Creates and returns a copy of this object.
boolean
equals (Object obj)
Indicates whether some other object is "equal to" this one.
void
finalize ()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
final
Class <?>
getClass ()
Returns the runtime class of this Object
.
int
hashCode ()
Returns a hash code value for the object.
final
void
notify ()
Wakes up a single thread that is waiting on this object's
monitor.
final
void
notifyAll ()
Wakes up all threads that are waiting on this object's monitor.
String
toString ()
Returns a string representation of the object.
final
void
wait (long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted , or until a
certain amount of real time has elapsed.
final
void
wait (long timeoutMillis)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted , or until a
certain amount of real time has elapsed.
final
void
wait ()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted .
Fields
ACTION_NEXT_AT_MOVEMENT_GRANULARITY
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_NEXT_AT_MOVEMENT_GRANULARITY
Action that requests to go to the next entity in this node's text
at a given movement granularity. For example, move to the next character,
word, etc.
Arguments:
AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
,
AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
Example: Move to the previous character and do not extend selection.
Bundle arguments = new Bundle();
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER);
arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
info.performAction(AccessibilityAction.ACTION_NEXT_AT_MOVEMENT_GRANULARITY.getId(),
arguments);
ACTION_NEXT_HTML_ELEMENT
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_NEXT_HTML_ELEMENT
Action to move to the next HTML element of a given type. For example, move
to the BUTTON, INPUT, TABLE, etc.
Arguments:
AccessibilityNodeInfo.ACTION_ARGUMENT_HTML_ELEMENT_STRING
Example:
Bundle arguments = new Bundle();
arguments.putString(AccessibilityNodeInfo.ACTION_ARGUMENT_HTML_ELEMENT_STRING, "BUTTON");
info.performAction(AccessibilityAction.ACTION_NEXT_HTML_ELEMENT.getId(), arguments);
ACTION_PRESS_AND_HOLD
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_PRESS_AND_HOLD
Action that presses and holds a node.
This action is for nodes that have distinct behavior that depends on how long a press is
held. Nodes having a single action for long press should use ACTION_LONG_CLICK
instead of this action, and nodes should not expose both actions.
When calling performAction(ACTION_PRESS_AND_HOLD, bundle
, use
AccessibilityNodeInfo.ACTION_ARGUMENT_PRESS_AND_HOLD_DURATION_MILLIS_INT
to specify how long the
node is pressed. The first time an accessibility service performs ACTION_PRES_AND_HOLD
on a node, it must specify 0 as ACTION_ARGUMENT_PRESS_AND_HOLD, so the application is
notified that the held state has started. To ensure reasonable behavior, the values
must be increased incrementally and may not exceed 10,000. UIs requested
to hold for times outside of this range should ignore the action.
The total time the element is held could be specified by an accessibility user up-front,
or may depend on what happens on the UI as the user continues to request the hold.
Note: The time between dispatching the action and it arriving in the
UI process is not guaranteed. It is possible on a busy system for the time to expire
unexpectedly. For the case of holding down a key for a repeating action, a delayed
arrival should be benign. Please do not use this sort of action in cases where such
delays will lead to unexpected UI behavior.
ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY
Action that requests to go to the previous entity in this node's text
at a given movement granularity. For example, move to the next character,
word, etc.
Arguments:
AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
,
AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
Example: Move to the next character and do not extend selection.
Bundle arguments = new Bundle();
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER);
arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
info.performAction(AccessibilityAction.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY.getId(),
arguments);
ACTION_PREVIOUS_HTML_ELEMENT
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_PREVIOUS_HTML_ELEMENT
Action to move to the previous HTML element of a given type. For example, move
to the BUTTON, INPUT, TABLE, etc.
Arguments:
AccessibilityNodeInfo.ACTION_ARGUMENT_HTML_ELEMENT_STRING
Example:
Bundle arguments = new Bundle();
arguments.putString(AccessibilityNodeInfo.ACTION_ARGUMENT_HTML_ELEMENT_STRING, "BUTTON");
info.performAction(AccessibilityAction.ACTION_PREVIOUS_HTML_ELEMENT.getId(), arguments);
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_SCROLL_BACKWARD
Action to scroll the node content backward.
The UI element that implements this should send a
AccessibilityEvent#TYPE_VIEW_SCROLLED
event. Depending on the orientation,
this element should also add the relevant directional scroll actions of
ACTION_SCROLL_LEFT
, ACTION_SCROLL_RIGHT
,
ACTION_SCROLL_UP
, and ACTION_SCROLL_DOWN
. If the scrolling brings
the next or previous element into view as the center element, such as in a ViewPager2,
use ACTION_PAGE_DOWN
and the other page actions instead of the directional
actions.
Example: a scrolling UI of horizontal orientation with a backward
scroll action should also add the scroll left/right action (LTR/RTL):
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
if (canScrollBackward) {
info.addAction(ACTION_SCROLL_FORWARD);
if (leftToRight) {
info.addAction(ACTION_SCROLL_LEFT);
} else {
info.addAction(ACTION_SCROLL_RIGHT);
}
}
}
performAccessibilityAction(int action, Bundle bundle) {
if (action == ACTION_SCROLL_BACKWARD) {
scrollBackward();
} else if (action == ACTION_SCROLL_LEFT) {
if (!isRTL()){
scrollBackward();
}
} else if (action == ACTION_SCROLL_RIGHT) {
if (isRTL()){
scrollBackward();
}
}
}
scrollBackward() {
...
if (mAccessibilityManager.isEnabled()) {
event = new AccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED);
event.setScrollDeltaX(dx);
event.setScrollDeltaY(dy);
event.setMaxScrollX(maxDx);
event.setMaxScrollY(maxDY);
sendAccessibilityEventUnchecked(event);
}
}
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_SCROLL_FORWARD
Action to scroll the node content forward.
The UI element that implements this should send a
AccessibilityEvent#TYPE_VIEW_SCROLLED
event. Depending on the orientation,
this element should also add the relevant directional scroll actions of
ACTION_SCROLL_LEFT
, ACTION_SCROLL_RIGHT
,
ACTION_SCROLL_UP
, and ACTION_SCROLL_DOWN
. If the scrolling brings
the next or previous element into view as the center element, such as in a ViewPager2,
use ACTION_PAGE_DOWN
and the other page actions instead of the directional
actions.
Example: a scrolling UI of vertical orientation with a forward
scroll action should also add the scroll down action:
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
if (canScrollForward) {
info.addAction(ACTION_SCROLL_FORWARD);
info.addAction(ACTION_SCROLL_DOWN);
}
}
performAccessibilityAction(int action, Bundle bundle) {
if (action == ACTION_SCROLL_FORWARD || action == ACTION_SCROLL_DOWN) {
scrollForward();
}
}
scrollForward() {
...
if (mAccessibilityManager.isEnabled()) {
event = new AccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED);
event.setScrollDeltaX(dx);
event.setScrollDeltaY(dy);
event.setMaxScrollX(maxDx);
event.setMaxScrollY(maxDY);
sendAccessibilityEventUnchecked(event);
}
}
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_SCROLL_IN_DIRECTION
Action that brings fully on screen the next node in the specified direction.
This should include wrapping around to the next/previous row, column, etc. in a
collection if one is available. If there is no node in that direction, the action
should fail and return false.
This action should be used instead of
AccessibilityAction#ACTION_SCROLL_TO_POSITION
when a widget does not have
clear row and column semantics or if a directional search is needed to find a node in
a complex ViewGroup where individual nodes may span multiple rows or columns. The
implementing widget must send a
AccessibilityEvent#TYPE_VIEW_TARGETED_BY_SCROLL
accessibility event with the
scroll target as the source. An accessibility service can listen for this event,
inspect its source, and use the result when determining where to place accessibility
focus.
Arguments: AccessibilityNodeInfo.ACTION_ARGUMENT_DIRECTION_INT
. This is a
required argument.
public static final AccessibilityNodeInfo.AccessibilityAction ACTION_SHOW_TOOLTIP
Action to show a tooltip. A node should expose this action only for views with tooltip
text that but are not currently showing a tooltip.
Public constructors
AccessibilityAction
public AccessibilityAction (int actionId,
CharSequence label)
Creates a new AccessibilityAction. For adding a standard action without a specific label,
use the static constants.
You can also override the description for one the standard actions. Below is an example
how to override the standard click action by adding a custom label:
AccessibilityAction action = new AccessibilityAction(
AccessibilityAction.ACTION_CLICK.getId(), getLocalizedLabel());
node.addAction(action);
Parameters
actionId
int
: The id for this action. This should either be one of the
standard actions or a specific action for your app. In that case it is
required to use a resource identifier.
label
CharSequence
: The label for the new AccessibilityAction.
This value may be null
.
Public methods
describeContents
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of writeToParcel(android.os.Parcel, int)
,
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR
bit.
Returns
int
a bitmask indicating the set of special object types marshaled
by this Parcelable object instance.
Value is either 0
or CONTENTS_FILE_DESCRIPTOR
equals
public boolean equals (Object other)
Indicates whether some other object is "equal to" this one.
The equals
method implements an equivalence relation
on non-null object references:
It is reflexive : for any non-null reference value
x
, x.equals(x)
should return
true
.
It is symmetric : for any non-null reference values
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
It is transitive : for any non-null reference values
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
It is consistent : for any non-null reference values
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
For any non-null reference value x
,
x.equals(null)
should return false
.
An equivalence relation partitions the elements it operates on
into equivalence classes ; all the members of an
equivalence class are equal to each other. Members of an
equivalence class are substitutable for each other, at least
for some purposes.
Parameters
other
Object
: This value may be null
.
Returns
boolean
true
if this object is the same as the obj
argument; false
otherwise.
getId
public int getId ()
Gets the id for this action.
Returns
int
The action id.
getLabel
public CharSequence getLabel ()
Gets the label for this action. Its purpose is to describe the
action to user.
hashCode
public int hashCode ()
Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
HashMap
.
The general contract of hashCode
is:
Whenever it is invoked on the same object more than once during
an execution of a Java application, the hashCode
method
must consistently return the same integer, provided no information
used in equals
comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
If two objects are equal according to the equals
method, then calling the hashCode
method on each of the two objects must produce the
same integer result.
It is not required that if two objects are unequal
according to the equals
method, then
calling the hashCode
method on each of the two objects
must produce distinct integer results. However, the programmer
should be aware that producing distinct integer results for
unequal objects may improve the performance of hash tables.
Returns
int
a hash code value for this object.
toString
public String toString ()
Returns a string representation of the object.
Returns
String
a string representation of the object.
writeToParcel
public void writeToParcel (Parcel out,
int flags)
Write data into a parcel.