Java Code Examples for androidx.core.view.accessibility.AccessibilityNodeInfoCompat#getRangeInfo()

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat#getRangeInfo() . 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: RuleSeekBar.java    From talkback with Apache License 2.0 5 votes vote down vote up
static void setProgress(AccessibilityNodeInfoCompat node, int progress) {
  RangeInfoCompat rangeInfo = node.getRangeInfo();
  if (rangeInfo != null && progress >= 0 && progress <= 100) {
    Bundle args = new Bundle();
    args.putFloat(
        AccessibilityNodeInfo.ACTION_ARGUMENT_PROGRESS_VALUE,
        percentToReal(progress, rangeInfo.getMin(), rangeInfo.getMax()));
    EventId eventId = EVENT_ID_UNTRACKED; // Performance not tracked for menu events.
    PerformActionUtils.performAction(
        node, AccessibilityAction.ACTION_SET_PROGRESS.getId(), args, eventId);
  }
}
 
Example 2
Source File: AccessibilityNodeInfoUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the progress percentage from the node. The value will be in the range [0, 100].
 *
 * @param node The node from which to obtain the progress percentage.
 * @return The progress percentage.
 */
public static float getProgressPercent(@Nullable AccessibilityNodeInfoCompat node) {
  if (node == null) {
    return 0.0f;
  }

  @Nullable final RangeInfoCompat rangeInfo = node.getRangeInfo();
  if (rangeInfo == null) {
    return 0.0f;
  }

  final float maxProgress = rangeInfo.getMax();
  final float minProgress = rangeInfo.getMin();
  final float currentProgress = rangeInfo.getCurrent();
  final float diffProgress = maxProgress - minProgress;
  if (diffProgress <= 0.0f) {
    logError("getProgressPercent", "Range is invalid. [%f, %f]", minProgress, maxProgress);
    return 0.0f;
  }

  if (currentProgress < minProgress) {
    logError(
        "getProgressPercent",
        "Current percent is out of range. Current: %f Range: [%f, %f]",
        currentProgress,
        minProgress,
        maxProgress);
    return 0.0f;
  }

  if (currentProgress > maxProgress) {
    logError(
        "getProgressPercent",
        "Current percent is out of range. Current: %f Range: [%f, %f]",
        currentProgress,
        minProgress,
        maxProgress);
    return 100.0f;
  }

  final float percent = (currentProgress - minProgress) / diffProgress;
  return (100.0f * Math.max(0.0f, Math.min(1.0f, percent)));
}