1 /* 2 * Copyright (C) 2024 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 com.android.systemui.inputdevice.tutorial.ui.composable 18 19 import androidx.annotation.ColorInt 20 import androidx.annotation.RawRes 21 import androidx.annotation.StringRes 22 import androidx.compose.ui.graphics.Color 23 import androidx.compose.ui.graphics.toArgb 24 import androidx.core.graphics.ColorUtils 25 import com.airbnb.lottie.compose.LottieDynamicProperties 26 27 data class TutorialScreenConfig( 28 val colors: Colors, 29 val strings: Strings, 30 val animations: Animations, 31 ) { 32 33 data class Colors( 34 val background: Color, 35 val title: Color, 36 val bodyText: Color, 37 val animationColors: LottieDynamicProperties, 38 ) { 39 constructor( 40 background: Color, 41 title: Color, 42 animationColors: LottieDynamicProperties, 43 ) : this(background, title, textColorOnBackground(background.toArgb()), animationColors) 44 45 companion object { textColorOnBackgroundnull46 private fun textColorOnBackground(@ColorInt background: Int): Color { 47 val whiteContrast = ColorUtils.calculateContrast(Color.White.toArgb(), background) 48 val blackContrast = ColorUtils.calculateContrast(Color.Black.toArgb(), background) 49 return if (whiteContrast >= blackContrast) Color.White else Color.Black 50 } 51 } 52 } 53 54 data class Strings( 55 @StringRes val titleResId: Int, 56 @StringRes val bodyResId: Int, 57 @StringRes val titleSuccessResId: Int, 58 @StringRes val bodySuccessResId: Int, 59 @StringRes val titleErrorResId: Int, 60 @StringRes val bodyErrorResId: Int, 61 ) 62 63 data class Animations(@RawRes val educationResId: Int) 64 } 65