• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 package com.google.jetpackcamera.ui.theme
17 
18 import android.app.Activity
19 import android.os.Build
20 import androidx.compose.foundation.isSystemInDarkTheme
21 import androidx.compose.material3.MaterialTheme
22 import androidx.compose.material3.darkColorScheme
23 import androidx.compose.material3.dynamicDarkColorScheme
24 import androidx.compose.material3.dynamicLightColorScheme
25 import androidx.compose.material3.lightColorScheme
26 import androidx.compose.runtime.Composable
27 import androidx.compose.runtime.SideEffect
28 import androidx.compose.ui.graphics.toArgb
29 import androidx.compose.ui.platform.LocalContext
30 import androidx.compose.ui.platform.LocalView
31 import androidx.core.view.WindowCompat
32 
33 private val DarkColorScheme =
34     darkColorScheme(
35         primary = Purple80,
36         secondary = PurpleGrey80,
37         tertiary = Pink80
38     )
39 
40 private val LightColorScheme =
41     lightColorScheme(
42         primary = Purple40,
43         secondary = PurpleGrey40,
44         tertiary = Pink40
45     )
46 
47 @Composable
JetpackCameraThemenull48 fun JetpackCameraTheme(
49     darkTheme: Boolean = isSystemInDarkTheme(),
50     // Dynamic color is available on Android 12+
51     dynamicColor: Boolean = true,
52     content: @Composable () -> Unit
53 ) {
54     val colorScheme =
55         when {
56             dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
57                 val context = LocalContext.current
58                 if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
59             }
60 
61             darkTheme -> DarkColorScheme
62             else -> LightColorScheme
63         }
64     val view = LocalView.current
65     if (!view.isInEditMode) {
66         SideEffect {
67             val window = (view.context as Activity).window
68             window.statusBarColor = colorScheme.primary.toArgb()
69             WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
70         }
71     }
72 
73     MaterialTheme(
74         colorScheme = colorScheme,
75         typography = Typography,
76         content = content
77     )
78 }
79