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

Commit f150b49a authored by Anton Potapov's avatar Anton Potapov
Browse files

Fix Volume Dialog vertical margins for display large scale

The idea is that the Volume Dialog should actually stay in the middle of
the physical screen. This change compensates slider margins with the
insets to make this happen. This results in a smaller total margins
between the dialog and the edges of the screen leaving more room for it
when the display is on its largest scale.

Flag: com.android.systemui.volume_redesign
Fixes: 412572353
Fixes: 412566986
Test: atest VolumeDialogScreenshotTest
Test: manual of foldable with max display scale. Observe the Volume
Dialog appearance

Change-Id: Ic4c31a04290599db79d935bf42973ee7552b6580
parent ef4d9c46
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -17,6 +17,11 @@
package com.android.systemui.common.ui.view

import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import androidx.core.view.marginBottom
import androidx.core.view.marginLeft
import androidx.core.view.marginRight
import androidx.core.view.marginTop
import kotlinx.coroutines.DisposableHandle

/**
@@ -76,3 +81,19 @@ fun View.updateLongClickListener(listener: View.OnLongClickListener?) {
        setLongClickable(false)
    }
}

/** Sets [View] margins if its [View.getLayoutParams] is a [MarginLayoutParams]. */
fun View.updateMargin(
    left: Int = marginLeft,
    top: Int = marginTop,
    right: Int = marginRight,
    bottom: Int = marginBottom,
) {
    layoutParams =
        (layoutParams as? MarginLayoutParams)?.also {
            it.leftMargin = left
            it.topMargin = top
            it.rightMargin = right
            it.bottomMargin = bottom
        }
}
+14 −8
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import androidx.dynamicanimation.animation.SpringForce
import com.android.app.tracing.coroutines.launchInTraced
import com.android.app.tracing.coroutines.launchTraced
import com.android.systemui.common.ui.view.onApplyWindowInsets
import com.android.systemui.common.ui.view.updateMargin
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.res.R
import com.android.systemui.util.kotlin.awaitCancellationThenDispose
@@ -48,7 +49,6 @@ import kotlin.math.ceil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onEach
@@ -77,13 +77,14 @@ constructor(

    private val halfOpenedOffsetPx: Float =
        context.resources.getDimensionPixelSize(R.dimen.volume_dialog_half_opened_offset).toFloat()
    private val mainSliderVerticalMargin: Int by lazy {
        context.resources.getDimensionPixelSize(R.dimen.volume_dialog_slider_vertical_margin)
    }

    fun CoroutineScope.bind(dialog: Dialog) {
        val insets: MutableStateFlow<WindowInsets> =
            MutableStateFlow(WindowInsets.Builder().build())
        // Root view of the Volume Dialog.
        val root: ViewGroup = dialog.requireViewById(R.id.volume_dialog)

        val mainSliderContainer: View? = root.findViewById(R.id.volume_dialog_main_slider_container)
        root.accessibilityDelegate = Accessibility(viewModel)
        root.setOnHoverListener { _, event ->
            viewModel.onHover(
@@ -115,18 +116,23 @@ constructor(

        launchTraced("VDVB#insets") {
            root
                .onApplyWindowInsets { v, newInsets ->
                .onApplyWindowInsets { view, newInsets ->
                    val insetsValues =
                        newInsets.getInsets(
                            WindowInsets.Type.displayCutout() or WindowInsets.Type.navigationBars()
                            WindowInsets.Type.displayCutout() or
                                WindowInsets.Type.navigationBars() or
                                WindowInsets.Type.statusBars()
                        )
                    v.updatePadding(
                    view.updatePadding(
                        left = insetsValues.left,
                        top = insetsValues.top,
                        right = insetsValues.right,
                        bottom = insetsValues.bottom,
                    )
                    insets.value = newInsets
                    mainSliderContainer?.updateMargin(
                        top = mainSliderVerticalMargin - view.paddingTop,
                        bottom = mainSliderVerticalMargin - view.paddingBottom,
                    )
                    WindowInsets.CONSUMED
                }
                .awaitCancellationThenDispose()