Java Code Examples for androidx.core.view.accessibility.AccessibilityNodeInfoCompat.RangeInfoCompat#getCurrent()
The following examples show how to use
androidx.core.view.accessibility.AccessibilityNodeInfoCompat.RangeInfoCompat#getCurrent() .
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 | 5 votes |
@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 2
Source File: AccessibilityNodeInfoUtils.java From talkback with Apache License 2.0 | 4 votes |
/** * 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))); }