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 package com.google.jetpackcamera.settings.ui.theme 17 18 import android.os.Build 19 import androidx.compose.foundation.isSystemInDarkTheme 20 import androidx.compose.material3.MaterialTheme 21 import androidx.compose.material3.darkColorScheme 22 import androidx.compose.material3.dynamicDarkColorScheme 23 import androidx.compose.material3.dynamicLightColorScheme 24 import androidx.compose.material3.lightColorScheme 25 import androidx.compose.runtime.Composable 26 import androidx.compose.ui.platform.LocalContext 27 28 @Composable SettingsPreviewThemenull29fun SettingsPreviewTheme( 30 darkTheme: Boolean = isSystemInDarkTheme(), 31 // Dynamic color is available on Android 12+ 32 dynamicColor: Boolean = true, 33 content: @Composable () -> Unit 34 ) { 35 val colorScheme = 36 when { 37 dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { 38 val context = LocalContext.current 39 if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) 40 } 41 42 darkTheme -> darkColorScheme() 43 else -> lightColorScheme() 44 } 45 46 MaterialTheme( 47 colorScheme = colorScheme, 48 content = content 49 ) 50 } 51