Skip to content

Commit

Permalink
Merge pull request #1289 from minvws/4363-bold
Browse files Browse the repository at this point in the history
don't mark bold as heading for Talkback users
  • Loading branch information
BartNijland91 authored May 18, 2022
2 parents 691057e + d6c960f commit f86196d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 2 additions & 10 deletions design/src/main/java/nl/rijksoverheid/ctr/design/ext/SpannedExt.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package nl.rijksoverheid.ctr.design.ext

import android.graphics.Typeface
import android.text.Spanned
import android.text.style.BulletSpan
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import androidx.core.text.getSpans
import nl.rijksoverheid.ctr.design.spans.BulletPointSpan

Expand Down Expand Up @@ -50,17 +48,11 @@ fun Spanned.substring(start: Int, end: Int): Spanned {

/**
* Determines whether a Spanned object is a heading
* This is the case in two situations:
* (1) If the Spanned object contains a StyleSpan with Typeface.Bold for the whole length
* (2) If the Spanned object contains one or more RelativeSizeSpans with a size change (= h1-h6)
* If the Spanned object contains one or more RelativeSizeSpans with a size change (= h1-h6)
*/
val Spanned.isHeading: Boolean
get() {
return getSpans<StyleSpan>().any { span ->
return span.style == Typeface.BOLD &&
getSpanStart(span) == 0 &&
getSpanEnd(span) == length
} || getSpans<RelativeSizeSpan>().any { span ->
return getSpans<RelativeSizeSpan>().any { span ->
return span.sizeChange > 0
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.children
import androidx.test.core.app.ApplicationProvider
import nl.rijksoverheid.ctr.design.widgets.HtmlTextViewWidget
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.koin.test.AutoCloseKoinTest
Expand Down Expand Up @@ -53,9 +54,18 @@ class HtmlTextViewWidgetTest : AutoCloseKoinTest() {
assertEquals(widget.children.filter { ViewCompat.isAccessibilityHeading(it) }.count(), 0) // 2: Heading 1 + Heading 2
assertEquals(widget.childCount, 1) // 5: Heading + Text + Linebreak + Heading + Text

widget.setHtmlText("<h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5><h6>Heading 6</h6>")
assertEquals(widget.children.filter { ViewCompat.isAccessibilityHeading(it) }.count(), 0) // 6: h1, h2, h3, h4, h5, h6
assertEquals(widget.childCount, 1) // 7: Heading + Heading + Heading + Heading + Heading + Heading + Linebreak
widget.setHtmlText("<h1>Heading 1</h1>")
assertTrue(ViewCompat.isAccessibilityHeading(widget.getChildAt(0)))
widget.setHtmlText("<h2>Heading 1</h2>")
assertTrue(ViewCompat.isAccessibilityHeading(widget.getChildAt(0)))
widget.setHtmlText("<h3>Heading 1</h3>")
assertTrue(ViewCompat.isAccessibilityHeading(widget.getChildAt(0)))
widget.setHtmlText("<h4>Heading 1</h4>")
assertTrue(ViewCompat.isAccessibilityHeading(widget.getChildAt(0)))
widget.setHtmlText("<h5>Heading 1</h5>")
assertTrue(ViewCompat.isAccessibilityHeading(widget.getChildAt(0)))
widget.setHtmlText("<h6>Heading 1</h6>")
assertTrue(ViewCompat.isAccessibilityHeading(widget.getChildAt(0)))

// List test
widget.setHtmlText("<ul><li>List item 1</li><li>List item 2</li></ul>")
Expand Down

0 comments on commit f86196d

Please sign in to comment.