Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 800e9601 authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Automerger Merge Worker
Browse files

Merge changes I018a5d6c,I85ff1c24,Iba722a17,Ic1dfd8de into udc-dev am: 1480f63c

parents c3b51212 1480f63c
Loading
Loading
Loading
Loading
+849 −0

File added.

Preview size limit exceeded, changes collapsed.

+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.android.compose.ui.util

import kotlin.math.roundToInt
import kotlin.math.roundToLong

// TODO(b/272311106): this is a fork from material. Unfork it when MathHelpers.kt reaches material3.

/** Linearly interpolate between [start] and [stop] with [fraction] fraction between them. */
fun lerp(start: Float, stop: Float, fraction: Float): Float {
    return (1 - fraction) * start + fraction * stop
}

/** Linearly interpolate between [start] and [stop] with [fraction] fraction between them. */
fun lerp(start: Int, stop: Int, fraction: Float): Int {
    return start + ((stop - start) * fraction.toDouble()).roundToInt()
}

/** Linearly interpolate between [start] and [stop] with [fraction] fraction between them. */
fun lerp(start: Long, stop: Long, fraction: Float): Long {
    return start + ((stop - start) * fraction.toDouble()).roundToLong()
}
+10 −0
Original line number Diff line number Diff line
@@ -21,8 +21,10 @@ import android.content.Context
import android.view.View
import androidx.activity.ComponentActivity
import androidx.lifecycle.LifecycleOwner
import com.android.systemui.multishade.ui.viewmodel.MultiShadeViewModel
import com.android.systemui.people.ui.viewmodel.PeopleViewModel
import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel
import com.android.systemui.util.time.SystemClock

/** The Compose facade, when Compose is *not* available. */
object ComposeFacade : BaseComposeFacade {
@@ -48,6 +50,14 @@ object ComposeFacade : BaseComposeFacade {
        throwComposeUnavailableError()
    }

    override fun createMultiShadeView(
        context: Context,
        viewModel: MultiShadeViewModel,
        clock: SystemClock,
    ): View {
        throwComposeUnavailableError()
    }

    private fun throwComposeUnavailableError(): Nothing {
        error(
            "Compose is not available. Make sure to check isComposeAvailable() before calling any" +
+20 −0
Original line number Diff line number Diff line
@@ -23,10 +23,13 @@ import androidx.activity.compose.setContent
import androidx.compose.ui.platform.ComposeView
import androidx.lifecycle.LifecycleOwner
import com.android.compose.theme.PlatformTheme
import com.android.systemui.multishade.ui.composable.MultiShade
import com.android.systemui.multishade.ui.viewmodel.MultiShadeViewModel
import com.android.systemui.people.ui.compose.PeopleScreen
import com.android.systemui.people.ui.viewmodel.PeopleViewModel
import com.android.systemui.qs.footer.ui.compose.FooterActions
import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel
import com.android.systemui.util.time.SystemClock

/** The Compose facade, when Compose is available. */
object ComposeFacade : BaseComposeFacade {
@@ -51,4 +54,21 @@ object ComposeFacade : BaseComposeFacade {
            setContent { PlatformTheme { FooterActions(viewModel, qsVisibilityLifecycleOwner) } }
        }
    }

    override fun createMultiShadeView(
        context: Context,
        viewModel: MultiShadeViewModel,
        clock: SystemClock,
    ): View {
        return ComposeView(context).apply {
            setContent {
                PlatformTheme {
                    MultiShade(
                        viewModel = viewModel,
                        clock = clock,
                    )
                }
            }
        }
    }
}
+144 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.android.systemui.multishade.ui.composable

import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.detectVerticalDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.unit.IntSize
import com.android.systemui.R
import com.android.systemui.multishade.shared.model.ProxiedInputModel
import com.android.systemui.multishade.ui.viewmodel.MultiShadeViewModel
import com.android.systemui.notifications.ui.composable.Notifications
import com.android.systemui.qs.footer.ui.compose.QuickSettings
import com.android.systemui.statusbar.ui.composable.StatusBar
import com.android.systemui.util.time.SystemClock

@Composable
fun MultiShade(
    viewModel: MultiShadeViewModel,
    clock: SystemClock,
    modifier: Modifier = Modifier,
) {
    val isScrimEnabled: Boolean by viewModel.isScrimEnabled.collectAsState()

    // TODO(b/273298030): find a different way to get the height constraint from its parent.
    BoxWithConstraints(modifier = modifier) {
        val maxHeightPx = with(LocalDensity.current) { maxHeight.toPx() }

        Scrim(
            modifier = Modifier.fillMaxSize(),
            remoteTouch = viewModel::onScrimTouched,
            alpha = { viewModel.scrimAlpha.value },
            isScrimEnabled = isScrimEnabled,
        )
        Shade(
            viewModel = viewModel.leftShade,
            currentTimeMillis = clock::elapsedRealtime,
            containerHeightPx = maxHeightPx,
            modifier = Modifier.align(Alignment.TopStart),
        ) {
            Column {
                StatusBar()
                Notifications()
            }
        }
        Shade(
            viewModel = viewModel.rightShade,
            currentTimeMillis = clock::elapsedRealtime,
            containerHeightPx = maxHeightPx,
            modifier = Modifier.align(Alignment.TopEnd),
        ) {
            Column {
                StatusBar()
                QuickSettings()
            }
        }
        Shade(
            viewModel = viewModel.singleShade,
            currentTimeMillis = clock::elapsedRealtime,
            containerHeightPx = maxHeightPx,
            modifier = Modifier,
        ) {
            Column {
                StatusBar()
                Notifications()
                QuickSettings()
            }
        }
    }
}

@Composable
private fun Scrim(
    remoteTouch: (ProxiedInputModel) -> Unit,
    alpha: () -> Float,
    isScrimEnabled: Boolean,
    modifier: Modifier = Modifier,
) {
    var size by remember { mutableStateOf(IntSize.Zero) }

    Box(
        modifier =
            modifier
                .graphicsLayer { this.alpha = alpha() }
                .background(colorResource(R.color.opaque_scrim))
                .fillMaxSize()
                .onSizeChanged { size = it }
                .then(
                    if (isScrimEnabled) {
                        Modifier.pointerInput(Unit) {
                                detectTapGestures(onTap = { remoteTouch(ProxiedInputModel.OnTap) })
                            }
                            .pointerInput(Unit) {
                                detectVerticalDragGestures(
                                    onVerticalDrag = { change, dragAmount ->
                                        remoteTouch(
                                            ProxiedInputModel.OnDrag(
                                                xFraction = change.position.x / size.width,
                                                yDragAmountPx = dragAmount,
                                            )
                                        )
                                    },
                                    onDragEnd = { remoteTouch(ProxiedInputModel.OnDragEnd) },
                                    onDragCancel = { remoteTouch(ProxiedInputModel.OnDragCancel) }
                                )
                            }
                    } else {
                        Modifier
                    }
                )
    )
}
Loading