androidx.core.view.accessibility.AccessibilityNodeInfoCompat.RangeInfoCompat Java Examples

The following examples show how to use androidx.core.view.accessibility.AccessibilityNodeInfoCompat.RangeInfoCompat. 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: NodeVariables.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public int getEnum(int variableId) {
  switch (variableId) {
    case NODE_ROLE:
      return mRole;
    case NODE_LIVE_REGION:
      return mNode.getLiveRegion();
    case NODE_WINDOW_TYPE:
      return AccessibilityNodeInfoUtils.getWindowType(mNode);
    case NODE_RANGE_INFO_TYPE:
      {
        RangeInfoCompat rangeInfo = mNode.getRangeInfo();
        return (rangeInfo == null) ? Compositor.RANGE_INFO_UNDEFINED : rangeInfo.getType();
      }
    default: // fall out
  }
  return mParentVariables.getEnum(variableId);
}
 
Example #2
Source File: RuleSeekBar.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
  // Verify that node is OK and get the current seek control level first.
  final RangeInfoCompat rangeInfo = seekBar.getRangeInfo();
  if (rangeInfo == null) {
    return false;
  }

  oldValue = realToPercent(rangeInfo.getCurrent(), rangeInfo.getMin(), rangeInfo.getMax());
  if (showDialog() != null) {
    editText.setText(Integer.toString(oldValue));
    editText.setOnEditorActionListener(
        (v, actionId, event) -> {
          if (actionId == EditorInfo.IME_ACTION_DONE) {
            submitDialog();
            return true;
          }
          return false;
        });
  }
  return true;
}
 
Example #3
Source File: BaseSlider.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPopulateNodeForVirtualView(
    int virtualViewId, AccessibilityNodeInfoCompat info) {

  info.addAction(AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_SET_PROGRESS);

  List<Float> values = slider.getValues();
  final float value = values.get(virtualViewId);
  float valueFrom = slider.getValueFrom();
  float valueTo = slider.getValueTo();

  if (slider.isEnabled()) {
    if (value > valueFrom) {
      info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
    }
    if (value < valueTo) {
      info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
    }
  }

  info.setRangeInfo(RangeInfoCompat.obtain(RANGE_TYPE_FLOAT, valueFrom, valueTo, value));
  info.setClassName(SeekBar.class.getName());
  StringBuilder contentDescription = new StringBuilder();
  // Add the content description of the slider.
  if (slider.getContentDescription() != null) {
    contentDescription.append(slider.getContentDescription()).append(",");
  }
  // Add the range to the content description.
  if (values.size() > 1) {
    contentDescription.append(startOrEndDescription(virtualViewId));
    contentDescription.append(slider.formatValue(value));
  }
  info.setContentDescription(contentDescription.toString());

  slider.updateBoundsForVirturalViewId(virtualViewId, virtualViewBounds);
  info.setBoundsInParent(virtualViewBounds);
}
 
Example #4
Source File: NodeVariables.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public double getNumber(int variableId) {
  switch (variableId) {
    case NODE_RANGE_CURRENT_VALUE:
      {
        RangeInfoCompat rangeInfo = mNode.getRangeInfo();
        return (rangeInfo == null) ? 0 : rangeInfo.getCurrent();
      }
    case NODE_PROGRESS_PERCENT:
      return AccessibilityNodeInfoUtils.getProgressPercent(mNode);
    default:
      return mParentVariables.getNumber(variableId);
  }
}
 
Example #5
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 #6
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)));
}