Skip to content

Instantly share code, notes, and snippets.

@ataulm
Created August 14, 2020 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ataulm/ccf2dc796992faaf70674e3f9254b8be to your computer and use it in GitHub Desktop.
Save ataulm/ccf2dc796992faaf70674e3f9254b8be to your computer and use it in GitHub Desktop.
private val intervalBounds = Rect()
@Suppress("DEPRECATION") // setBoundsInParent is required by [ExploreByTouchHelper]
override fun onPopulateNodeForVirtualView(virtualViewId: Int, node: AccessibilityNodeInfoCompat) {
node.className = RatingsHistogramView::class.simpleName
node.contentDescription = "content desc $virtualViewId"
updateBoundsForInterval(virtualViewId)
node.setBoundsInParent(intervalBounds)
}
private fun updateBoundsForInterval(index: Int) {
val histogram = this@RatingsHistogramView.ratingsHistogram ?: return
val intervalWidth = width.toFloat() / histogram.intervals.size
val left = index * intervalWidth
intervalBounds.left = (left + 2).roundToInt()
intervalBounds.top = (height - (histogram.intervals[index].weight * height)).roundToInt()
intervalBounds.right = (left + intervalWidth - 2).roundToInt()
intervalBounds.bottom = height
}
@khsbory
Copy link

khsbory commented Aug 24, 2020 via email

@ataulm
Copy link
Author

ataulm commented Aug 24, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment