Skip to content

Commit 2bff640

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "Adding an announcement type accessibility event and a method on View to announce."
2 parents c68bbe6 + 51ab90c commit 2bff640

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

api/current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23119,6 +23119,7 @@ package android.view {
2311923119
method public void addOnLayoutChangeListener(android.view.View.OnLayoutChangeListener);
2312023120
method public void addTouchables(java.util.ArrayList<android.view.View>);
2312123121
method public android.view.ViewPropertyAnimator animate();
23122+
method public void announceForAccessibility(java.lang.CharSequence);
2312223123
method protected boolean awakenScrollBars();
2312323124
method protected boolean awakenScrollBars(int);
2312423125
method protected boolean awakenScrollBars(int, boolean);
@@ -24343,6 +24344,7 @@ package android.view.accessibility {
2434324344
field public static final int INVALID_POSITION = -1; // 0xffffffff
2434424345
field public static final deprecated int MAX_TEXT_LENGTH = 500; // 0x1f4
2434524346
field public static final int TYPES_ALL_MASK = -1; // 0xffffffff
24347+
field public static final int TYPE_ANNOUNCEMENT = 16384; // 0x4000
2434624348
field public static final int TYPE_NOTIFICATION_STATE_CHANGED = 64; // 0x40
2434724349
field public static final int TYPE_TOUCH_EXPLORATION_GESTURE_END = 1024; // 0x400
2434824350
field public static final int TYPE_TOUCH_EXPLORATION_GESTURE_START = 512; // 0x200

core/java/android/view/View.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,6 +3951,24 @@ public void sendAccessibilityEvent(int eventType) {
39513951
}
39523952
}
39533953

3954+
/**
3955+
* Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT}
3956+
* {@link AccessibilityEvent} to make an announcement which is related to some
3957+
* sort of a context change for which none of the events representing UI transitions
3958+
* is a good fit. For example, announcing a new page in a book. If accessibility
3959+
* is not enabled this method does nothing.
3960+
*
3961+
* @param text The announcement text.
3962+
*/
3963+
public void announceForAccessibility(CharSequence text) {
3964+
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
3965+
AccessibilityEvent event = AccessibilityEvent.obtain(
3966+
AccessibilityEvent.TYPE_ANNOUNCEMENT);
3967+
event.getText().add(text);
3968+
sendAccessibilityEventUnchecked(event);
3969+
}
3970+
}
3971+
39543972
/**
39553973
* @see #sendAccessibilityEvent(int)
39563974
*

core/java/android/view/accessibility/AccessibilityEvent.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,26 @@
429429
* view.</br>
430430
* </p>
431431
* <p>
432+
* <b>MISCELLANEOUS TYPES</b></br>
433+
* </p>
434+
* <p>
435+
* <b>Announcement</b> - represents the event of an application making an
436+
* announcement. Usually this announcement is related to some sort of a context
437+
* change for which none of the events representing UI transitions is a good fit.
438+
* For example, announcing a new page in a book.</br>
439+
* <em>Type:</em> {@link #TYPE_ANNOUNCEMENT}</br>
440+
* <em>Properties:</em></br>
441+
* <ul>
442+
* <li>{@link #getEventType()} - The type of the event.</li>
443+
* <li>{@link #getSource()} - The source info (for registered clients).</li>
444+
* <li>{@link #getClassName()} - The class name of the source.</li>
445+
* <li>{@link #getPackageName()} - The package name of the source.</li>
446+
* <li>{@link #getEventTime()} - The event time.</li>
447+
* <li>{@link #getText()} - The text of the announcement.</li>
448+
* <li>{@link #isEnabled()} - Whether the source is enabled.</li>
449+
* </ul>
450+
* </p>
451+
* <p>
432452
* <b>Security note</b>
433453
* <p>
434454
* Since an event contains the text of its source privacy can be compromised by leaking
@@ -537,6 +557,11 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
537557
*/
538558
public static final int TYPE_VIEW_TEXT_SELECTION_CHANGED = 0x00002000;
539559

560+
/**
561+
* Represents the event of an application making an announcement.
562+
*/
563+
public static final int TYPE_ANNOUNCEMENT = 0x00004000;
564+
540565
/**
541566
* Mask for {@link AccessibilityEvent} all types.
542567
*
@@ -554,6 +579,7 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
554579
* @see #TYPE_WINDOW_CONTENT_CHANGED
555580
* @see #TYPE_VIEW_SCROLLED
556581
* @see #TYPE_VIEW_TEXT_SELECTION_CHANGED
582+
* @see #TYPE_ANNOUNCEMENT
557583
*/
558584
public static final int TYPES_ALL_MASK = 0xFFFFFFFF;
559585

@@ -984,6 +1010,8 @@ public static String eventTypeToString(int eventType) {
9841010
return "TYPE_VIEW_TEXT_SELECTION_CHANGED";
9851011
case TYPE_VIEW_SCROLLED:
9861012
return "TYPE_VIEW_SCROLLED";
1013+
case TYPE_ANNOUNCEMENT:
1014+
return "TYPE_ANNOUNCEMENT";
9871015
default:
9881016
return null;
9891017
}

0 commit comments

Comments
 (0)