1 /* 2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.glance.appwidget.demos 18 19 import android.content.Context 20 import androidx.compose.runtime.Composable 21 import androidx.compose.ui.unit.dp 22 import androidx.compose.ui.unit.sp 23 import androidx.glance.GlanceId 24 import androidx.glance.GlanceModifier 25 import androidx.glance.GlanceTheme 26 import androidx.glance.appwidget.GlanceAppWidget 27 import androidx.glance.appwidget.GlanceAppWidgetReceiver 28 import androidx.glance.appwidget.SizeMode 29 import androidx.glance.appwidget.lazy.LazyColumn 30 import androidx.glance.appwidget.provideContent 31 import androidx.glance.background 32 import androidx.glance.layout.Column 33 import androidx.glance.layout.Spacer 34 import androidx.glance.layout.fillMaxSize 35 import androidx.glance.layout.fillMaxWidth 36 import androidx.glance.layout.padding 37 import androidx.glance.layout.size 38 import androidx.glance.layout.wrapContentHeight 39 import androidx.glance.text.FontFamily 40 import androidx.glance.text.FontWeight 41 import androidx.glance.text.Text 42 import androidx.glance.text.TextAlign 43 import androidx.glance.text.TextStyle 44 45 /** Sample AppWidget showcases Glance text styles. */ 46 class TypographyDemoAppWidget : GlanceAppWidget() { 47 override val sizeMode: SizeMode = SizeMode.Exact 48 <lambda>null49 override suspend fun provideGlance(context: Context, id: GlanceId) = provideContent { 50 Content() 51 } 52 <lambda>null53 override suspend fun providePreview(context: Context, widgetCategory: Int) = provideContent { 54 Content() 55 } 56 57 @Composable Contentnull58 private fun Content() { 59 Column( 60 modifier = 61 GlanceModifier.fillMaxSize().background(GlanceTheme.colors.background).padding(8.dp) 62 ) { 63 Column { 64 Text( 65 "Text Component Demo Widget", 66 modifier = GlanceModifier.fillMaxWidth().wrapContentHeight(), 67 style = 68 TextStyle( 69 fontWeight = FontWeight.Bold, 70 fontSize = 24.sp, 71 textAlign = TextAlign.Center 72 ) 73 ) 74 Spacer(GlanceModifier.size(16.dp)) 75 Text("Glance text styles:", style = TextStyle(fontSize = 18.sp)) 76 Spacer(GlanceModifier.size(20.dp)) 77 } 78 79 LazyColumn { 80 item { 81 Text( 82 "Display Large", 83 style = 84 TextStyle( 85 fontSize = 57.sp, 86 fontWeight = FontWeight.Normal, 87 fontFamily = FontFamily.SansSerif 88 ) 89 ) 90 } 91 item { 92 Text( 93 "Headline Large", 94 style = 95 TextStyle( 96 fontSize = 32.sp, 97 fontWeight = FontWeight.Normal, 98 fontFamily = FontFamily.SansSerif 99 ) 100 ) 101 } 102 item { 103 Text( 104 "Headline Small", 105 style = 106 TextStyle( 107 fontSize = 24.sp, 108 fontWeight = FontWeight.Normal, 109 fontFamily = FontFamily.SansSerif 110 ) 111 ) 112 } 113 item { 114 Text( 115 "Title Medium", 116 style = 117 TextStyle( 118 fontSize = 16.sp, 119 fontWeight = FontWeight.Medium, 120 fontFamily = FontFamily.SansSerif 121 ) 122 ) 123 } 124 item { 125 Text( 126 "Body Medium", 127 style = 128 TextStyle( 129 fontSize = 14.sp, 130 fontWeight = FontWeight.Normal, 131 fontFamily = FontFamily.SansSerif 132 ) 133 ) 134 } 135 item { 136 Text( 137 "Label Large", 138 style = 139 TextStyle( 140 fontSize = 14.sp, 141 fontWeight = FontWeight.Medium, 142 fontFamily = FontFamily.SansSerif 143 ) 144 ) 145 } 146 item { 147 Text( 148 "Label Medium", 149 style = 150 TextStyle( 151 fontSize = 12.sp, 152 fontWeight = FontWeight.Medium, 153 fontFamily = FontFamily.SansSerif 154 ) 155 ) 156 } 157 } 158 } 159 } 160 } 161 162 class TypographyDemoAppWidgetReceiver : GlanceAppWidgetReceiver() { 163 override val glanceAppWidget: GlanceAppWidget = TypographyDemoAppWidget() 164 } 165