| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.widget; |
| 18 |
|
| 19 |
import android.os.Bundle; |
| 20 |
import android.view.View; |
| 21 |
import android.view.View.AccessibilityDelegate; |
| 22 |
import android.view.accessibility.AccessibilityEvent; |
| 23 |
import android.view.accessibility.AccessibilityNodeInfo; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class RecyclerViewAccessibilityDelegate extends AccessibilityDelegate { |
| 31 |
final RecyclerView mRecyclerView; |
| 32 |
|
| 33 |
|
| 34 |
public RecyclerViewAccessibilityDelegate(RecyclerView recyclerView) { |
| 35 |
mRecyclerView = recyclerView; |
| 36 |
} |
| 37 |
|
| 38 |
boolean shouldIgnore() { |
| 39 |
return mRecyclerView.hasPendingAdapterUpdates(); |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 44 |
if (super.performAccessibilityAction(host, action, args)) { |
| 45 |
return true; |
| 46 |
} |
| 47 |
if (!shouldIgnore() && mRecyclerView.getLayoutManager() != null) { |
| 48 |
return mRecyclerView.getLayoutManager().performAccessibilityAction(action, args); |
| 49 |
} |
| 50 |
|
| 51 |
return false; |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 56 |
super.onInitializeAccessibilityNodeInfo(host, info); |
| 57 |
info.setClassName(RecyclerView.class.getName()); |
| 58 |
if (!shouldIgnore() && mRecyclerView.getLayoutManager() != null) { |
| 59 |
mRecyclerView.getLayoutManager().onInitializeAccessibilityNodeInfo(info); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 65 |
super.onInitializeAccessibilityEvent(host, event); |
| 66 |
event.setClassName(RecyclerView.class.getName()); |
| 67 |
if (host instanceof RecyclerView && !shouldIgnore()) { |
| 68 |
RecyclerView rv = (RecyclerView) host; |
| 69 |
if (rv.getLayoutManager() != null) { |
| 70 |
rv.getLayoutManager().onInitializeAccessibilityEvent(event); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public AccessibilityDelegate getItemDelegate() { |
| 81 |
return mItemDelegate; |
| 82 |
} |
| 83 |
|
| 84 |
final AccessibilityDelegate mItemDelegate = new AccessibilityDelegate() { |
| 85 |
@Override |
| 86 |
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 87 |
super.onInitializeAccessibilityNodeInfo(host, info); |
| 88 |
if (!shouldIgnore() && mRecyclerView.getLayoutManager() != null) { |
| 89 |
mRecyclerView.getLayoutManager() |
| 90 |
.onInitializeAccessibilityNodeInfoForItem(host, info); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
@Override |
| 95 |
public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 96 |
if (super.performAccessibilityAction(host, action, args)) { |
| 97 |
return true; |
| 98 |
} |
| 99 |
if (!shouldIgnore() && mRecyclerView.getLayoutManager() != null) { |
| 100 |
return mRecyclerView.getLayoutManager() |
| 101 |
.performAccessibilityActionForItem(host, action, args); |
| 102 |
} |
| 103 |
return false; |
| 104 |
} |
| 105 |
}; |
| 106 |
} |
| 107 |
|