下面列出了android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#setChecked ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) {
final boolean hasBounds = getBoundsForDay(virtualViewId, mTempRect);
if (!hasBounds) {
// The day is invalid, kill the node.
mTempRect.setEmpty();
node.setContentDescription("");
node.setBoundsInParent(mTempRect);
node.setVisibleToUser(false);
return;
}
node.setText(getDayText(virtualViewId));
node.setContentDescription(getDayDescription(virtualViewId));
node.setBoundsInParent(mTempRect);
final boolean isDayEnabled = isDayEnabled(virtualViewId);
if (isDayEnabled) {
node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
}
node.setEnabled(isDayEnabled);
if (mActivatedDays.isValid() && mActivatedDays.isActivated(virtualViewId)) {
// TODO: This should use activated once that's supported.
node.setChecked(true);
}
}
@Override
protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) {
final boolean hasBounds = getBoundsForDay(virtualViewId, mTempRect);
if (!hasBounds) {
// The day is invalid, kill the node.
mTempRect.setEmpty();
node.setContentDescription("");
node.setBoundsInParent(mTempRect);
node.setVisibleToUser(false);
return;
}
node.setText(getDayText(virtualViewId));
node.setContentDescription(getDayDescription(virtualViewId));
node.setBoundsInParent(mTempRect);
final boolean isDayEnabled = isDayEnabled(virtualViewId);
if (isDayEnabled) {
node.addAction(AccessibilityActionCompat.ACTION_CLICK);
}
node.setEnabled(isDayEnabled);
if (virtualViewId == mActivatedDay) {
// TODO: This should use activated once that's supported.
node.setChecked(true);
}
}
@Override
protected void onPopulateNodeForVirtualView(
int virtualViewId, AccessibilityNodeInfoCompat node) {
final CustomItem item = getItem(virtualViewId);
if (item == null) {
throw new IllegalArgumentException("Invalid virtual view id");
}
// Node and event text and content descriptions are usually
// identical, so we'll use the exact same string as before.
node.setText(item.description);
// Reported bounds should be consistent with those used to draw
// the item in onDraw(). They should also be consistent with the
// hit detection performed in getVirtualViewAt() and
// onTouchEvent().
final Rect bounds = mTempRect;
final int height = getHeight();
final int width = getWidth();
scaleRectF(item.bounds, bounds, width, height);
node.setBoundsInParent(bounds);
// Since the user can tap an item, add the CLICK action. We'll
// need to handle this later in onPerformActionForVirtualView.
node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
// This item has a checked state.
node.setCheckable(true);
node.setChecked(item.checked);
}