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

Commit 4621d9c4 authored by Andreas Agvard's avatar Andreas Agvard
Browse files

Clarification to squeeze effect names and comments

 - isSqueezeEffectAnimatingInwards changed to isMainAnimationRunning since this animation animates both inwards and then outwards.
 - Comments updated to clarify that main animation goes both in and out.
 - Ran ktfmt to format file according to standard

Bug: 399263897
Flag: com.android.systemui.shared.enable_lpp_assist_invocation_effect
Test: manual sanity check - this change shouldn't affect any logic
Change-Id: If9e62b52b9a116ee4e23c8443df077bc4b4b6e3b
parent d68eed42
Loading
Loading
Loading
Loading
+38 −44
Original line number Original line Diff line number Diff line
@@ -49,7 +49,7 @@ private val SqueezeColor = Color.Black
fun SqueezeEffect(
fun SqueezeEffect(
    viewModelFactory: SqueezeEffectViewModel.Factory,
    viewModelFactory: SqueezeEffectViewModel.Factory,
    onEffectFinished: () -> Unit,
    onEffectFinished: () -> Unit,
    modifier: Modifier = Modifier
    modifier: Modifier = Modifier,
) {
) {
    val viewModel = rememberViewModel(traceName = "SqueezeEffect") { viewModelFactory.create() }
    val viewModel = rememberViewModel(traceName = "SqueezeEffect") { viewModelFactory.create() }


@@ -62,45 +62,41 @@ fun SqueezeEffect(


    val squeezeProgress = remember { Animatable(0f) }
    val squeezeProgress = remember { Animatable(0f) }


    // Flag to check if the squeeze effect is interruptible or not. If the power button was long
    // The squeeze animation has two states indicated by the value of this flag:
    // pressed, the squeeze animation finishes without being interrupted by the state of power
    // true - the main animation is running, animating the progress to 1 and then back to 0.
    // button.
    // false - the main animation has been interrupted and we are animating back to 0. This happens
    var isSqueezeAnimationInterruptible by remember { mutableStateOf(true) }
    //         if the user let's go of the power button before long press power has been detected.

    // Flag to check if Squeeze effect progressing inward on the device (progress value moving
    // towards 1). There are following possible cases for squeeze effect animation -
    // Case 1 - Power button was long pressed
    //      Squeeze effect progress value goes to 1 and afterwards this value goes back to 0.
    // Case 2 - Power button was pressed but released just before long press threshold
    //      Squeeze effect progress value goes towards 1 and as soon as the power button is released
    //      this value goes back to 0.
    // In both the above cases, as soon as the squeeze effect finishes animating (progress value
    // In both the above cases, as soon as the squeeze effect finishes animating (progress value
    // becomes 0 again), we execute the "onEffectFinished" block which ensures that effects window
    // becomes 0 again), we execute the "onEffectFinished" block which ensures that effects window
    // is removed.
    // is removed.
    var isSqueezeEffectAnimatingInwards by remember { mutableStateOf(false) }
    var isMainAnimationRunning by remember { mutableStateOf(false) }

    // The main animation is interruptible until power button long press has been detected. At this
    // point the default assistant is invoked, and since this invocation cannot be interrupted by
    // lifting the power button the animation shouldn't be interruptible either.
    var isAnimationInterruptible by remember { mutableStateOf(true) }


    LaunchedEffect(longPressed) {
    LaunchedEffect(longPressed) {
        if (longPressed) {
        if (longPressed) {
            isSqueezeAnimationInterruptible = false
            isAnimationInterruptible = false
        }
        }
    }
    }


    LaunchedEffect(down, isSqueezeAnimationInterruptible) {
    LaunchedEffect(down, isAnimationInterruptible) {
        isSqueezeEffectAnimatingInwards = down || !isSqueezeAnimationInterruptible
        isMainAnimationRunning = down || !isAnimationInterruptible
    }
    }


    LaunchedEffect(isSqueezeEffectAnimatingInwards) {
    LaunchedEffect(isMainAnimationRunning) {
        if (isSqueezeEffectAnimatingInwards) {
        if (isMainAnimationRunning) {
            squeezeProgress.animateTo(1f, animationSpec = tween(durationMillis = 800))
            squeezeProgress.animateTo(1f, animationSpec = tween(durationMillis = 800))
            squeezeProgress.animateTo(0f, animationSpec = tween(durationMillis = 333))
            squeezeProgress.animateTo(0f, animationSpec = tween(durationMillis = 333))
            if (squeezeProgress.value == 0f) {
            if (squeezeProgress.value == 0f) {
                onEffectFinished()
                onEffectFinished()
            }
            }
            isSqueezeAnimationInterruptible = true
            isAnimationInterruptible = true
        } else {
        } else {
            if (squeezeProgress.value != 0f) {
            if (squeezeProgress.value != 0f) {
                squeezeProgress
                squeezeProgress.animateTo(0f, animationSpec = tween(durationMillis = 333))
                    .animateTo(0f, animationSpec = tween(durationMillis = 333))
            }
            }
            if (squeezeProgress.value == 0f) {
            if (squeezeProgress.value == 0f) {
                onEffectFinished()
                onEffectFinished()
@@ -120,7 +116,7 @@ fun SqueezeEffect(
        drawRect(
        drawRect(
            color = SqueezeColor,
            color = SqueezeColor,
            topLeft = Offset(0f, size.height - squeezeThickness),
            topLeft = Offset(0f, size.height - squeezeThickness),
            size = Size(size.width, squeezeThickness)
            size = Size(size.width, squeezeThickness),
        )
        )


        drawRect(color = SqueezeColor, size = Size(squeezeThickness, size.height))
        drawRect(color = SqueezeColor, size = Size(squeezeThickness, size.height))
@@ -128,35 +124,30 @@ fun SqueezeEffect(
        drawRect(
        drawRect(
            color = SqueezeColor,
            color = SqueezeColor,
            topLeft = Offset(size.width - squeezeThickness, 0f),
            topLeft = Offset(size.width - squeezeThickness, 0f),
            size = Size(squeezeThickness, size.height)
            size = Size(squeezeThickness, size.height),
        )
        )


        drawTransform(
        drawTransform(dx = squeezeThickness, dy = squeezeThickness, rotation = 0f, corner = top)
            dx = squeezeThickness,
            dy = squeezeThickness,
            rotation = 0f,
            corner = top
        )


        drawTransform(
        drawTransform(
            dx = size.width - squeezeThickness,
            dx = size.width - squeezeThickness,
            dy = squeezeThickness,
            dy = squeezeThickness,
            rotation = 90f,
            rotation = 90f,
            corner = top
            corner = top,
        )
        )


        drawTransform(
        drawTransform(
            dx = squeezeThickness,
            dx = squeezeThickness,
            dy = size.height - squeezeThickness,
            dy = size.height - squeezeThickness,
            rotation = 270f,
            rotation = 270f,
            corner = bottom
            corner = bottom,
        )
        )


        drawTransform(
        drawTransform(
            dx = size.width - squeezeThickness,
            dx = size.width - squeezeThickness,
            dy = size.height - squeezeThickness,
            dy = size.height - squeezeThickness,
            rotation = 180f,
            rotation = 180f,
            corner = bottom
            corner = bottom,
        )
        )
    }
    }
}
}
@@ -167,16 +158,19 @@ private fun DrawScope.drawTransform(
    rotation: Float = 0f,
    rotation: Float = 0f,
    corner: VectorPainter,
    corner: VectorPainter,
) {
) {
    withTransform(transformBlock = {
    withTransform(
        transform(matrix = Matrix().apply {
        transformBlock = {
            transform(
                matrix =
                    Matrix().apply {
                        translate(dx, dy)
                        translate(dx, dy)
                        if (rotation != 0f) {
                        if (rotation != 0f) {
                            rotateZ(rotation)
                            rotateZ(rotation)
                        }
                        }
        })
    }) {
        with(corner) {
            draw(size = intrinsicSize)
                    }
                    }
            )
        }
    ) {
        with(corner) { draw(size = intrinsicSize) }
    }
    }
}
}