Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6342,6 +6342,9 @@ public TLRPC.Chat getCurrentChat() {
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();

accessibilityFocused = false;
accessibilityHovered = false;

NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.startSpoilers);
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.stopSpoilers);
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.emojiLoaded);
Expand Down Expand Up @@ -26347,6 +26350,12 @@ public int getLayoutHeight() {

@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
if (action == AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS) {
accessibilityFocused = true;
} else if (action == AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) {
accessibilityFocused = false;
updateAccessibilityTraversalText();
}
if (delegate != null && delegate.onAccessibilityAction(action, arguments)) {
return false;
}
Expand Down Expand Up @@ -26424,6 +26433,7 @@ public boolean onHoverEvent(MotionEvent event) {
int x = (int) getEventX(event);
int y = (int) getEventY(event);
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
accessibilityHovered = true;
for (int i = 0; i < accessibilityVirtualViewBounds.size(); i++) {
Rect rect = accessibilityVirtualViewBounds.valueAt(i);
if (rect.contains(x, y)) {
Expand All @@ -26437,10 +26447,28 @@ public boolean onHoverEvent(MotionEvent event) {
}
} else if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT) {
currentFocusedVirtualView = 0;
accessibilityHovered = false;
updateAccessibilityTraversalText();
}
return super.onHoverEvent(event);
}

private boolean accessibilityFocused;
private boolean accessibilityHovered;

private boolean isReadByAccessibility() {
return accessibilityFocused || accessibilityHovered || isAccessibilityFocused();
}

// the framework's granular traversal iterates over the host view's content description, and
// changing it reports the message as changed, which has screen readers read it again: so it
// is only brought up to date once the message is no longer being read
private void updateAccessibilityTraversalText() {
if (accessibilityText != null && !TextUtils.equals(getContentDescription(), accessibilityText)) {
setContentDescription(accessibilityText);
}
}

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
Expand Down Expand Up @@ -27102,7 +27130,20 @@ public void onClick(View view) {
info.setContentDescription(accessibilityText.toString());
} else {
info.setText(accessibilityText);
// links are only exposed to screen readers through the node text, so keep
// the content description off the node to not shadow it
info.setContentDescription(null);
}
if (!isReadByAccessibility()) {
updateAccessibilityTraversalText();
}
info.setMovementGranularities(
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER |
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD |
AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH
);
info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);

info.setEnabled(true);
AccessibilityNodeInfo.CollectionItemInfo itemInfo = info.getCollectionItemInfo();
Expand Down