Skip to content

Instantly share code, notes, and snippets.

@ataulm
Created August 14, 2020 10:56
Show Gist options
  • Select an option

  • Save ataulm/ccf2dc796992faaf70674e3f9254b8be to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

khsbory commented Aug 24, 2020 via email

@ataulm
Copy link
Copy Markdown
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