Use our Locale instead of java.util.Locale everywhere
Here is the result of LocaleList construction cost:
benchmark: 16,409 ns LocaleListBenchmark.create[en-US]
benchmark: 32,470 ns LocaleListBenchmark.create[en-US,ja-JP]
benchmark: 47,791 ns LocaleListBenchmark.create[en-US,ja-JP,zh-CH]
benchmark: 62,738 ns LocaleListBenchmark.create[en-US,ja-JP,zh-CH,zh-TW]
benchmark: 77,677 ns LocaleListBenchmark.create[en-US,ja-JP,zh-CH,zh-TW,sr-Latn-SR]
Bug: 139312607
Bug: 122478208
Test: ./gradlew test
Change-Id: I8f20910323e6338fe483efdc65405b2a587e7715
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/MultiParagraphIntegrationTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/MultiParagraphIntegrationTest.kt
index 7f8dc48..3dd32a6 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/MultiParagraphIntegrationTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/MultiParagraphIntegrationTest.kt
@@ -42,7 +42,6 @@
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import java.util.Locale
@RunWith(JUnit4::class)
@SmallTest
@@ -2484,7 +2483,7 @@
textStyles: List<AnnotatedString.Item<TextStyle>> = listOf(),
paragraphStyles: List<AnnotatedString.Item<ParagraphStyle>> = listOf(),
fontFamily: FontFamily = fontFamilyMeasureFont,
- locale: Locale? = null,
+ localeList: LocaleList? = null,
textStyle: TextStyle? = null,
density: Density? = null,
layoutDirection: LayoutDirection = LayoutDirection.Ltr,
@@ -2499,7 +2498,7 @@
textStyle = TextStyle(
fontFamily = fontFamily,
fontSize = fontSize,
- locale = locale
+ localeList = localeList
).merge(textStyle),
paragraphStyle = ParagraphStyle(
textIndent = textIndent,
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntegrationTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntegrationTest.kt
index e7b570f..902b432 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntegrationTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/ParagraphIntegrationTest.kt
@@ -54,7 +54,6 @@
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.mockito.Mockito.mock
-import java.util.Locale
import kotlin.math.roundToInt
@RunWith(JUnit4::class)
@@ -1607,19 +1606,19 @@
val fontSizeInPx = fontSize.toPx().value
val locales = arrayOf(
// duplicate ja is on purpose
- Locale("ja"),
- Locale("ja"),
- Locale("zh", "CN"),
- Locale("zh", "TW")
+ LocaleList("ja"),
+ LocaleList("ja"),
+ LocaleList("zh-CN"),
+ LocaleList("zh-TW")
)
- val bitmaps = locales.map { locale ->
+ val bitmaps = locales.map { localeList ->
val paragraph = Paragraph(
text = text,
textStyles = listOf(),
style = TextStyle(
fontSize = fontSize,
- locale = locale
+ localeList = localeList
),
paragraphStyle = ParagraphStyle(),
density = defaultDensity,
@@ -3271,7 +3270,7 @@
lineHeight: Float? = null,
textStyles: List<AnnotatedString.Item<TextStyle>> = listOf(),
fontFamily: FontFamily = fontFamilyMeasureFont,
- locale: Locale? = null,
+ localeList: LocaleList? = null,
textStyle: TextStyle? = null,
density: Density? = null,
textDirectionAlgorithm: TextDirectionAlgorithm? = null,
@@ -3283,7 +3282,7 @@
style = TextStyle(
fontFamily = fontFamily,
fontSize = fontSize,
- locale = locale
+ localeList = localeList
).merge(textStyle),
paragraphStyle = ParagraphStyle(
textIndent = textIndent,
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/platform/AndroidParagraphTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/platform/AndroidParagraphTest.kt
index de877a2..8c017e3 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/platform/AndroidParagraphTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/platform/AndroidParagraphTest.kt
@@ -49,6 +49,8 @@
import androidx.ui.text.matchers.hasSpanOnTop
import androidx.ui.text.AnnotatedString
import androidx.ui.painting.Shadow
+import androidx.ui.text.Locale
+import androidx.ui.text.LocaleList
import androidx.ui.text.ParagraphStyle
import androidx.ui.text.TestFontResourceLoader
import androidx.ui.text.TextStyle
@@ -70,7 +72,6 @@
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import java.util.Locale
import kotlin.math.ceil
@RunWith(JUnit4::class)
@@ -482,8 +483,8 @@
@Test
fun testAnnotatedString_setLocaleOnWholeText() {
val text = "abcde"
- val locale = Locale("en", "US")
- val textStyle = TextStyle(locale = locale)
+ val localeList = LocaleList("en-US")
+ val textStyle = TextStyle(localeList = localeList)
val paragraph = simpleParagraph(
text = text,
@@ -497,8 +498,8 @@
@Test
fun testAnnotatedString_setLocaleOnPartText() {
val text = "abcde"
- val locale = Locale("en", "US")
- val textStyle = TextStyle(locale = locale)
+ val localeList = LocaleList("en-US")
+ val textStyle = TextStyle(localeList = localeList)
val paragraph = simpleParagraph(
text = text,
@@ -512,8 +513,8 @@
@Test
fun testAnnotatedString_setLocaleTwice_lastOneOverwrite() {
val text = "abcde"
- val textStyle = TextStyle(locale = Locale("en", "US"))
- val textStyleOverwrite = TextStyle(locale = Locale("ja", "JP"))
+ val textStyle = TextStyle(localeList = LocaleList("en-US"))
+ val textStyleOverwrite = TextStyle(localeList = LocaleList("ja-JP"))
val paragraph = simpleParagraph(
text = text,
@@ -1068,16 +1069,17 @@
@Test
fun testTextStyle_locale_appliedOnTextPaint() {
- val systemLocale = java.util.Locale.JAPANESE
- val locale = Locale(systemLocale.language, systemLocale.country)
+ val platformLocale = java.util.Locale.JAPANESE
+ val localeList = LocaleList(platformLocale.toLanguageTag())
val paragraph = simpleParagraph(
text = "",
- textStyle = TextStyle(locale = locale)
+ textStyle = TextStyle(localeList = localeList)
)
paragraph.layout(ParagraphConstraints(width = 0.0f))
- assertThat(paragraph.textPaint.textLocale, equalTo(systemLocale))
+ assertThat(paragraph.textPaint.textLocale.language, equalTo(platformLocale.language))
+ assertThat(paragraph.textPaint.textLocale.country, equalTo(platformLocale.country))
}
@Test
@@ -1224,11 +1226,11 @@
@Test
fun locale_isSetOnParagraphImpl_enUS() {
- val locale = Locale("en", "US")
+ val localeList = LocaleList("en-US")
val text = "abc"
val paragraph = simpleParagraph(
text = text,
- textStyle = TextStyle(locale = locale)
+ textStyle = TextStyle(localeList = localeList)
)
paragraph.layout(ParagraphConstraints(width = Float.MAX_VALUE))
@@ -1238,11 +1240,11 @@
@Test
fun locale_isSetOnParagraphImpl_jpJP() {
- val locale = Locale("ja", "JP")
+ val localeList = LocaleList("ja-JP")
val text = "abc"
val paragraph = simpleParagraph(
text = text,
- textStyle = TextStyle(locale = locale)
+ textStyle = TextStyle(localeList = localeList)
)
paragraph.layout(ParagraphConstraints(width = Float.MAX_VALUE))
@@ -1252,11 +1254,11 @@
@Test
fun locale_noCountryCode_isSetOnParagraphImpl() {
- val locale = Locale("ja")
+ val localeList = LocaleList("ja")
val text = "abc"
val paragraph = simpleParagraph(
text = text,
- textStyle = TextStyle(locale = locale)
+ textStyle = TextStyle(localeList = localeList)
)
paragraph.layout(ParagraphConstraints(width = Float.MAX_VALUE))