Skip to content

Commit

Permalink
Using downloadable fonts in Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
astamato committed May 3, 2022
1 parent a586207 commit 7e44d87
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
1 change: 1 addition & 0 deletions Jetchat/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ dependencies {
implementation Libs.AndroidX.Compose.runtime
implementation Libs.AndroidX.Compose.runtimeLivedata
implementation Libs.AndroidX.Compose.viewBinding
implementation Libs.AndroidX.Compose.uiText
debugImplementation Libs.AndroidX.Compose.tooling

debugImplementation Libs.AndroidX.Compose.uiTestManifest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,47 @@
package com.example.compose.jetchat.theme

import androidx.compose.material3.Typography
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.googlefonts.Font
import androidx.compose.ui.text.googlefonts.GoogleFont
import androidx.compose.ui.unit.sp
import com.example.compose.jetchat.R

private val MontserratFontFamily = FontFamily(
Font(R.font.montserrat_regular),
Font(R.font.montserrat_light, FontWeight.Light),
Font(R.font.montserrat_medium, FontWeight.Medium),
Font(R.font.montserrat_semibold, FontWeight.SemiBold)
@OptIn(ExperimentalTextApi::class)
val provider = GoogleFont.Provider(
providerAuthority = "com.google.android.gms.fonts",
providerPackage = "com.google.android.gms",
certificates = R.array.com_google_android_gms_fonts_certs
)

private val KarlaFontFamily = FontFamily(
Font(R.font.karla_regular),
Font(R.font.karla_bold, FontWeight.Bold)
@OptIn(ExperimentalTextApi::class)
val MontserratFont = GoogleFont(name = "Montserrat")

@OptIn(ExperimentalTextApi::class)
val KarlaFont = GoogleFont(name = "Karla")

@OptIn(ExperimentalTextApi::class)
val MontserratFontFamily = FontFamily(
Font(googleFont = MontserratFont, fontProvider = provider),
Font(resId = R.font.montserrat_regular),
Font(googleFont = MontserratFont, fontProvider = provider, weight = FontWeight.Light),
Font(resId = R.font.montserrat_light, weight = FontWeight.Light),
Font(googleFont = MontserratFont, fontProvider = provider, weight = FontWeight.Medium),
Font(resId = R.font.montserrat_medium, weight = FontWeight.Medium),
Font(googleFont = MontserratFont, fontProvider = provider, weight = FontWeight.SemiBold),
Font(resId = R.font.montserrat_semibold, weight = FontWeight.SemiBold),
)

@OptIn(ExperimentalTextApi::class)
val KarlaFontFamily = FontFamily(
Font(googleFont = KarlaFont, fontProvider = provider),
Font(resId = R.font.karla_regular),
Font(googleFont = KarlaFont, fontProvider = provider, weight = FontWeight.Bold),
Font(resId = R.font.karla_bold, weight = FontWeight.Bold),
)

val JetchatTypography = Typography(
Expand Down
32 changes: 32 additions & 0 deletions Jetchat/app/src/main/res/values-v23/font_certs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 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.
-->
<resources>
<array name="com_google_android_gms_fonts_certs">
<item>@array/com_google_android_gms_fonts_certs_dev</item>
<item>@array/com_google_android_gms_fonts_certs_prod</item>
</array>
<string-array name="com_google_android_gms_fonts_certs_dev">
<item>
MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGS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SoOO0yZ31j7kYvtwYK6NeADwbSxDdJEqO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/Tgt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK
</item>
</string-array>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Libs {
const val material3 = "com.google.android.material:material:1.6.0-alpha03"

object Kotlin {
private const val version = "1.6.10"
private const val version = "1.6.20"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
const val extensions = "org.jetbrains.kotlin:kotlin-android-extensions:$version"
Expand All @@ -52,7 +52,7 @@ object Libs {

object Compose {
const val snapshot = ""
const val version = "1.2.0-alpha06"
const val version = "1.2.0-alpha08"

const val foundation = "androidx.compose.foundation:foundation:$version"
const val layout = "androidx.compose.foundation:foundation-layout:$version"
Expand All @@ -64,6 +64,7 @@ object Libs {
const val toolingPreview = "androidx.compose.ui:ui-tooling-preview:$version"
const val test = "androidx.compose.ui:ui-test:$version"
const val uiTest = "androidx.compose.ui:ui-test-junit4:$version"
const val uiText = "androidx.compose.ui:ui-text-google-fonts:$version"
const val uiTestManifest = "androidx.compose.ui:ui-test-manifest:$version"
const val uiUtil = "androidx.compose.ui:ui-util:${version}"
const val viewBinding = "androidx.compose.ui:ui-viewbinding:$version"
Expand Down

0 comments on commit 7e44d87

Please sign in to comment.