Changed the default Theme.kt

This commit is contained in:
Anthony La committed 2023-05-30 17:40:10 -07:00
1 parent 127805bc70
commit dbf0bd9a58
8 files changed
+171 -75

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CompilerConfiguration"> <component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" /> <bytecodeTargetLevel target="20" />
</component> </component>
</project> </project>
+1 -1
View File
@@ -1,6 +1,6 @@
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="20" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
+2
View File
@@ -61,6 +61,8 @@ dependencies {
implementation("com.google.accompanist:accompanist-systemuicontroller:0.31.2-alpha") implementation("com.google.accompanist:accompanist-systemuicontroller:0.31.2-alpha")
implementation("androidx.navigation:navigation-compose:2.7.0-alpha01") implementation("androidx.navigation:navigation-compose:2.7.0-alpha01")
implementation("androidx.compose.material:material:1.5.0-beta01") implementation("androidx.compose.material:material:1.5.0-beta01")
implementation("androidx.datastore:datastore:1.1.0-alpha04")
implementation("androidx.datastore:datastore-preferences:1.1.0-alpha04")
testImplementation("junit:junit:4.13.2") testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
@@ -3,15 +3,12 @@ package com.anthonyla.livewallpaper
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.core.view.WindowCompat
import com.anthonyla.livewallpaper.themes.LiveWallpaperTheme import com.anthonyla.livewallpaper.themes.LiveWallpaperTheme
import com.anthonyla.livewallpaper.ui.LiveWallpaperApp import com.anthonyla.livewallpaper.ui.LiveWallpaperApp
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// Enable full screen app mode
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent { setContent {
LiveWallpaperTheme { LiveWallpaperTheme {
LiveWallpaperApp() LiveWallpaperApp()
@@ -1,12 +1,17 @@
package com.anthonyla.livewallpaper.navigation package com.anthonyla.livewallpaper.navigation
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarDefaults
import androidx.compose.material3.NavigationBarDefaults.containerColor
import androidx.compose.material3.NavigationBarItem import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.navigation.NavController import androidx.navigation.NavController
@@ -25,7 +30,11 @@ fun BottomNavigationBar(
screens: List<BottomNavScreens> screens: List<BottomNavScreens>
) { ) {
NavigationBar( NavigationBar(
containerColor = MaterialTheme.colorScheme.primary, containerColor = containerColor,
contentColor = MaterialTheme.colorScheme.contentColorFor(containerColor),
tonalElevation = NavigationBarDefaults.Elevation,
windowInsets = NavigationBarDefaults.windowInsets,
modifier = Modifier
) { ) {
val navBackStackEntry by navController.currentBackStackEntryAsState() val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination val currentDestination = navBackStackEntry?.destination
@@ -1,11 +1,67 @@
package com.anthonyla.livewallpaper.themes package com.anthonyla.livewallpaper.themes
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
val Purple80 = Color(0xFFD0BCFF) val md_theme_light_primary = Color(0xFF136D34)
val PurpleGrey80 = Color(0xFFCCC2DC) val md_theme_light_onPrimary = Color(0xFFFFFFFF)
val Pink80 = Color(0xFFEFB8C8) val md_theme_light_primaryContainer = Color(0xFFA0F6AD)
val md_theme_light_onPrimaryContainer = Color(0xFF00210A)
val md_theme_light_secondary = Color(0xFF506351)
val md_theme_light_onSecondary = Color(0xFFFFFFFF)
val md_theme_light_secondaryContainer = Color(0xFFD3E8D2)
val md_theme_light_onSecondaryContainer = Color(0xFF0E1F11)
val md_theme_light_tertiary = Color(0xFF39656D)
val md_theme_light_onTertiary = Color(0xFFFFFFFF)
val md_theme_light_tertiaryContainer = Color(0xFFBDEAF4)
val md_theme_light_onTertiaryContainer = Color(0xFF001F24)
val md_theme_light_error = Color(0xFFBA1A1A)
val md_theme_light_errorContainer = Color(0xFFFFDAD6)
val md_theme_light_onError = Color(0xFFFFFFFF)
val md_theme_light_onErrorContainer = Color(0xFF410002)
val md_theme_light_background = Color(0xFFFCFDF7)
val md_theme_light_onBackground = Color(0xFF1A1C19)
val md_theme_light_surface = Color(0xFFFCFDF7)
val md_theme_light_onSurface = Color(0xFF1A1C19)
val md_theme_light_surfaceVariant = Color(0xFFDDE5DA)
val md_theme_light_onSurfaceVariant = Color(0xFF414941)
val md_theme_light_outline = Color(0xFF727970)
val md_theme_light_inverseOnSurface = Color(0xFFF0F1EC)
val md_theme_light_inverseSurface = Color(0xFF2E312E)
val md_theme_light_inversePrimary = Color(0xFF85D993)
val md_theme_light_shadow = Color(0xFF000000)
val md_theme_light_surfaceTint = Color(0xFF136D34)
val md_theme_light_outlineVariant = Color(0xFFC1C9BE)
val md_theme_light_scrim = Color(0xFF000000)
val Purple40 = Color(0xFF6650a4) val md_theme_dark_primary = Color(0xFF85D993)
val PurpleGrey40 = Color(0xFF625b71) val md_theme_dark_onPrimary = Color(0xFF003916)
val Pink40 = Color(0xFF7D5260) val md_theme_dark_primaryContainer = Color(0xFF005323)
val md_theme_dark_onPrimaryContainer = Color(0xFFA0F6AD)
val md_theme_dark_secondary = Color(0xFFB7CCB6)
val md_theme_dark_onSecondary = Color(0xFF233425)
val md_theme_dark_secondaryContainer = Color(0xFF394B3B)
val md_theme_dark_onSecondaryContainer = Color(0xFFD3E8D2)
val md_theme_dark_tertiary = Color(0xFFA1CED7)
val md_theme_dark_onTertiary = Color(0xFF00363E)
val md_theme_dark_tertiaryContainer = Color(0xFF204D55)
val md_theme_dark_onTertiaryContainer = Color(0xFFBDEAF4)
val md_theme_dark_error = Color(0xFFFFB4AB)
val md_theme_dark_errorContainer = Color(0xFF93000A)
val md_theme_dark_onError = Color(0xFF690005)
val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6)
val md_theme_dark_background = Color(0xFF1A1C19)
val md_theme_dark_onBackground = Color(0xFFE2E3DE)
val md_theme_dark_surface = Color(0xFF1A1C19)
val md_theme_dark_onSurface = Color(0xFFE2E3DE)
val md_theme_dark_surfaceVariant = Color(0xFF414941)
val md_theme_dark_onSurfaceVariant = Color(0xFFC1C9BE)
val md_theme_dark_outline = Color(0xFF8B9389)
val md_theme_dark_inverseOnSurface = Color(0xFF1A1C19)
val md_theme_dark_inverseSurface = Color(0xFFE2E3DE)
val md_theme_dark_inversePrimary = Color(0xFF136D34)
val md_theme_dark_shadow = Color(0xFF000000)
val md_theme_dark_surfaceTint = Color(0xFF85D993)
val md_theme_dark_outlineVariant = Color(0xFF414941)
val md_theme_dark_scrim = Color(0xFF000000)
val seed = Color(0xFFA5D0A8)
@@ -1,70 +1,90 @@
package com.anthonyla.livewallpaper.themes package com.anthonyla.livewallpaper.themes
import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme import androidx.compose.material3.lightColorScheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
private val DarkColorScheme = darkColorScheme(
primary = Purple80, private val LightColors = lightColorScheme(
secondary = PurpleGrey80, primary = md_theme_light_primary,
tertiary = Pink80 onPrimary = md_theme_light_onPrimary,
primaryContainer = md_theme_light_primaryContainer,
onPrimaryContainer = md_theme_light_onPrimaryContainer,
secondary = md_theme_light_secondary,
onSecondary = md_theme_light_onSecondary,
secondaryContainer = md_theme_light_secondaryContainer,
onSecondaryContainer = md_theme_light_onSecondaryContainer,
tertiary = md_theme_light_tertiary,
onTertiary = md_theme_light_onTertiary,
tertiaryContainer = md_theme_light_tertiaryContainer,
onTertiaryContainer = md_theme_light_onTertiaryContainer,
error = md_theme_light_error,
errorContainer = md_theme_light_errorContainer,
onError = md_theme_light_onError,
onErrorContainer = md_theme_light_onErrorContainer,
background = md_theme_light_background,
onBackground = md_theme_light_onBackground,
surface = md_theme_light_surface,
onSurface = md_theme_light_onSurface,
surfaceVariant = md_theme_light_surfaceVariant,
onSurfaceVariant = md_theme_light_onSurfaceVariant,
outline = md_theme_light_outline,
inverseOnSurface = md_theme_light_inverseOnSurface,
inverseSurface = md_theme_light_inverseSurface,
inversePrimary = md_theme_light_inversePrimary,
surfaceTint = md_theme_light_surfaceTint,
outlineVariant = md_theme_light_outlineVariant,
scrim = md_theme_light_scrim,
) )
private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40
/* Other default colors to override private val DarkColors = darkColorScheme(
background = Color(0xFFFFFBFE), primary = md_theme_dark_primary,
surface = Color(0xFFFFFBFE), onPrimary = md_theme_dark_onPrimary,
onPrimary = Color.White, primaryContainer = md_theme_dark_primaryContainer,
onSecondary = Color.White, onPrimaryContainer = md_theme_dark_onPrimaryContainer,
onTertiary = Color.White, secondary = md_theme_dark_secondary,
onBackground = Color(0xFF1C1B1F), onSecondary = md_theme_dark_onSecondary,
onSurface = Color(0xFF1C1B1F), secondaryContainer = md_theme_dark_secondaryContainer,
*/ onSecondaryContainer = md_theme_dark_onSecondaryContainer,
tertiary = md_theme_dark_tertiary,
onTertiary = md_theme_dark_onTertiary,
tertiaryContainer = md_theme_dark_tertiaryContainer,
onTertiaryContainer = md_theme_dark_onTertiaryContainer,
error = md_theme_dark_error,
errorContainer = md_theme_dark_errorContainer,
onError = md_theme_dark_onError,
onErrorContainer = md_theme_dark_onErrorContainer,
background = md_theme_dark_background,
onBackground = md_theme_dark_onBackground,
surface = md_theme_dark_surface,
onSurface = md_theme_dark_onSurface,
surfaceVariant = md_theme_dark_surfaceVariant,
onSurfaceVariant = md_theme_dark_onSurfaceVariant,
outline = md_theme_dark_outline,
inverseOnSurface = md_theme_dark_inverseOnSurface,
inverseSurface = md_theme_dark_inverseSurface,
inversePrimary = md_theme_dark_inversePrimary,
surfaceTint = md_theme_dark_surfaceTint,
outlineVariant = md_theme_dark_outlineVariant,
scrim = md_theme_dark_scrim,
) )
@Composable @Composable
fun LiveWallpaperTheme( fun LiveWallpaperTheme(
darkTheme: Boolean = isSystemInDarkTheme(), useDarkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+ content: @Composable() () -> Unit
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) { ) {
val colorScheme = when { val colors = if (!useDarkTheme) {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { LightColors
val context = LocalContext.current } else {
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) DarkColors
} }
darkTheme -> DarkColorScheme MaterialTheme(
else -> LightColorScheme colorScheme = colors,
} content = content
val view = LocalView.current )
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
}
}
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content
)
} }
@@ -1,5 +1,6 @@
package com.anthonyla.livewallpaper.ui package com.anthonyla.livewallpaper.ui
import android.app.Activity
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
@@ -7,6 +8,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.anthonyla.livewallpaper.navigation.BottomNavScreens import com.anthonyla.livewallpaper.navigation.BottomNavScreens
@@ -17,15 +21,7 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun LiveWallpaperApp(modifier: Modifier = Modifier) { fun LiveWallpaperApp(modifier: Modifier = Modifier) {
// Transparent status bar SetTransparentSystemBars()
val systemUiController = rememberSystemUiController()
SideEffect {
systemUiController.setStatusBarColor(
color = Color.Transparent,
// check if app is in dark mode or not
darkIcons = false
)
}
// Bottom navigation // Bottom navigation
val navController = rememberNavController() val navController = rememberNavController()
@@ -47,4 +43,20 @@ fun LiveWallpaperApp(modifier: Modifier = Modifier) {
bottomNav(navController) bottomNav(navController)
} }
} }
}
@Composable
fun SetTransparentSystemBars() {
val systemUiController = rememberSystemUiController()
val view = LocalView.current
SideEffect {
with(view.context as Activity) {
WindowCompat.setDecorFitsSystemWindows(window, false)
systemUiController.setSystemBarsColor(
color = Color.Transparent,
// check if app is in dark mode or not
darkIcons = false
)
}
}
} }