Skip to content

Commit

Permalink
Make chart bars not clickable on the TRAFFIC tab for accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
irfano committed Mar 2, 2024
1 parent 411dbf9 commit 668dd97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ class TrafficBarChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder(
if (hasData(item.entries)) {
chart.post {
val cutContentDescriptions = takeEntriesWithinGraphWidth(barCount, item.entryContentDescriptions)
accessibilityHelper = BarChartAccessibilityHelper(
chart,
contentDescriptions = cutContentDescriptions,
accessibilityEvent = accessibilityEvent
)
accessibilityHelper = BarChartAccessibilityHelper(chart, cutContentDescriptions)

ViewCompat.setAccessibilityDelegate(chart, accessibilityHelper)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
class BarChartAccessibilityHelper(
private val barChart: BarChart,
private val contentDescriptions: List<String>,
private val accessibilityEvent: BarChartAccessibilityEvent
private val accessibilityEvent: BarChartAccessibilityEvent? = null
) : ExploreByTouchHelper(barChart) {
private val dataSet: IBarDataSet = barChart.data.dataSets.first()

Expand Down Expand Up @@ -51,7 +51,7 @@ class BarChartAccessibilityHelper(
when (action) {
AccessibilityNodeInfoCompat.ACTION_CLICK -> {
val entry = dataSet.getEntryForIndex(virtualViewId)
accessibilityEvent.onHighlight(entry, virtualViewId)
accessibilityEvent?.onHighlight(entry, virtualViewId)
return true
}
}
Expand All @@ -74,7 +74,7 @@ class BarChartAccessibilityHelper(
}
}

node.addAction(AccessibilityActionCompat.ACTION_CLICK)
accessibilityEvent?.let { node.addAction(AccessibilityActionCompat.ACTION_CLICK) }
val entryRectF = barChart.getBarBounds(dataSet.getEntryForIndex(virtualViewId))
val entryRect = Rect()
entryRectF.round(entryRect)
Expand Down

0 comments on commit 668dd97

Please sign in to comment.