下面列出了android.view.accessibility.AccessibilityNodeInfo#setSource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected AccessibilityNodeInfo provideAccessibilityNodeInfo(View parent, Context context) {
final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();
node.setSource(parent, id);
node.setPackageName(context.getPackageName());
node.setClassName(getClassName());
node.setEditable(editable);
node.setViewIdResourceName(idEntry);
node.setVisibleToUser(true);
final Rect absBounds = line.getAbsCoordinates();
if (absBounds != null) {
node.setBoundsInScreen(absBounds);
}
if (TextUtils.getTrimmedLength(text) > 0) {
// TODO: Must checked trimmed length because input fields use 8 empty spaces to
// set width
node.setText(text);
}
return node;
}
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
int left, int top, int right, int bottom) {
AccessibilityNodeInfo info = mInputText.createAccessibilityNodeInfo();
info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
return info;
}
/**
* @see AccessibilityNodeProvider#createAccessibilityNodeInfo(int)
*/
protected AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
if (!mAccessibilityManager.isEnabled() || mNativeObj == 0 || !mFrameInfoInitialized) {
return null;
}
int rootId = nativeGetRootId(mNativeObj);
if (virtualViewId == View.NO_ID) {
virtualViewId = rootId;
}
if (mAccessibilityFocusId == View.NO_ID) {
mAccessibilityFocusId = rootId;
}
final AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(mView);
info.setPackageName(mContentViewCore.getContext().getPackageName());
info.setSource(mView, virtualViewId);
if (nativePopulateAccessibilityNodeInfo(mNativeObj, info, virtualViewId)) {
return info;
} else {
return null;
}
}
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
int left, int top, int right, int bottom) {
AccessibilityNodeInfo info = mInputText.createAccessibilityNodeInfo();
info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
// info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
return info;
}
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText(
int left, int top, int right, int bottom) {
AccessibilityNodeInfo info = mInputText.createAccessibilityNodeInfo();
info.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
info.setVisibleToUser(getVisibility() == View.VISIBLE);
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
return info;
}
/**
* @see AccessibilityNodeProvider#createAccessibilityNodeInfo(int)
*/
protected AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
if (!mAccessibilityManager.isEnabled() || mNativeObj == 0 || !mFrameInfoInitialized) {
return null;
}
int rootId = nativeGetRootId(mNativeObj);
if (virtualViewId == View.NO_ID) {
virtualViewId = rootId;
}
if (mAccessibilityFocusId == View.NO_ID) {
mAccessibilityFocusId = rootId;
}
final AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(mView);
info.setPackageName(mContentViewCore.getContext().getPackageName());
info.setSource(mView, virtualViewId);
if (nativePopulateAccessibilityNodeInfo(mNativeObj, info, virtualViewId)) {
return info;
} else {
return null;
}
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int virtualViewId,
String text, int left, int top, int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(Button.class.getName());
info.setPackageName(mContext.getPackageName());
info.setSource(NumberPicker.this, virtualViewId);
info.setParent(NumberPicker.this);
info.setText(text);
info.setClickable(true);
info.setLongClickable(true);
info.setEnabled(NumberPicker.this.isEnabled());
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
if (mAccessibilityFocusedView != virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (NumberPicker.this.isEnabled()) {
info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
}
return info;
}
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info)
{
super.onInitializeAccessibilityNodeInfo(host, info);
@Nullable final Package viewPackage = PromptView.this.getClass().getPackage();
if (viewPackage != null)
{
info.setPackageName(viewPackage.getName());
}
info.setSource(host);
info.setClickable(true);
info.setEnabled(true);
info.setChecked(false);
info.setFocusable(true);
info.setFocused(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
{
info.setLabelFor(mPromptOptions.getTargetView());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
info.setDismissable(true);
}
info.setContentDescription(mPromptOptions.getContentDescription());
info.setText(mPromptOptions.getContentDescription());
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int virtualViewId,
String text, int left, int top, int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(Button.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(NumberPicker.this, virtualViewId);
info.setParent(NumberPicker.this);
info.setText(text);
info.setClickable(true);
info.setLongClickable(true);
info.setEnabled(NumberPicker.this.isEnabled());
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
// info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
if (mAccessibilityFocusedView != virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (NumberPicker.this.isEnabled()) {
info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
}
return info;
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int virtualViewId,
String text, int left, int top, int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(Button.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(NumberPicker.this, virtualViewId);
info.setParent(NumberPicker.this);
info.setText(text);
info.setClickable(true);
info.setLongClickable(true);
info.setEnabled(NumberPicker.this.isEnabled());
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
info.setVisibleToUser(getVisibility() == View.VISIBLE);
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
if (mAccessibilityFocusedView != virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (NumberPicker.this.isEnabled()) {
info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
}
return info;
}
private AccessibilityNodeInfo createAccessibiltyNodeInfoForInputText() {
AccessibilityNodeInfo info = mInputText.createAccessibilityNodeInfo();
info.setSource(TextPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (mAccessibilityFocusedView != VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == VIRTUAL_VIEW_ID_INPUT) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
return info;
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int virtualViewId,
String text, int left, int top, int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(Button.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(TextPicker.this, virtualViewId);
info.setParent(TextPicker.this);
info.setText(text);
info.setClickable(true);
info.setLongClickable(true);
info.setEnabled(TextPicker.this.isEnabled());
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
// TODO info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
if (mAccessibilityFocusedView != virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (TextPicker.this.isEnabled()) {
info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
}
return info;
}
/**
* @see AccessibilityNodeProvider#createAccessibilityNodeInfo(int)
*/
protected AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
if (!mAccessibilityManager.isEnabled() || mNativeObj == 0) {
return null;
}
int rootId = nativeGetRootId(mNativeObj);
if (virtualViewId == View.NO_ID) {
return createNodeForHost(rootId);
}
if (!isFrameInfoInitialized()) {
return null;
}
final AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(mView);
info.setPackageName(mContentViewCore.getContext().getPackageName());
info.setSource(mView, virtualViewId);
if (virtualViewId == rootId) {
info.setParent(mView);
}
if (nativePopulateAccessibilityNodeInfo(mNativeObj, info, virtualViewId)) {
return info;
} else {
info.recycle();
return null;
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
if (CAN_HIDE_DESCENDANTS) {
super.onInitializeAccessibilityNodeInfo(host, info);
} else {
// Obtain a node for the host, then manually generate the list
// of children to only include non-obscured views.
final AccessibilityNodeInfo superNode = AccessibilityNodeInfo.obtain(info);
super.onInitializeAccessibilityNodeInfo(host, superNode);
info.setSource(host);
final ViewParent parent = host.getParentForAccessibility();
if (parent instanceof View) {
info.setParent((View) parent);
}
copyNodeInfoNoChildren(info, superNode);
superNode.recycle();
addChildrenForAccessibility(info, (ViewGroup) host);
}
info.setClassName(DrawerLayout.class.getName());
// This view reports itself as focusable so that it can intercept
// the back button, but we should prevent this view from reporting
// itself as focusable to accessibility services.
info.setFocusable(false);
info.setFocused(false);
if (C.API_LOLLIPOP) {
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_FOCUS);
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLEAR_FOCUS);
}
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int virtualViewId,
String text, int left, int top, int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(Button.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(NumberPicker.this, virtualViewId);
info.setParent(NumberPicker.this);
info.setText(text);
info.setClickable(true);
info.setLongClickable(true);
info.setEnabled(NumberPicker.this.isEnabled());
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
// TODO info.setVisibleToUser(isVisibleToUser(boundsInParent));
info.setBoundsInParent(boundsInParent);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
if (mAccessibilityFocusedView != virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == virtualViewId) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (NumberPicker.this.isEnabled()) {
info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
}
return info;
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(NumberPicker.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(NumberPicker.this);
if (hasVirtualDecrementButton()) {
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
}
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (hasVirtualIncrementButton()) {
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
}
info.setParent((View) getParentForAccessibility());
info.setEnabled(NumberPicker.this.isEnabled());
info.setScrollable(true);
/** TODO: Figure out compat implementation for this
final float applicationScale =
getContext().getResources().getCompatibilityInfo().applicationScale;
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
boundsInParent.scale(applicationScale);
info.setBoundsInParent(boundsInParent);
info.setVisibleToUser(isVisibleToUser());
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
boundsInScreen.scale(applicationScale);
info.setBoundsInScreen(boundsInScreen);
*/
if (mAccessibilityFocusedView != View.NO_ID) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == View.NO_ID) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (NumberPicker.this.isEnabled()) {
if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
if (getWrapSelectorWheel() || getValue() > getMinValue()) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
}
return info;
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(NumberPicker.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(NumberPicker.this);
if (hasVirtualDecrementButton()) {
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
}
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (hasVirtualIncrementButton()) {
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
}
info.setParent((View) getParentForAccessibility());
info.setEnabled(NumberPicker.this.isEnabled());
info.setScrollable(true);
// TODO: Figure out compat implementation for this final float
// final float applicationScale =
// getContext().getResources().getCompatibilityInfo().applicationScale;
//
// Rect boundsInParent = mTempRect;
// boundsInParent.set(left, top, right, bottom);
// boundsInParent.scale(applicationScale);
// info.setBoundsInParent(boundsInParent);
//
// info.setVisibleToUser(isVisibleToUser());
//
// Rect boundsInScreen = boundsInParent;
// int[] locationOnScreen = mTempArray;
// getLocationOnScreen(locationOnScreen);
// boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
// boundsInScreen.scale(applicationScale);
// info.setBoundsInScreen(boundsInScreen);
if (mAccessibilityFocusedView != View.NO_ID) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == View.NO_ID) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (NumberPicker.this.isEnabled()) {
if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
if (getWrapSelectorWheel() || getValue() > getMinValue()) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
}
return info;
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(NumberPicker.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(NumberPicker.this);
if (hasVirtualDecrementButton()) {
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
}
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (hasVirtualIncrementButton()) {
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
}
info.setParent((View) getParentForAccessibility());
info.setEnabled(NumberPicker.this.isEnabled());
info.setScrollable(true);
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
info.setBoundsInParent(boundsInParent);
info.setVisibleToUser(getVisibility() == View.VISIBLE);
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(boundsInScreen);
if (mAccessibilityFocusedView != View.NO_ID) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == View.NO_ID) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (NumberPicker.this.isEnabled()) {
if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
if (getWrapSelectorWheel() || getValue() > getMinValue()) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
}
return info;
}
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
int right, int bottom) {
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
info.setClassName(TextPicker.class.getName());
info.setPackageName(getContext().getPackageName());
info.setSource(TextPicker.this);
if (hasVirtualDecrementButton()) {
info.addChild(TextPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
}
info.addChild(TextPicker.this, VIRTUAL_VIEW_ID_INPUT);
if (hasVirtualIncrementButton()) {
info.addChild(TextPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
}
info.setParent((View) getParentForAccessibility());
info.setEnabled(TextPicker.this.isEnabled());
info.setScrollable(true);
/** TODO: Figure out compat implementation for this
final float applicationScale =
getContext().getResources().getCompatibilityInfo().applicationScale;
Rect boundsInParent = mTempRect;
boundsInParent.set(left, top, right, bottom);
boundsInParent.scale(applicationScale);
info.setBoundsInParent(boundsInParent);
info.setVisibleToUser(isVisibleToUser());
Rect boundsInScreen = boundsInParent;
int[] locationOnScreen = mTempArray;
getLocationOnScreen(locationOnScreen);
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
boundsInScreen.scale(applicationScale);
info.setBoundsInScreen(boundsInScreen);
*/
if (mAccessibilityFocusedView != View.NO_ID) {
info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
if (mAccessibilityFocusedView == View.NO_ID) {
info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
}
if (TextPicker.this.isEnabled()) {
if (getWrapSelectorWheel() || getValue() < getMaxValue()) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
if (getWrapSelectorWheel() || getValue() > getMinValue()) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
}
return info;
}
@Override
public AccessibilityNodeInfo createAccessibilityNodeInfo(int thumbId) {
AccessibilityNodeInfo info = null;
if (thumbId == View.NO_ID) {
// We are requested to create an AccessibilityNodeInfo describing
// this View, i.e. the root of the virtual sub-tree. Note that the
// host View has an AccessibilityNodeProvider which means that this
// provider is responsible for creating the node info for that root.
info = AccessibilityNodeInfo.obtain(MultiSlider.this);
onInitializeAccessibilityNodeInfo(info);
// Add the virtual children of the root View.
final int childCount = mThumbs.size();
for (int i = 0; i < childCount; i++) {
info.addChild(MultiSlider.this, i);
}
if (mThumbs.size() == 1) {
info.setScrollable(true);
if (Build.VERSION.SDK_INT >= 21) {
info.addAction(ACTION_SET_PROGRESS);
info.addAction(ACTION_SCROLL_BACKWARD);
info.addAction(ACTION_SCROLL_FORWARD);
} else {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
}
} else {
// Find the view that corresponds to the given id.
Thumb thumb = mThumbs.get(thumbId);
if (thumb == null) {
return null;
}
// Obtain and initialize an AccessibilityNodeInfo with
// information about the virtual view.
info = AccessibilityNodeInfo.obtain(MultiSlider.this, thumbId);
info.setClassName(thumb.getClass().getName());
info.setParent(MultiSlider.this);
info.setSource(MultiSlider.this, thumbId);
info.setContentDescription("Multi-Slider thumb no:" + thumbId);
if (Build.VERSION.SDK_INT >= 21) {
info.addAction(ACTION_SET_PROGRESS);
if (thumb.getPossibleMax() > thumb.value) {
info.addAction(ACTION_SCROLL_BACKWARD);
}
if (thumb.getPossibleMax() > thumb.value) {
info.addAction(ACTION_SCROLL_FORWARD);
}
} else {
if (thumb.getPossibleMin() > thumb.value) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
}
if (thumb.getPossibleMax() > thumb.value) {
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
}
if (thumb.getThumb() != null) {
int[] loc = new int[2];
getLocationOnScreen(loc);
Rect rect = thumb.getThumb().copyBounds();
rect.top += loc[1];
rect.left += loc[0];
rect.right += loc[0];
rect.bottom += loc[1];
info.setBoundsInScreen(rect);
//TODO somehow this resuls in [0,0][0,0]. wonder check why
//info.setBoundsInParent(rect);
}
info.setText(thumb.tag + ": " + thumb.value);
info.setEnabled(thumb.isEnabled());
if (Build.VERSION.SDK_INT >= 24) {
info.setImportantForAccessibility(true);
}
info.setVisibleToUser(true);
info.setScrollable(true);
}
return info;
}