From 27ad2e95b40fd0ca76de384695498ea114d627ca Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Thu, 12 Feb 2015 17:54:15 -0800 Subject: Accessibility: Ensure fresh accessilbity focused and input focused nodes. Change-Id: Ia3c84284843a415cdbbc2b6a9b06d9ddffbe0e04 --- .../view/accessibility/AccessibilityCache.java | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'core/java') diff --git a/core/java/android/view/accessibility/AccessibilityCache.java b/core/java/android/view/accessibility/AccessibilityCache.java index 52912b1..d0dde00 100644 --- a/core/java/android/view/accessibility/AccessibilityCache.java +++ b/core/java/android/view/accessibility/AccessibilityCache.java @@ -40,6 +40,9 @@ final class AccessibilityCache { private final Object mLock = new Object(); + private long mAccessibilityFocus = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; + private long mInputFocus = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; + private final SparseArray mWindowCache = new SparseArray<>(); @@ -73,9 +76,29 @@ final class AccessibilityCache { synchronized (mLock) { final int eventType = event.getEventType(); switch (eventType) { - case AccessibilityEvent.TYPE_VIEW_FOCUSED: - case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: - case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: + case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { + if (mAccessibilityFocus != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { + refreshCachedNodeLocked(event.getWindowId(), mAccessibilityFocus); + } + mAccessibilityFocus = event.getSourceNodeId(); + refreshCachedNodeLocked(event.getWindowId(), mAccessibilityFocus); + } break; + + case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { + if (mAccessibilityFocus == event.getSourceNodeId()) { + refreshCachedNodeLocked(event.getWindowId(), mAccessibilityFocus); + mAccessibilityFocus = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; + } + } break; + + case AccessibilityEvent.TYPE_VIEW_FOCUSED: { + if (mInputFocus != AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { + refreshCachedNodeLocked(event.getWindowId(), mInputFocus); + } + mInputFocus = event.getSourceNodeId(); + refreshCachedNodeLocked(event.getWindowId(), mInputFocus); + } break; + case AccessibilityEvent.TYPE_VIEW_SELECTED: case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: case AccessibilityEvent.TYPE_VIEW_CLICKED: @@ -268,6 +291,9 @@ final class AccessibilityCache { final int windowId = mNodeCache.keyAt(i); clearNodesForWindowLocked(windowId); } + + mAccessibilityFocus = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; + mInputFocus = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; } } -- cgit v1.1