Remove references to "google-sans" in SystemUITypography

Test: Manual
Bug: 230605885
Change-Id: Ib5602aea3803086cadaf1eb700e7916cd3325732
This commit is contained in:
Jordan Demeulenaere
2022-05-25 12:27:51 +02:00
parent 8c222cabb6
commit df264869d3
5 changed files with 242 additions and 196 deletions

View File

@@ -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,
) {

View File

@@ -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,
)
}

View File

@@ -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
}

View File

@@ -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
}
}
}

View File

@@ -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,
)
}