Skip to content

Commit 7804a9a

Browse files
authored
Enable edge-to-edge in the demo application (#658)
1 parent 415a79d commit 7804a9a

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package ch.srgssr.pillarbox.demo
77
import android.os.Bundle
88
import androidx.activity.ComponentActivity
99
import androidx.activity.compose.setContent
10+
import androidx.activity.enableEdgeToEdge
1011
import androidx.compose.foundation.layout.fillMaxSize
1112
import androidx.compose.material3.MaterialTheme
1213
import androidx.compose.material3.Surface
@@ -20,7 +21,10 @@ import ch.srgssr.pillarbox.demo.ui.theme.PillarboxTheme
2021
*/
2122
class MainActivity : ComponentActivity() {
2223
override fun onCreate(savedInstanceState: Bundle?) {
24+
enableEdgeToEdge()
25+
2326
super.onCreate(savedInstanceState)
27+
2428
setContent {
2529
PillarboxTheme {
2630
// A surface container using the 'background' color from the theme

pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerActivity.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import android.content.Context
1010
import android.content.Intent
1111
import android.content.ServiceConnection
1212
import android.content.res.Configuration
13+
import android.graphics.Color
1314
import android.os.Build
1415
import android.os.Bundle
1516
import android.os.IBinder
1617
import androidx.activity.ComponentActivity
18+
import androidx.activity.SystemBarStyle
1719
import androidx.activity.compose.setContent
20+
import androidx.activity.enableEdgeToEdge
1821
import androidx.annotation.RequiresApi
1922
import androidx.compose.foundation.layout.fillMaxSize
23+
import androidx.compose.foundation.layout.navigationBarsPadding
24+
import androidx.compose.foundation.layout.statusBarsPadding
2025
import androidx.compose.material3.MaterialTheme
2126
import androidx.compose.material3.Surface
2227
import androidx.compose.runtime.Composable
@@ -45,11 +50,11 @@ import java.net.URL
4550
/**
4651
* Simple player activity that can handle picture in picture.
4752
*
48-
* It handle basic background playback, as it will stop playback when the Activity is destroyed!
49-
* To have pure background playback with good integration from other device like Auto, Wear, etc... we need *MediaSessionService*
53+
* It handles basic background playback, as it will stop playback when the Activity is destroyed!
54+
* To have pure background playback with good integration from other devices like Auto, Wear, etc... we need *MediaSessionService*
5055
*
5156
* For this demo, only the picture in picture button can enable picture in picture.
52-
* But feel free to call [startPictureInPicture] whenever you decide, for example when [onUserLeaveHint]
57+
* But feel free to call [startPictureInPicture] whenever you decide, for example, when [onUserLeaveHint]
5358
*/
5459
class SimplePlayerActivity : ComponentActivity(), ServiceConnection {
5560

@@ -64,7 +69,13 @@ class SimplePlayerActivity : ComponentActivity(), ServiceConnection {
6469
}
6570

6671
override fun onCreate(savedInstanceState: Bundle?) {
72+
enableEdgeToEdge(
73+
statusBarStyle = SystemBarStyle.dark(Color.BLACK),
74+
navigationBarStyle = SystemBarStyle.dark(Color.BLACK),
75+
)
76+
6777
super.onCreate(savedInstanceState)
78+
6879
val ilHost = IntentCompat.getSerializableExtra(intent, ARG_IL_HOST, URL::class.java) ?: IlHost.DEFAULT
6980
playerViewModel = ViewModelProvider(this, factory = SimplePlayerViewModel.Factory(application, ilHost))[SimplePlayerViewModel::class.java]
7081
readIntent(intent)
@@ -83,7 +94,13 @@ class SimplePlayerActivity : ComponentActivity(), ServiceConnection {
8394
bindPlaybackService()
8495
setContent {
8596
PillarboxTheme {
86-
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
97+
Surface(
98+
modifier = Modifier
99+
.fillMaxSize()
100+
.statusBarsPadding()
101+
.navigationBarsPadding(),
102+
color = MaterialTheme.colorScheme.background,
103+
) {
87104
MainContent(playerViewModel.player)
88105
}
89106
}

pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.Arrangement
1717
import androidx.compose.foundation.layout.Box
1818
import androidx.compose.foundation.layout.Column
1919
import androidx.compose.foundation.layout.Row
20+
import androidx.compose.foundation.layout.WindowInsets
2021
import androidx.compose.foundation.layout.fillMaxHeight
2122
import androidx.compose.foundation.layout.fillMaxSize
2223
import androidx.compose.foundation.layout.fillMaxWidth
@@ -287,7 +288,8 @@ private fun SearchInput(
287288
}
288289
}
289290
},
290-
shape = MaterialTheme.shapes.large
291+
shape = MaterialTheme.shapes.large,
292+
windowInsets = WindowInsets(0.dp),
291293
) {}
292294

293295
LaunchedEffect(Unit) {

pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/theme/PillarboxTheme.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@
44
*/
55
package ch.srgssr.pillarbox.demo.ui.theme
66

7-
import android.app.Activity
87
import androidx.compose.foundation.isSystemInDarkTheme
98
import androidx.compose.material3.MaterialTheme
109
import androidx.compose.material3.darkColorScheme
1110
import androidx.compose.material3.lightColorScheme
1211
import androidx.compose.runtime.Composable
1312
import androidx.compose.runtime.CompositionLocalProvider
14-
import androidx.compose.runtime.SideEffect
15-
import androidx.compose.ui.graphics.toArgb
16-
import androidx.compose.ui.platform.LocalView
17-
import androidx.core.view.WindowCompat
1813
import ch.srgssr.pillarbox.demo.shared.ui.theme.md_theme_dark_background
1914
import ch.srgssr.pillarbox.demo.shared.ui.theme.md_theme_dark_error
2015
import ch.srgssr.pillarbox.demo.shared.ui.theme.md_theme_dark_errorContainer
@@ -157,15 +152,6 @@ fun PillarboxTheme(
157152
lightColorScheme
158153
}
159154

160-
val view = LocalView.current
161-
if (!view.isInEditMode) {
162-
SideEffect {
163-
val window = (view.context as Activity).window
164-
window.statusBarColor = colorScheme.primary.toArgb()
165-
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
166-
}
167-
}
168-
169155
MaterialTheme(colorScheme = colorScheme) {
170156
CompositionLocalProvider(
171157
LocalPaddings provides paddings,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<style name="Theme.PillarboxDemo" parent="android:Theme.Material.NoActionBar" />
5+
</resources>

0 commit comments

Comments
 (0)