下面列出了android.view.accessibility.AccessibilityNodeInfo#setRangeInfo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** @hide */
@Override
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfoInternal(info);
if (!isIndeterminate()) {
AccessibilityNodeInfo.RangeInfo rangeInfo = AccessibilityNodeInfo.RangeInfo.obtain(
AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT, getMin(), getMax(),
getProgress());
info.setRangeInfo(rangeInfo);
}
}
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
info.setClassName(ProgressBar.class.getName());
AudioManager audioManager =
(AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if ((audioManager == null) || (VERSION.SDK_INT < VERSION_CODES.N)) {
return;
}
// Setting the range info on a device pre-N causes the volume percent to be always announced
// as "0 percent." Not setting the range info on M-devices results in the percentage
// corresponding to the volume slider to be announced. This is slightly different from the
// actual volume percentage due to how progress bars are set. Therefore, we should prefer the
// range info spoken feedback when possible, but when not available (i.e. on M-devices) use
// the spoken feedback corresponding to the progress bar progress instead.
float minVolume = audioManager.getStreamMinVolume(volumeStreamType);
float maxVolume = audioManager.getStreamMaxVolume(volumeStreamType);
float currentVolume = audioManager.getStreamVolume(volumeStreamType);
// Note that this corresponds to the actual volume percentage given by the Volume Settings
// page, which may be different than what TalkBack uses. Volume Settings calculates percentage
// of total volume and not percentage of the valid volume range, otherwise we would subtract
// minimum volume from the current volume.
float percent = ((currentVolume) / (maxVolume - minVolume)) * 100;
AccessibilityNodeInfo.RangeInfo rangeInfo =
AccessibilityNodeInfo.RangeInfo.obtain(RangeInfo.RANGE_TYPE_PERCENT, 0, 100, percent);
info.setRangeInfo(rangeInfo);
}
@Override
protected void setAccessibilityNodeInfoRangeInfo(AccessibilityNodeInfo node,
int rangeType, float min, float max, float current) {
node.setRangeInfo(AccessibilityNodeInfo.RangeInfo.obtain(
rangeType, min, max, current));
}