From 8c222cabb631082f21abfa3abcd56c5ec62aee9a Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Tue, 24 May 2022 14:13:29 +0200 Subject: [PATCH 1/2] Define the SystemUI typography This CL defines the material typography that is going to be used by Compose code in SystemUI. Most of the code from this CL was forked from the Google Material implementation in google3 [1, 2, 3, 4], so that our typography is consistent from 1P apps (and with the Google Material spec). For this reason, I changed only what I had to + reformatted the files using ktfmt. The direct references to "google-sans" will be removed in http://ag/19500381 to keep this CL as close as possible from the google3 classes. Note that this new typography might not be 100% consistent with the current text styles used in SystemUI, given that they are not consistent with the new M3 spec. Those kind of inconsistencies will be fixed later, as we figure out how SystemUI is going to be aligned with M3 in general (and not w.r.t. Compose in particular). [1] http://google3/java/com/google/android/libraries/material/compose/Typography.kt [2] http://google3/java/com/google/android/libraries/material/compose/tools/tokens/library/md/first_party/TypographyTokens.kt [3] http://google3/java/com/google/android/libraries/material/compose/tools/tokens/library/md/first_party/TypeScaleTokens.kt [4] http://google3/java/com/google/android/libraries/material/compose/tools/tokens/library/md/first_party/asynctype/TypefaceTokens.kt Bug: 230605885 Test: Manual Change-Id: I116ef944c79e09fb0d4b0914c3da71a946fc169a --- .../systemui/compose/theme/SystemUITheme.kt | 7 +- .../theme/typography/SystemUITypography.kt | 45 ++++++ .../theme/typography/TypeScaleTokens.kt | 97 ++++++++++++ .../theme/typography/TypefaceTokens.kt | 39 +++++ .../theme/typography/TypographyTokens.kt | 142 ++++++++++++++++++ 5 files changed, 326 insertions(+), 4 deletions(-) create mode 100644 packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt create mode 100644 packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt create mode 100644 packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt create mode 100644 packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt index 79e3d3d475a89..de6ada29010ce 100644 --- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt @@ -18,12 +18,12 @@ package com.android.systemui.compose.theme import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Typography import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.platform.LocalContext +import com.android.systemui.compose.theme.typography.SystemUITypography /** The Material 3 theme that should wrap all SystemUI Composables. */ @Composable @@ -33,7 +33,7 @@ fun SystemUITheme( ) { val context = LocalContext.current - // TODO(b/230605885): Define our typography and color scheme. + // TODO(b/230605885): Define our color scheme. val colorScheme = if (isDarkTheme) { dynamicDarkColorScheme(context) @@ -41,9 +41,8 @@ fun SystemUITheme( dynamicLightColorScheme(context) } val androidColorScheme = AndroidColorScheme(context) - val typography = Typography() - MaterialTheme(colorScheme, typography = typography) { + MaterialTheme(colorScheme, typography = SystemUITypography) { CompositionLocalProvider( LocalAndroidColorScheme provides androidColorScheme, ) { diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt new file mode 100644 index 0000000000000..c3208bad598f1 --- /dev/null +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.compose.theme.typography + +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Typography + +/** + * The SystemUI typography. + * + * Do not use directly and call [MaterialTheme.typography] instead to access the different text + * styles. + */ +internal val SystemUITypography = + Typography( + displayLarge = TypographyTokens.DisplayLarge, + displayMedium = TypographyTokens.DisplayMedium, + displaySmall = TypographyTokens.DisplaySmall, + headlineLarge = TypographyTokens.HeadlineLarge, + headlineMedium = TypographyTokens.HeadlineMedium, + headlineSmall = TypographyTokens.HeadlineSmall, + titleLarge = TypographyTokens.TitleLarge, + titleMedium = TypographyTokens.TitleMedium, + titleSmall = TypographyTokens.TitleSmall, + bodyLarge = TypographyTokens.BodyLarge, + bodyMedium = TypographyTokens.BodyMedium, + bodySmall = TypographyTokens.BodySmall, + labelLarge = TypographyTokens.LabelLarge, + labelMedium = TypographyTokens.LabelMedium, + labelSmall = TypographyTokens.LabelSmall, + ) diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt new file mode 100644 index 0000000000000..13f004089d48a --- /dev/null +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.compose.theme.typography + +import androidx.compose.ui.unit.sp + +object TypeScaleTokens { + val BodyLargeFont = TypefaceTokens.Plain + val BodyLargeLineHeight = 24.0.sp + val BodyLargeSize = 16.sp + val BodyLargeTracking = 0.0.sp + val BodyLargeWeight = TypefaceTokens.WeightRegular + val BodyMediumFont = TypefaceTokens.Plain + val BodyMediumLineHeight = 20.0.sp + val BodyMediumSize = 14.sp + val BodyMediumTracking = 0.0.sp + val BodyMediumWeight = TypefaceTokens.WeightRegular + val BodySmallFont = TypefaceTokens.Plain + val BodySmallLineHeight = 16.0.sp + val BodySmallSize = 12.sp + val BodySmallTracking = 0.1.sp + val BodySmallWeight = TypefaceTokens.WeightRegular + val DisplayLargeFont = TypefaceTokens.Brand + val DisplayLargeLineHeight = 64.0.sp + val DisplayLargeSize = 57.sp + val DisplayLargeTracking = 0.0.sp + val DisplayLargeWeight = TypefaceTokens.WeightRegular + val DisplayMediumFont = TypefaceTokens.Brand + val DisplayMediumLineHeight = 52.0.sp + val DisplayMediumSize = 45.sp + val DisplayMediumTracking = 0.0.sp + val DisplayMediumWeight = TypefaceTokens.WeightRegular + val DisplaySmallFont = TypefaceTokens.Brand + val DisplaySmallLineHeight = 44.0.sp + val DisplaySmallSize = 36.sp + val DisplaySmallTracking = 0.0.sp + val DisplaySmallWeight = TypefaceTokens.WeightRegular + val HeadlineLargeFont = TypefaceTokens.Brand + val HeadlineLargeLineHeight = 40.0.sp + val HeadlineLargeSize = 32.sp + val HeadlineLargeTracking = 0.0.sp + val HeadlineLargeWeight = TypefaceTokens.WeightRegular + val HeadlineMediumFont = TypefaceTokens.Brand + val HeadlineMediumLineHeight = 36.0.sp + val HeadlineMediumSize = 28.sp + val HeadlineMediumTracking = 0.0.sp + val HeadlineMediumWeight = TypefaceTokens.WeightRegular + val HeadlineSmallFont = TypefaceTokens.Brand + val HeadlineSmallLineHeight = 32.0.sp + val HeadlineSmallSize = 24.sp + val HeadlineSmallTracking = 0.0.sp + val HeadlineSmallWeight = TypefaceTokens.WeightRegular + val LabelLargeFont = TypefaceTokens.Plain + val LabelLargeLineHeight = 20.0.sp + val LabelLargeSize = 14.sp + val LabelLargeTracking = 0.0.sp + val LabelLargeWeight = TypefaceTokens.WeightMedium + val LabelMediumFont = TypefaceTokens.Plain + val LabelMediumLineHeight = 16.0.sp + val LabelMediumSize = 12.sp + val LabelMediumTracking = 0.1.sp + val LabelMediumWeight = TypefaceTokens.WeightMedium + val LabelSmallFont = TypefaceTokens.Plain + val LabelSmallLineHeight = 16.0.sp + val LabelSmallSize = 11.sp + val LabelSmallTracking = 0.1.sp + val LabelSmallWeight = TypefaceTokens.WeightMedium + val TitleLargeFont = TypefaceTokens.Brand + val TitleLargeLineHeight = 28.0.sp + val TitleLargeSize = 22.sp + val TitleLargeTracking = 0.0.sp + val TitleLargeWeight = TypefaceTokens.WeightRegular + val TitleMediumFont = TypefaceTokens.Plain + val TitleMediumLineHeight = 24.0.sp + val TitleMediumSize = 16.sp + val TitleMediumTracking = 0.0.sp + val TitleMediumWeight = TypefaceTokens.WeightMedium + val TitleSmallFont = TypefaceTokens.Plain + val TitleSmallLineHeight = 20.0.sp + val TitleSmallSize = 14.sp + val TitleSmallTracking = 0.0.sp + val TitleSmallWeight = TypefaceTokens.WeightMedium +} diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt new file mode 100644 index 0000000000000..a17d226f85bbd --- /dev/null +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:OptIn(ExperimentalTextApi::class) + +package com.android.systemui.compose.theme.typography + +import androidx.compose.ui.text.ExperimentalTextApi +import androidx.compose.ui.text.font.DeviceFontFamilyName +import androidx.compose.ui.text.font.Font +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight + +val brandFont = DeviceFontFamilyName("google-sans") +val plainFont = DeviceFontFamilyName("google-sans-text") + +object TypefaceTokens { + + val WeightMedium = FontWeight.Medium + val WeightRegular = FontWeight.Normal + + val Brand = + FontFamily(Font(brandFont, weight = WeightMedium), Font(brandFont, weight = WeightRegular)) + val Plain = + FontFamily(Font(plainFont, weight = WeightMedium), Font(plainFont, weight = WeightRegular)) +} diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt new file mode 100644 index 0000000000000..46ad88923ebec --- /dev/null +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.compose.theme.typography + +import androidx.compose.ui.text.TextStyle + +object TypographyTokens { + val BodyLarge = + TextStyle( + fontFamily = TypeScaleTokens.BodyLargeFont, + fontWeight = TypeScaleTokens.BodyLargeWeight, + fontSize = TypeScaleTokens.BodyLargeSize, + lineHeight = TypeScaleTokens.BodyLargeLineHeight, + letterSpacing = TypeScaleTokens.BodyLargeTracking, + ) + val BodyMedium = + TextStyle( + fontFamily = TypeScaleTokens.BodyMediumFont, + fontWeight = TypeScaleTokens.BodyMediumWeight, + fontSize = TypeScaleTokens.BodyMediumSize, + lineHeight = TypeScaleTokens.BodyMediumLineHeight, + letterSpacing = TypeScaleTokens.BodyMediumTracking, + ) + val BodySmall = + TextStyle( + fontFamily = TypeScaleTokens.BodySmallFont, + fontWeight = TypeScaleTokens.BodySmallWeight, + fontSize = TypeScaleTokens.BodySmallSize, + lineHeight = TypeScaleTokens.BodySmallLineHeight, + letterSpacing = TypeScaleTokens.BodySmallTracking, + ) + val DisplayLarge = + TextStyle( + fontFamily = TypeScaleTokens.DisplayLargeFont, + fontWeight = TypeScaleTokens.DisplayLargeWeight, + fontSize = TypeScaleTokens.DisplayLargeSize, + lineHeight = TypeScaleTokens.DisplayLargeLineHeight, + letterSpacing = TypeScaleTokens.DisplayLargeTracking, + ) + val DisplayMedium = + TextStyle( + fontFamily = TypeScaleTokens.DisplayMediumFont, + fontWeight = TypeScaleTokens.DisplayMediumWeight, + fontSize = TypeScaleTokens.DisplayMediumSize, + lineHeight = TypeScaleTokens.DisplayMediumLineHeight, + letterSpacing = TypeScaleTokens.DisplayMediumTracking, + ) + val DisplaySmall = + TextStyle( + fontFamily = TypeScaleTokens.DisplaySmallFont, + fontWeight = TypeScaleTokens.DisplaySmallWeight, + fontSize = TypeScaleTokens.DisplaySmallSize, + lineHeight = TypeScaleTokens.DisplaySmallLineHeight, + letterSpacing = TypeScaleTokens.DisplaySmallTracking, + ) + val HeadlineLarge = + TextStyle( + fontFamily = TypeScaleTokens.HeadlineLargeFont, + fontWeight = TypeScaleTokens.HeadlineLargeWeight, + fontSize = TypeScaleTokens.HeadlineLargeSize, + lineHeight = TypeScaleTokens.HeadlineLargeLineHeight, + letterSpacing = TypeScaleTokens.HeadlineLargeTracking, + ) + val HeadlineMedium = + TextStyle( + fontFamily = TypeScaleTokens.HeadlineMediumFont, + fontWeight = TypeScaleTokens.HeadlineMediumWeight, + fontSize = TypeScaleTokens.HeadlineMediumSize, + lineHeight = TypeScaleTokens.HeadlineMediumLineHeight, + letterSpacing = TypeScaleTokens.HeadlineMediumTracking, + ) + val HeadlineSmall = + TextStyle( + fontFamily = TypeScaleTokens.HeadlineSmallFont, + fontWeight = TypeScaleTokens.HeadlineSmallWeight, + fontSize = TypeScaleTokens.HeadlineSmallSize, + lineHeight = TypeScaleTokens.HeadlineSmallLineHeight, + letterSpacing = TypeScaleTokens.HeadlineSmallTracking, + ) + val LabelLarge = + TextStyle( + fontFamily = TypeScaleTokens.LabelLargeFont, + fontWeight = TypeScaleTokens.LabelLargeWeight, + fontSize = TypeScaleTokens.LabelLargeSize, + lineHeight = TypeScaleTokens.LabelLargeLineHeight, + letterSpacing = TypeScaleTokens.LabelLargeTracking, + ) + val LabelMedium = + TextStyle( + fontFamily = TypeScaleTokens.LabelMediumFont, + fontWeight = TypeScaleTokens.LabelMediumWeight, + fontSize = TypeScaleTokens.LabelMediumSize, + lineHeight = TypeScaleTokens.LabelMediumLineHeight, + letterSpacing = TypeScaleTokens.LabelMediumTracking, + ) + val LabelSmall = + TextStyle( + fontFamily = TypeScaleTokens.LabelSmallFont, + fontWeight = TypeScaleTokens.LabelSmallWeight, + fontSize = TypeScaleTokens.LabelSmallSize, + lineHeight = TypeScaleTokens.LabelSmallLineHeight, + letterSpacing = TypeScaleTokens.LabelSmallTracking, + ) + val TitleLarge = + TextStyle( + fontFamily = TypeScaleTokens.TitleLargeFont, + fontWeight = TypeScaleTokens.TitleLargeWeight, + fontSize = TypeScaleTokens.TitleLargeSize, + lineHeight = TypeScaleTokens.TitleLargeLineHeight, + letterSpacing = TypeScaleTokens.TitleLargeTracking, + ) + val TitleMedium = + TextStyle( + fontFamily = TypeScaleTokens.TitleMediumFont, + fontWeight = TypeScaleTokens.TitleMediumWeight, + fontSize = TypeScaleTokens.TitleMediumSize, + lineHeight = TypeScaleTokens.TitleMediumLineHeight, + letterSpacing = TypeScaleTokens.TitleMediumTracking, + ) + val TitleSmall = + TextStyle( + fontFamily = TypeScaleTokens.TitleSmallFont, + fontWeight = TypeScaleTokens.TitleSmallWeight, + fontSize = TypeScaleTokens.TitleSmallSize, + lineHeight = TypeScaleTokens.TitleSmallLineHeight, + letterSpacing = TypeScaleTokens.TitleSmallTracking, + ) +} From df264869d33d59a8a0c49071fb162f0f50f9ddc4 Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Wed, 25 May 2022 12:27:51 +0200 Subject: [PATCH 2/2] Remove references to "google-sans" in SystemUITypography Test: Manual Bug: 230605885 Change-Id: Ib5602aea3803086cadaf1eb700e7916cd3325732 --- .../systemui/compose/theme/SystemUITheme.kt | 14 +- .../theme/typography/SystemUITypography.kt | 35 ++-- .../theme/typography/TypeScaleTokens.kt | 152 +++++++-------- .../theme/typography/TypefaceTokens.kt | 55 +++++- .../theme/typography/TypographyTokens.kt | 182 +++++++++--------- 5 files changed, 242 insertions(+), 196 deletions(-) diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt index de6ada29010ce..00532f4e46b84 100644 --- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt @@ -22,8 +22,13 @@ import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.remember import androidx.compose.ui.platform.LocalContext -import com.android.systemui.compose.theme.typography.SystemUITypography +import com.android.systemui.compose.theme.typography.TypeScaleTokens +import com.android.systemui.compose.theme.typography.TypefaceNames +import com.android.systemui.compose.theme.typography.TypefaceTokens +import com.android.systemui.compose.theme.typography.TypographyTokens +import com.android.systemui.compose.theme.typography.systemUITypography /** The Material 3 theme that should wrap all SystemUI Composables. */ @Composable @@ -41,8 +46,13 @@ fun SystemUITheme( dynamicLightColorScheme(context) } val androidColorScheme = AndroidColorScheme(context) + val typefaceNames = remember(context) { TypefaceNames.get(context) } + val typography = + remember(typefaceNames) { + systemUITypography(TypographyTokens(TypeScaleTokens(TypefaceTokens(typefaceNames)))) + } - MaterialTheme(colorScheme, typography = SystemUITypography) { + MaterialTheme(colorScheme, typography = typography) { CompositionLocalProvider( LocalAndroidColorScheme provides androidColorScheme, ) { diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt index c3208bad598f1..365f4bb69897d 100644 --- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/SystemUITypography.kt @@ -25,21 +25,22 @@ import androidx.compose.material3.Typography * Do not use directly and call [MaterialTheme.typography] instead to access the different text * styles. */ -internal val SystemUITypography = - Typography( - displayLarge = TypographyTokens.DisplayLarge, - displayMedium = TypographyTokens.DisplayMedium, - displaySmall = TypographyTokens.DisplaySmall, - headlineLarge = TypographyTokens.HeadlineLarge, - headlineMedium = TypographyTokens.HeadlineMedium, - headlineSmall = TypographyTokens.HeadlineSmall, - titleLarge = TypographyTokens.TitleLarge, - titleMedium = TypographyTokens.TitleMedium, - titleSmall = TypographyTokens.TitleSmall, - bodyLarge = TypographyTokens.BodyLarge, - bodyMedium = TypographyTokens.BodyMedium, - bodySmall = TypographyTokens.BodySmall, - labelLarge = TypographyTokens.LabelLarge, - labelMedium = TypographyTokens.LabelMedium, - labelSmall = TypographyTokens.LabelSmall, +internal fun systemUITypography(typographyTokens: TypographyTokens): Typography { + return Typography( + displayLarge = typographyTokens.displayLarge, + displayMedium = typographyTokens.displayMedium, + displaySmall = typographyTokens.displaySmall, + headlineLarge = typographyTokens.headlineLarge, + headlineMedium = typographyTokens.headlineMedium, + headlineSmall = typographyTokens.headlineSmall, + titleLarge = typographyTokens.titleLarge, + titleMedium = typographyTokens.titleMedium, + titleSmall = typographyTokens.titleSmall, + bodyLarge = typographyTokens.bodyLarge, + bodyMedium = typographyTokens.bodyMedium, + bodySmall = typographyTokens.bodySmall, + labelLarge = typographyTokens.labelLarge, + labelMedium = typographyTokens.labelMedium, + labelSmall = typographyTokens.labelSmall, ) +} diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt index 13f004089d48a..537ba0b7a834c 100644 --- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypeScaleTokens.kt @@ -18,80 +18,80 @@ package com.android.systemui.compose.theme.typography import androidx.compose.ui.unit.sp -object TypeScaleTokens { - val BodyLargeFont = TypefaceTokens.Plain - val BodyLargeLineHeight = 24.0.sp - val BodyLargeSize = 16.sp - val BodyLargeTracking = 0.0.sp - val BodyLargeWeight = TypefaceTokens.WeightRegular - val BodyMediumFont = TypefaceTokens.Plain - val BodyMediumLineHeight = 20.0.sp - val BodyMediumSize = 14.sp - val BodyMediumTracking = 0.0.sp - val BodyMediumWeight = TypefaceTokens.WeightRegular - val BodySmallFont = TypefaceTokens.Plain - val BodySmallLineHeight = 16.0.sp - val BodySmallSize = 12.sp - val BodySmallTracking = 0.1.sp - val BodySmallWeight = TypefaceTokens.WeightRegular - val DisplayLargeFont = TypefaceTokens.Brand - val DisplayLargeLineHeight = 64.0.sp - val DisplayLargeSize = 57.sp - val DisplayLargeTracking = 0.0.sp - val DisplayLargeWeight = TypefaceTokens.WeightRegular - val DisplayMediumFont = TypefaceTokens.Brand - val DisplayMediumLineHeight = 52.0.sp - val DisplayMediumSize = 45.sp - val DisplayMediumTracking = 0.0.sp - val DisplayMediumWeight = TypefaceTokens.WeightRegular - val DisplaySmallFont = TypefaceTokens.Brand - val DisplaySmallLineHeight = 44.0.sp - val DisplaySmallSize = 36.sp - val DisplaySmallTracking = 0.0.sp - val DisplaySmallWeight = TypefaceTokens.WeightRegular - val HeadlineLargeFont = TypefaceTokens.Brand - val HeadlineLargeLineHeight = 40.0.sp - val HeadlineLargeSize = 32.sp - val HeadlineLargeTracking = 0.0.sp - val HeadlineLargeWeight = TypefaceTokens.WeightRegular - val HeadlineMediumFont = TypefaceTokens.Brand - val HeadlineMediumLineHeight = 36.0.sp - val HeadlineMediumSize = 28.sp - val HeadlineMediumTracking = 0.0.sp - val HeadlineMediumWeight = TypefaceTokens.WeightRegular - val HeadlineSmallFont = TypefaceTokens.Brand - val HeadlineSmallLineHeight = 32.0.sp - val HeadlineSmallSize = 24.sp - val HeadlineSmallTracking = 0.0.sp - val HeadlineSmallWeight = TypefaceTokens.WeightRegular - val LabelLargeFont = TypefaceTokens.Plain - val LabelLargeLineHeight = 20.0.sp - val LabelLargeSize = 14.sp - val LabelLargeTracking = 0.0.sp - val LabelLargeWeight = TypefaceTokens.WeightMedium - val LabelMediumFont = TypefaceTokens.Plain - val LabelMediumLineHeight = 16.0.sp - val LabelMediumSize = 12.sp - val LabelMediumTracking = 0.1.sp - val LabelMediumWeight = TypefaceTokens.WeightMedium - val LabelSmallFont = TypefaceTokens.Plain - val LabelSmallLineHeight = 16.0.sp - val LabelSmallSize = 11.sp - val LabelSmallTracking = 0.1.sp - val LabelSmallWeight = TypefaceTokens.WeightMedium - val TitleLargeFont = TypefaceTokens.Brand - val TitleLargeLineHeight = 28.0.sp - val TitleLargeSize = 22.sp - val TitleLargeTracking = 0.0.sp - val TitleLargeWeight = TypefaceTokens.WeightRegular - val TitleMediumFont = TypefaceTokens.Plain - val TitleMediumLineHeight = 24.0.sp - val TitleMediumSize = 16.sp - val TitleMediumTracking = 0.0.sp - val TitleMediumWeight = TypefaceTokens.WeightMedium - val TitleSmallFont = TypefaceTokens.Plain - val TitleSmallLineHeight = 20.0.sp - val TitleSmallSize = 14.sp - val TitleSmallTracking = 0.0.sp - val TitleSmallWeight = TypefaceTokens.WeightMedium +internal class TypeScaleTokens(typefaceTokens: TypefaceTokens) { + val bodyLargeFont = typefaceTokens.plain + val bodyLargeLineHeight = 24.0.sp + val bodyLargeSize = 16.sp + val bodyLargeTracking = 0.0.sp + val bodyLargeWeight = TypefaceTokens.WeightRegular + val bodyMediumFont = typefaceTokens.plain + val bodyMediumLineHeight = 20.0.sp + val bodyMediumSize = 14.sp + val bodyMediumTracking = 0.0.sp + val bodyMediumWeight = TypefaceTokens.WeightRegular + val bodySmallFont = typefaceTokens.plain + val bodySmallLineHeight = 16.0.sp + val bodySmallSize = 12.sp + val bodySmallTracking = 0.1.sp + val bodySmallWeight = TypefaceTokens.WeightRegular + val displayLargeFont = typefaceTokens.brand + val displayLargeLineHeight = 64.0.sp + val displayLargeSize = 57.sp + val displayLargeTracking = 0.0.sp + val displayLargeWeight = TypefaceTokens.WeightRegular + val displayMediumFont = typefaceTokens.brand + val displayMediumLineHeight = 52.0.sp + val displayMediumSize = 45.sp + val displayMediumTracking = 0.0.sp + val displayMediumWeight = TypefaceTokens.WeightRegular + val displaySmallFont = typefaceTokens.brand + val displaySmallLineHeight = 44.0.sp + val displaySmallSize = 36.sp + val displaySmallTracking = 0.0.sp + val displaySmallWeight = TypefaceTokens.WeightRegular + val headlineLargeFont = typefaceTokens.brand + val headlineLargeLineHeight = 40.0.sp + val headlineLargeSize = 32.sp + val headlineLargeTracking = 0.0.sp + val headlineLargeWeight = TypefaceTokens.WeightRegular + val headlineMediumFont = typefaceTokens.brand + val headlineMediumLineHeight = 36.0.sp + val headlineMediumSize = 28.sp + val headlineMediumTracking = 0.0.sp + val headlineMediumWeight = TypefaceTokens.WeightRegular + val headlineSmallFont = typefaceTokens.brand + val headlineSmallLineHeight = 32.0.sp + val headlineSmallSize = 24.sp + val headlineSmallTracking = 0.0.sp + val headlineSmallWeight = TypefaceTokens.WeightRegular + val labelLargeFont = typefaceTokens.plain + val labelLargeLineHeight = 20.0.sp + val labelLargeSize = 14.sp + val labelLargeTracking = 0.0.sp + val labelLargeWeight = TypefaceTokens.WeightMedium + val labelMediumFont = typefaceTokens.plain + val labelMediumLineHeight = 16.0.sp + val labelMediumSize = 12.sp + val labelMediumTracking = 0.1.sp + val labelMediumWeight = TypefaceTokens.WeightMedium + val labelSmallFont = typefaceTokens.plain + val labelSmallLineHeight = 16.0.sp + val labelSmallSize = 11.sp + val labelSmallTracking = 0.1.sp + val labelSmallWeight = TypefaceTokens.WeightMedium + val titleLargeFont = typefaceTokens.brand + val titleLargeLineHeight = 28.0.sp + val titleLargeSize = 22.sp + val titleLargeTracking = 0.0.sp + val titleLargeWeight = TypefaceTokens.WeightRegular + val titleMediumFont = typefaceTokens.plain + val titleMediumLineHeight = 24.0.sp + val titleMediumSize = 16.sp + val titleMediumTracking = 0.0.sp + val titleMediumWeight = TypefaceTokens.WeightMedium + val titleSmallFont = typefaceTokens.plain + val titleSmallLineHeight = 20.0.sp + val titleSmallSize = 14.sp + val titleSmallTracking = 0.0.sp + val titleSmallWeight = TypefaceTokens.WeightMedium } diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt index a17d226f85bbd..f3d554fc93636 100644 --- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypefaceTokens.kt @@ -18,22 +18,57 @@ package com.android.systemui.compose.theme.typography +import android.content.Context import androidx.compose.ui.text.ExperimentalTextApi import androidx.compose.ui.text.font.DeviceFontFamilyName import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight -val brandFont = DeviceFontFamilyName("google-sans") -val plainFont = DeviceFontFamilyName("google-sans-text") +internal class TypefaceTokens(typefaceNames: TypefaceNames) { + companion object { + val WeightMedium = FontWeight.Medium + val WeightRegular = FontWeight.Normal + } -object TypefaceTokens { + private val brandFont = DeviceFontFamilyName(typefaceNames.brand) + private val plainFont = DeviceFontFamilyName(typefaceNames.plain) - val WeightMedium = FontWeight.Medium - val WeightRegular = FontWeight.Normal - - val Brand = - FontFamily(Font(brandFont, weight = WeightMedium), Font(brandFont, weight = WeightRegular)) - val Plain = - FontFamily(Font(plainFont, weight = WeightMedium), Font(plainFont, weight = WeightRegular)) + val brand = + FontFamily( + Font(brandFont, weight = WeightMedium), + Font(brandFont, weight = WeightRegular), + ) + val plain = + FontFamily( + Font(plainFont, weight = WeightMedium), + Font(plainFont, weight = WeightRegular), + ) +} + +internal data class TypefaceNames +private constructor( + val brand: String, + val plain: String, +) { + private enum class Config(val configName: String, val default: String) { + Brand("config_headlineFontFamily", "sans-serif"), + Plain("config_bodyFontFamily", "sans-serif"), + } + + companion object { + fun get(context: Context): TypefaceNames { + return TypefaceNames( + brand = getTypefaceName(context, Config.Brand), + plain = getTypefaceName(context, Config.Plain), + ) + } + + private fun getTypefaceName(context: Context, config: Config): String { + return context + .getString(context.resources.getIdentifier(config.configName, "string", "android")) + .takeIf { it.isNotEmpty() } + ?: config.default + } + } } diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt index 46ad88923ebec..55f3d1fef05a4 100644 --- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/typography/TypographyTokens.kt @@ -18,125 +18,125 @@ package com.android.systemui.compose.theme.typography import androidx.compose.ui.text.TextStyle -object TypographyTokens { - val BodyLarge = +internal class TypographyTokens(typeScaleTokens: TypeScaleTokens) { + val bodyLarge = TextStyle( - fontFamily = TypeScaleTokens.BodyLargeFont, - fontWeight = TypeScaleTokens.BodyLargeWeight, - fontSize = TypeScaleTokens.BodyLargeSize, - lineHeight = TypeScaleTokens.BodyLargeLineHeight, - letterSpacing = TypeScaleTokens.BodyLargeTracking, + fontFamily = typeScaleTokens.bodyLargeFont, + fontWeight = typeScaleTokens.bodyLargeWeight, + fontSize = typeScaleTokens.bodyLargeSize, + lineHeight = typeScaleTokens.bodyLargeLineHeight, + letterSpacing = typeScaleTokens.bodyLargeTracking, ) - val BodyMedium = + val bodyMedium = TextStyle( - fontFamily = TypeScaleTokens.BodyMediumFont, - fontWeight = TypeScaleTokens.BodyMediumWeight, - fontSize = TypeScaleTokens.BodyMediumSize, - lineHeight = TypeScaleTokens.BodyMediumLineHeight, - letterSpacing = TypeScaleTokens.BodyMediumTracking, + fontFamily = typeScaleTokens.bodyMediumFont, + fontWeight = typeScaleTokens.bodyMediumWeight, + fontSize = typeScaleTokens.bodyMediumSize, + lineHeight = typeScaleTokens.bodyMediumLineHeight, + letterSpacing = typeScaleTokens.bodyMediumTracking, ) - val BodySmall = + val bodySmall = TextStyle( - fontFamily = TypeScaleTokens.BodySmallFont, - fontWeight = TypeScaleTokens.BodySmallWeight, - fontSize = TypeScaleTokens.BodySmallSize, - lineHeight = TypeScaleTokens.BodySmallLineHeight, - letterSpacing = TypeScaleTokens.BodySmallTracking, + fontFamily = typeScaleTokens.bodySmallFont, + fontWeight = typeScaleTokens.bodySmallWeight, + fontSize = typeScaleTokens.bodySmallSize, + lineHeight = typeScaleTokens.bodySmallLineHeight, + letterSpacing = typeScaleTokens.bodySmallTracking, ) - val DisplayLarge = + val displayLarge = TextStyle( - fontFamily = TypeScaleTokens.DisplayLargeFont, - fontWeight = TypeScaleTokens.DisplayLargeWeight, - fontSize = TypeScaleTokens.DisplayLargeSize, - lineHeight = TypeScaleTokens.DisplayLargeLineHeight, - letterSpacing = TypeScaleTokens.DisplayLargeTracking, + fontFamily = typeScaleTokens.displayLargeFont, + fontWeight = typeScaleTokens.displayLargeWeight, + fontSize = typeScaleTokens.displayLargeSize, + lineHeight = typeScaleTokens.displayLargeLineHeight, + letterSpacing = typeScaleTokens.displayLargeTracking, ) - val DisplayMedium = + val displayMedium = TextStyle( - fontFamily = TypeScaleTokens.DisplayMediumFont, - fontWeight = TypeScaleTokens.DisplayMediumWeight, - fontSize = TypeScaleTokens.DisplayMediumSize, - lineHeight = TypeScaleTokens.DisplayMediumLineHeight, - letterSpacing = TypeScaleTokens.DisplayMediumTracking, + fontFamily = typeScaleTokens.displayMediumFont, + fontWeight = typeScaleTokens.displayMediumWeight, + fontSize = typeScaleTokens.displayMediumSize, + lineHeight = typeScaleTokens.displayMediumLineHeight, + letterSpacing = typeScaleTokens.displayMediumTracking, ) - val DisplaySmall = + val displaySmall = TextStyle( - fontFamily = TypeScaleTokens.DisplaySmallFont, - fontWeight = TypeScaleTokens.DisplaySmallWeight, - fontSize = TypeScaleTokens.DisplaySmallSize, - lineHeight = TypeScaleTokens.DisplaySmallLineHeight, - letterSpacing = TypeScaleTokens.DisplaySmallTracking, + fontFamily = typeScaleTokens.displaySmallFont, + fontWeight = typeScaleTokens.displaySmallWeight, + fontSize = typeScaleTokens.displaySmallSize, + lineHeight = typeScaleTokens.displaySmallLineHeight, + letterSpacing = typeScaleTokens.displaySmallTracking, ) - val HeadlineLarge = + val headlineLarge = TextStyle( - fontFamily = TypeScaleTokens.HeadlineLargeFont, - fontWeight = TypeScaleTokens.HeadlineLargeWeight, - fontSize = TypeScaleTokens.HeadlineLargeSize, - lineHeight = TypeScaleTokens.HeadlineLargeLineHeight, - letterSpacing = TypeScaleTokens.HeadlineLargeTracking, + fontFamily = typeScaleTokens.headlineLargeFont, + fontWeight = typeScaleTokens.headlineLargeWeight, + fontSize = typeScaleTokens.headlineLargeSize, + lineHeight = typeScaleTokens.headlineLargeLineHeight, + letterSpacing = typeScaleTokens.headlineLargeTracking, ) - val HeadlineMedium = + val headlineMedium = TextStyle( - fontFamily = TypeScaleTokens.HeadlineMediumFont, - fontWeight = TypeScaleTokens.HeadlineMediumWeight, - fontSize = TypeScaleTokens.HeadlineMediumSize, - lineHeight = TypeScaleTokens.HeadlineMediumLineHeight, - letterSpacing = TypeScaleTokens.HeadlineMediumTracking, + fontFamily = typeScaleTokens.headlineMediumFont, + fontWeight = typeScaleTokens.headlineMediumWeight, + fontSize = typeScaleTokens.headlineMediumSize, + lineHeight = typeScaleTokens.headlineMediumLineHeight, + letterSpacing = typeScaleTokens.headlineMediumTracking, ) - val HeadlineSmall = + val headlineSmall = TextStyle( - fontFamily = TypeScaleTokens.HeadlineSmallFont, - fontWeight = TypeScaleTokens.HeadlineSmallWeight, - fontSize = TypeScaleTokens.HeadlineSmallSize, - lineHeight = TypeScaleTokens.HeadlineSmallLineHeight, - letterSpacing = TypeScaleTokens.HeadlineSmallTracking, + fontFamily = typeScaleTokens.headlineSmallFont, + fontWeight = typeScaleTokens.headlineSmallWeight, + fontSize = typeScaleTokens.headlineSmallSize, + lineHeight = typeScaleTokens.headlineSmallLineHeight, + letterSpacing = typeScaleTokens.headlineSmallTracking, ) - val LabelLarge = + val labelLarge = TextStyle( - fontFamily = TypeScaleTokens.LabelLargeFont, - fontWeight = TypeScaleTokens.LabelLargeWeight, - fontSize = TypeScaleTokens.LabelLargeSize, - lineHeight = TypeScaleTokens.LabelLargeLineHeight, - letterSpacing = TypeScaleTokens.LabelLargeTracking, + fontFamily = typeScaleTokens.labelLargeFont, + fontWeight = typeScaleTokens.labelLargeWeight, + fontSize = typeScaleTokens.labelLargeSize, + lineHeight = typeScaleTokens.labelLargeLineHeight, + letterSpacing = typeScaleTokens.labelLargeTracking, ) - val LabelMedium = + val labelMedium = TextStyle( - fontFamily = TypeScaleTokens.LabelMediumFont, - fontWeight = TypeScaleTokens.LabelMediumWeight, - fontSize = TypeScaleTokens.LabelMediumSize, - lineHeight = TypeScaleTokens.LabelMediumLineHeight, - letterSpacing = TypeScaleTokens.LabelMediumTracking, + fontFamily = typeScaleTokens.labelMediumFont, + fontWeight = typeScaleTokens.labelMediumWeight, + fontSize = typeScaleTokens.labelMediumSize, + lineHeight = typeScaleTokens.labelMediumLineHeight, + letterSpacing = typeScaleTokens.labelMediumTracking, ) - val LabelSmall = + val labelSmall = TextStyle( - fontFamily = TypeScaleTokens.LabelSmallFont, - fontWeight = TypeScaleTokens.LabelSmallWeight, - fontSize = TypeScaleTokens.LabelSmallSize, - lineHeight = TypeScaleTokens.LabelSmallLineHeight, - letterSpacing = TypeScaleTokens.LabelSmallTracking, + fontFamily = typeScaleTokens.labelSmallFont, + fontWeight = typeScaleTokens.labelSmallWeight, + fontSize = typeScaleTokens.labelSmallSize, + lineHeight = typeScaleTokens.labelSmallLineHeight, + letterSpacing = typeScaleTokens.labelSmallTracking, ) - val TitleLarge = + val titleLarge = TextStyle( - fontFamily = TypeScaleTokens.TitleLargeFont, - fontWeight = TypeScaleTokens.TitleLargeWeight, - fontSize = TypeScaleTokens.TitleLargeSize, - lineHeight = TypeScaleTokens.TitleLargeLineHeight, - letterSpacing = TypeScaleTokens.TitleLargeTracking, + fontFamily = typeScaleTokens.titleLargeFont, + fontWeight = typeScaleTokens.titleLargeWeight, + fontSize = typeScaleTokens.titleLargeSize, + lineHeight = typeScaleTokens.titleLargeLineHeight, + letterSpacing = typeScaleTokens.titleLargeTracking, ) - val TitleMedium = + val titleMedium = TextStyle( - fontFamily = TypeScaleTokens.TitleMediumFont, - fontWeight = TypeScaleTokens.TitleMediumWeight, - fontSize = TypeScaleTokens.TitleMediumSize, - lineHeight = TypeScaleTokens.TitleMediumLineHeight, - letterSpacing = TypeScaleTokens.TitleMediumTracking, + fontFamily = typeScaleTokens.titleMediumFont, + fontWeight = typeScaleTokens.titleMediumWeight, + fontSize = typeScaleTokens.titleMediumSize, + lineHeight = typeScaleTokens.titleMediumLineHeight, + letterSpacing = typeScaleTokens.titleMediumTracking, ) - val TitleSmall = + val titleSmall = TextStyle( - fontFamily = TypeScaleTokens.TitleSmallFont, - fontWeight = TypeScaleTokens.TitleSmallWeight, - fontSize = TypeScaleTokens.TitleSmallSize, - lineHeight = TypeScaleTokens.TitleSmallLineHeight, - letterSpacing = TypeScaleTokens.TitleSmallTracking, + fontFamily = typeScaleTokens.titleSmallFont, + fontWeight = typeScaleTokens.titleSmallWeight, + fontSize = typeScaleTokens.titleSmallSize, + lineHeight = typeScaleTokens.titleSmallLineHeight, + letterSpacing = typeScaleTokens.titleSmallTracking, ) }