Java Code Examples for android.view.accessibility.AccessibilityNodeInfo#RangeInfo

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#RangeInfo . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProgressBar.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @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);
    }
}
 
Example 2
Source File: VolumeSlider.java    From talkback with Apache License 2.0 5 votes vote down vote up
@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);
}