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 15, 2020

Hi, my name is Hyongsop Kim from Korea and accessibility consultant.
I read your blod post that android custom view accessible article.
I learned a lot from your posting that even a Cambus view can be implemented so that TalkBack can read the view.
Could you share the entire sample app project for my study?
I'd like to build your project on my phone and experience it in person, see each of the source codes, and learn more deeply.
My email address is hyongsop.kim@nvisions.co.kr.
Thank you.

@ataulm
Copy link
Author

ataulm commented Aug 15, 2020

Hi Hyongsop Kim, you can find the full project here https://github.com/ataulm/android-skeleton/compare/virtual-views-a11y?expand=1

@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