1 /* 2 * Copyright (C) 2022 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.credentialmanager.ui.theme 18 19 import android.annotation.ColorInt 20 import android.content.Context 21 import androidx.compose.runtime.staticCompositionLocalOf 22 import androidx.compose.ui.graphics.Color 23 import com.android.internal.R 24 25 /** File copied from PlatformComposeCore. */ 26 27 /** CompositionLocal used to pass [AndroidColorScheme] down the tree. */ 28 val LocalAndroidColorScheme = 29 staticCompositionLocalOf<AndroidColorScheme> { 30 throw IllegalStateException( 31 "No AndroidColorScheme configured. Make sure to use LocalAndroidColorScheme in a " + 32 "Composable surrounded by a PlatformTheme {}." 33 ) 34 } 35 36 /** 37 * The Android color scheme. 38 * 39 * Important: Use M3 colors from MaterialTheme.colorScheme whenever possible instead. In the future, 40 * most of the colors in this class will be removed in favor of their M3 counterpart. 41 */ 42 class AndroidColorScheme internal constructor(context: Context) { 43 val colorSurfaceBright = getColor(context, R.attr.materialColorSurfaceBright) 44 val colorSurfaceContainerHigh = getColor(context, R.attr.materialColorSurfaceContainerHigh) 45 val colorOutlineVariant = getColor(context, R.attr.materialColorOutlineVariant) 46 val colorOnSurface = getColor(context, R.attr.materialColorOnSurface) 47 val colorOnSurfaceVariant = getColor(context, R.attr.materialColorOnSurfaceVariant) 48 49 companion object { 50 fun getColor(context: Context, attr: Int): Color { 51 val ta = context.obtainStyledAttributes(intArrayOf(attr)) 52 @ColorInt val color = ta.getColor(0, 0) 53 ta.recycle() 54 return Color(color) 55 } 56 } 57 } 58