Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Composable
- fun AudioPlayerProgressUI(
- progress: Float,
- modifier: Modifier = Modifier
- ) {
- val animatedProgress by animateFloatAsState(
- targetValue = progress,
- animationSpec = tween(500, easing = LinearEasing),
- label = "Seek bar progress"
- )
- BoxWithConstraints(
- modifier = modifier
- .fillMaxSize()
- .background(Color.Gray)
- ) {
- val screenWidth = maxWidth.value
- val screenHeight = maxHeight.value
- val dummyHeight = LocalConfiguration.current.screenHeightDp
- Text(
- text = "OuterLayoutHeight --> {${dummyHeight.dp}} {$screenHeight}",
- modifier = Modifier.align(Alignment.TopStart)
- )
- val barsCount = remember {
- screenWidth / 2
- }.toInt()
- val random = remember {
- Random.Default
- }
- val heights = remember {
- buildList {
- for (i in 0..barsCount) {
- add(element = screenHeight * (random.nextFloat() * 0.5f + 0.1f))
- }
- }.toPersistentList()
- }
- val space = remember {
- maxWidth / 35
- }.value
- var startX = remember {
- 0f
- }
- val path = remember {
- Path().apply {
- heights.forEachIndexed { index, barHeight ->
- addRoundRect(
- RoundRect(
- rect = Rect(
- offset = Offset(
- x = startX,
- y = (screenHeight) * 0.5f
- ),
- size = Size(width = screenWidth * 0.01f, barHeight)
- ),
- radiusX = 10f,
- radiusY = 10f
- )
- )
- startX += space
- }
- close()
- }
- }
- val textMeasurer = rememberTextMeasurer()
- Canvas(
- modifier = Modifier
- .padding(top = 40.dp)
- .fillMaxSize()
- .background(Color.Green)
- ) {
- val canvasWidth = size.width
- val canvasHeight = size.height
- drawRect(
- color = Color.Red,
- topLeft = Offset(0f, canvasHeight * 0.25f),
- size = Size(
- width = canvasWidth * animatedProgress,
- height = canvasHeight * 0.5f
- )
- )
- clipPath(path = path, clipOp = ClipOp.Difference) {
- drawRoundRect(
- color = Color.Transparent,
- size = Size(width = canvasWidth, height = canvasHeight),
- cornerRadius = CornerRadius(screenWidth * 0.05f, screenWidth * 0.05f)
- )
- }
- drawText(
- textMeasurer.measure(
- text = "Canvas Height -> {$canvasHeight}",
- style = TextStyle(
- color = Color.Blue,
- textAlign = TextAlign.Center,
- fontSize = 24.sp
- ),
- maxLines = 2,
- overflow = Ellipsis,
- )
- )
- }
- }
- }
- @Preview
- @Composable
- fun PreviewAudioPlayerProgressUI() {
- ScrutinizingTheServiceTheme {
- AudioPlayerProgressUI(
- progress = 0.0f,
- modifier = Modifier.fillMaxSize()
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment