下面列出了android.view.View#setAccessibilityDelegate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void cleanup() {
for (final Map.Entry<View, TrackingAccessibilityDelegate> entry :
mWatching.entrySet()) {
final View v = entry.getKey();
final TrackingAccessibilityDelegate toCleanup = entry.getValue();
final View.AccessibilityDelegate currentViewDelegate = getOldDelegate(v);
if (currentViewDelegate == toCleanup) {
v.setAccessibilityDelegate(toCleanup.getRealDelegate());
} else if (currentViewDelegate instanceof TrackingAccessibilityDelegate) {
final TrackingAccessibilityDelegate newChain =
(TrackingAccessibilityDelegate) currentViewDelegate;
newChain.removeFromDelegateChain(toCleanup);
} else {
// Assume we've been replaced, zeroed out, or for some other reason we're
// already gone.
// (This isn't too weird, for example, it's expected when views get recycled)
}
}
mWatching.clear();
}
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
super.addView(child, index, params);
final View openDrawer = findOpenDrawer();
if (openDrawer != null || isDrawerView(child)) {
// A drawer is already open or the new view is a drawer, so the
// new view should start out hidden.
child.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
} else {
// Otherwise this is a content view and no drawer is open, so the
// new view should start out visible.
child.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
}
// We only need a delegate here if the framework doesn't understand
// NO_HIDE_DESCENDANTS importance.
if (!CAN_HIDE_DESCENDANTS) {
child.setAccessibilityDelegate(mChildAccessibilityDelegate);
}
}
@SuppressLint({"NewApi"})
public void reclaimViews(List<View> views) {
int childCount = getChildCount();
RecyclerListener listener = RecycleBin.access$2200(this.mRecycler);
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (lp != null && this.mRecycler.shouldRecycleViewType(lp.viewType)) {
views.add(child);
if (VERSION.SDK_INT >= 14) {
child.setAccessibilityDelegate(null);
}
if (listener != null) {
listener.onMovedToScrapHeap(child);
}
}
}
this.mRecycler.reclaimScrapViews(views);
removeAllViewsInLayout();
}
/** Move all views remaining in activeViews to scrapViews. */
void scrapActiveViews() {
final View[] activeViews = this.activeViews;
final int[] activeViewTypes = this.activeViewTypes;
final boolean multipleScraps = viewTypeCount > 1;
SparseArray<View> scrapViews = currentScrapViews;
final int count = activeViews.length;
for (int i = count - 1; i >= 0; i--) {
final View victim = activeViews[i];
if (victim != null) {
int whichScrap = activeViewTypes[i];
activeViews[i] = null;
activeViewTypes[i] = -1;
if (!shouldRecycleViewType(whichScrap)) {
continue;
}
if (multipleScraps) {
scrapViews = this.scrapViews[whichScrap];
}
scrapViews.put(i, victim);
victim.setAccessibilityDelegate(null);
}
}
pruneScrapViews();
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap
* The view to add
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void addScrapView(View scrap, int position, int viewType) {
// create a new Scrap
Scrap item = new Scrap(scrap, true);
if (viewTypeCount == 1) {
currentScraps.put(position, item);
} else {
scraps[viewType].put(position, item);
}
if (Build.VERSION.SDK_INT >= 14) {
scrap.setAccessibilityDelegate(null);
}
}
/**
* Move all views remaining in activeViews to scrapViews.
*/
void scrapActiveViews() {
final View[] activeViews = this.activeViews;
final int[] activeViewTypes = this.activeViewTypes;
final boolean multipleScraps = viewTypeCount > 1;
SparseArray<View> scrapViews = currentScrapViews;
final int count = activeViews.length;
for (int i = count - 1; i >= 0; i--) {
final View victim = activeViews[i];
if (victim != null) {
int whichScrap = activeViewTypes[i];
activeViews[i] = null;
activeViewTypes[i] = -1;
if (!shouldRecycleViewType(whichScrap)) {
continue;
}
if (multipleScraps) {
scrapViews = this.scrapViews[whichScrap];
}
scrapViews.put(i, victim);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
victim.setAccessibilityDelegate(null);
}
}
}
pruneScrapViews();
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap The view to add
*/
void addScrapView(View scrap, int position, int viewType) {
if (viewTypeCount == 1) {
currentScrapViews.put(position, scrap);
} else {
scrapViews[viewType].put(position, scrap);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
scrap.setAccessibilityDelegate(null);
}
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap The view to add
*/
void addScrapView(View scrap, int position, int viewType) {
if (viewTypeCount == 1) {
currentScrapViews.put(position, scrap);
} else {
scrapViews[viewType].put(position, scrap);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
scrap.setAccessibilityDelegate(null);
}
}
/** Move all views remaining in activeViews to scrapViews. */
void scrapActiveViews() {
final View[] activeViews = this.activeViews;
final int[] activeViewTypes = this.activeViewTypes;
final boolean multipleScraps = viewTypeCount > 1;
SparseArray<View> scrapViews = currentScrapViews;
final int count = activeViews.length;
for (int i = count - 1; i >= 0; i--) {
final View victim = activeViews[i];
if (victim != null) {
int whichScrap = activeViewTypes[i];
activeViews[i] = null;
activeViewTypes[i] = -1;
if (!shouldRecycleViewType(whichScrap)) {
continue;
}
if (multipleScraps) {
scrapViews = this.scrapViews[whichScrap];
}
scrapViews.put(i, victim);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
victim.setAccessibilityDelegate(null);
}
}
}
pruneScrapViews();
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap
* The view to add
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void addScrapView(View scrap, int position, int viewType) {
// create a new Scrap
Scrap item = new Scrap(scrap, true);
if (viewTypeCount == 1) {
currentScraps.put(position, item);
} else {
scraps[viewType].put(position, item);
}
if (Build.VERSION.SDK_INT >= 14) {
scrap.setAccessibilityDelegate(null);
}
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap
* The view to add
*/
@SuppressLint("NewApi")
void addScrapView(View scrap, int position, int viewType) {
if (viewTypeCount == 1) {
currentScrapViews.put(position, scrap);
} else {
scrapViews[viewType].put(position, scrap);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
scrap.setAccessibilityDelegate(null);
}
}
/** Move all views remaining in activeViews to scrapViews. */
@SuppressLint("NewApi")
void scrapActiveViews() {
final View[] activeViews = this.activeViews;
final int[] activeViewTypes = this.activeViewTypes;
final boolean multipleScraps = viewTypeCount > 1;
SparseArray<View> scrapViews = currentScrapViews;
final int count = activeViews.length;
for (int i = count - 1; i >= 0; i--) {
final View victim = activeViews[i];
if (victim != null) {
int whichScrap = activeViewTypes[i];
activeViews[i] = null;
activeViewTypes[i] = -1;
if (!shouldRecycleViewType(whichScrap)) {
continue;
}
if (multipleScraps) {
scrapViews = this.scrapViews[whichScrap];
}
scrapViews.put(i, victim);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
victim.setAccessibilityDelegate(null);
}
}
}
pruneScrapViews();
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap The view to add
*/
void addScrapView(View scrap, int position, int viewType) {
if (viewTypeCount == 1) {
currentScrapViews.put(position, scrap);
} else {
scrapViews[viewType].put(position, scrap);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
scrap.setAccessibilityDelegate(null);
}
}
/** Move all views remaining in activeViews to scrapViews. */
void scrapActiveViews() {
final View[] activeViews = this.activeViews;
final int[] activeViewTypes = this.activeViewTypes;
final boolean multipleScraps = viewTypeCount > 1;
SparseArray<View> scrapViews = currentScrapViews;
final int count = activeViews.length;
for (int i = count - 1; i >= 0; i--) {
final View victim = activeViews[i];
if (victim != null) {
int whichScrap = activeViewTypes[i];
activeViews[i] = null;
activeViewTypes[i] = -1;
if (!shouldRecycleViewType(whichScrap)) {
continue;
}
if (multipleScraps) {
scrapViews = this.scrapViews[whichScrap];
}
scrapViews.put(i, victim);
victim.setAccessibilityDelegate(null);
}
}
pruneScrapViews();
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap
* The view to add
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void addScrapView(View scrap, int position, int viewType) {
// create a new Scrap
Scrap item = new Scrap(scrap, true);
if (viewTypeCount == 1) {
currentScraps.put(position, item);
} else {
scraps[viewType].put(position, item);
}
if (Build.VERSION.SDK_INT >= 14) {
scrap.setAccessibilityDelegate(null);
}
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap The view to add
*/
void addScrapView(View scrap, int position, int viewType) {
if (viewTypeCount == 1) {
currentScrapViews.put(position, scrap);
} else {
scrapViews[viewType].put(position, scrap);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
scrap.setAccessibilityDelegate(null);
}
}
/**
* Put a view into the ScrapViews list. These views are unordered.
*
* @param scrap The view to add
*/
void addScrapView(View scrap, int position, int viewType) {
if (viewTypeCount == 1) {
currentScrapViews.put(position, scrap);
} else {
scrapViews[viewType].put(position, scrap);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
scrap.setAccessibilityDelegate(null);
}
}
public static void setAccessibilityDelegate(View v, Object delegate) {
v.setAccessibilityDelegate((AccessibilityDelegate) delegate);
}
public static void a(View view, Object obj)
{
view.setAccessibilityDelegate((android.view.View.AccessibilityDelegate)obj);
}
public static void setAccessibilityDelegate(View v, Object delegate) {
v.setAccessibilityDelegate((AccessibilityDelegate) delegate);
}