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

Commit 6133c570 authored by Bharat Singh's avatar Bharat Singh
Browse files

[SysUI][Floaty] Use pixel display size ratio for scaling rounded corners

Bug: 407953099
Flag: com.android.systemui.shared.enable_lpp_assist_invocation_effect
Test: manual, by following steps:
1. Get dump state of ScreenDecorations by "adb shell dumpsys activity
   service com.android.systemui | grep -i -A 100 "ScreenDecorations
   state""
2. Log the pixel display size ratio and scaled size of rounded corners for SqueezeEffect
3. Values obtained in #1 and #2 should match
4. Try the squeeze effect with scaled rounded corners on Pixel 8 Pro and Pixel 9. In both phones, rounded corners should smoothly transition from actual device rounded corners.
Change-Id: I1c84143a394607f4b574a61b67ca5379489c133e
parent 85037edb
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ constructor(
                        // threshold of initial delay
                        launchWindowEffect?.cancel()
                        if (down) {
                            val roundedCornerId =
                            val roundedCornerInfo =
                                async(context = bgContext) {
                                    squeezeEffectInteractor.getRoundedCornersResourceId()
                                }
@@ -75,8 +75,9 @@ constructor(
                            launchWindowEffect = launch {
                                delay(initialDelay.await())
                                addWindow(
                                    roundedCornerId.await().top,
                                    roundedCornerId.await().bottom,
                                    roundedCornerInfo.await().topResourceId,
                                    roundedCornerInfo.await().bottomResourceId,
                                    roundedCornerInfo.await().physicalPixelDisplaySizeRatio,
                                )
                            }
                        } else {
@@ -91,6 +92,7 @@ constructor(
    private fun addWindow(
        @DrawableRes topRoundedCornerId: Int,
        @DrawableRes bottomRoundedCornerId: Int,
        physicalPixelDisplaySizeRatio: Float,
    ) {
        if (root == null) {
            root =
@@ -99,6 +101,7 @@ constructor(
                    viewModelFactory = viewModelFactory,
                    topRoundedCornerResourceId = topRoundedCornerId,
                    bottomRoundedCornerResourceId = bottomRoundedCornerId,
                    physicalPixelDisplaySizeRatio = physicalPixelDisplaySizeRatio,
                    onEffectFinished = {
                        if (root?.isAttachedToWindow == true) {
                            windowManager.removeView(root)
+7 −1
Original line number Diff line number Diff line
@@ -16,4 +16,10 @@

package com.android.systemui.topwindoweffects.data.entity

data class SqueezeEffectCornerResourceId(val top: Int, val bottom: Int)
import androidx.annotation.DrawableRes

data class SqueezeEffectCornersInfo(
    @DrawableRes val topResourceId: Int,
    @DrawableRes val bottomResourceId: Int,
    val physicalPixelDisplaySizeRatio: Float,
)
+2 −2
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.systemui.topwindoweffects.data.repository

import com.android.systemui.topwindoweffects.data.entity.SqueezeEffectCornerResourceId
import com.android.systemui.topwindoweffects.data.entity.SqueezeEffectCornersInfo
import kotlinx.coroutines.flow.Flow

interface SqueezeEffectRepository {
@@ -24,5 +24,5 @@ interface SqueezeEffectRepository {

    suspend fun getInvocationEffectInitialDelayMs(): Long

    suspend fun getRoundedCornersResourceId(): SqueezeEffectCornerResourceId
    suspend fun getRoundedCornersInfo(): SqueezeEffectCornersInfo
}
+19 −5
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.res.R
import com.android.systemui.shared.Flags
import com.android.systemui.topwindoweffects.data.entity.SqueezeEffectCornerResourceId
import com.android.systemui.topwindoweffects.data.entity.SqueezeEffectCornersInfo
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import javax.inject.Inject
@@ -93,24 +93,38 @@ constructor(
        }
    }

    override suspend fun getRoundedCornersResourceId(): SqueezeEffectCornerResourceId {
    override suspend fun getRoundedCornersInfo(): SqueezeEffectCornersInfo {
        val displayInfo = DisplayInfo()
        context.display.getDisplayInfo(displayInfo)
        val displayIndex =
            DisplayUtils.getDisplayUniqueIdConfigIndex(context.resources, displayInfo.uniqueId)
        return SqueezeEffectCornerResourceId(
            top =
        val maxResDisplayMode =
            DisplayUtils.getMaximumResolutionDisplayMode(displayInfo.supportedModes)
        val ratio =
            if (maxResDisplayMode == null) {
                1f
            } else {
                DisplayUtils.getPhysicalPixelDisplaySizeRatio(
                    /*physicalWidth = */ maxResDisplayMode.physicalWidth,
                    /*physicalHeight = */ maxResDisplayMode.physicalHeight,
                    /*currentWidth = */ displayInfo.naturalWidth,
                    /*currentHeight = */ displayInfo.naturalHeight,
                )
            }
        return SqueezeEffectCornersInfo(
            topResourceId =
                getDrawableResource(
                    displayIndex = displayIndex,
                    arrayResId = R.array.config_roundedCornerTopDrawableArray,
                    backupDrawableId = R.drawable.rounded_corner_top,
                ),
            bottom =
            bottomResourceId =
                getDrawableResource(
                    displayIndex = displayIndex,
                    arrayResId = R.array.config_roundedCornerBottomDrawableArray,
                    backupDrawableId = R.drawable.rounded_corner_bottom,
                ),
            physicalPixelDisplaySizeRatio = ratio,
        )
    }

+1 −2
Original line number Diff line number Diff line
@@ -29,6 +29,5 @@ constructor(private val squeezeEffectRepository: SqueezeEffectRepository) {
    suspend fun getInvocationEffectInitialDelayMs() =
        squeezeEffectRepository.getInvocationEffectInitialDelayMs()

    suspend fun getRoundedCornersResourceId() =
        squeezeEffectRepository.getRoundedCornersResourceId()
    suspend fun getRoundedCornersResourceId() = squeezeEffectRepository.getRoundedCornersInfo()
}
Loading