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

Commit 43bd6605 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Fix connected display dialog overlap with 3 buttons nav

The content insets are now aware of the navbar size.
Note that this can't be put in the base class (SystemUIBottomSheet), as
it is specific to the content of the dialog. The base class only cares
about the window.

Fixes: 306541121
Test: SystemUIBottomSheetDialogTest + manually trying all navigation
       modes and orientations
Change-Id: I3fc5e152026b93c6415a3f5bd0d011c3c86e0fd8
parent 09435f86
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -19,9 +19,12 @@ import android.content.Context
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.core.view.updatePadding
import com.android.systemui.biometrics.Utils
import com.android.systemui.res.R
import com.android.systemui.statusbar.phone.SystemUIBottomSheetDialog
import com.android.systemui.statusbar.policy.ConfigurationController
import kotlin.math.max

/**
 * Dialog used to decide what to do with a connected display.
@@ -58,5 +61,23 @@ class MirroringConfirmationDialog(
                onCancelMirroring.onClick(null)
            }
        }
        setupInsets()
    }

    private fun setupInsets() {
        // This avoids overlap between dialog content and navigation bars.
        requireViewById<View>(R.id.cd_bottom_sheet).apply {
            val navbarInsets = Utils.getNavbarInsets(context)
            val defaultDialogBottomInset =
                context.resources.getDimensionPixelSize(R.dimen.dialog_bottom_padding)
            // we only care about the bottom inset as in all other configuration where navigations
            // are in other display sides there is no overlap with the dialog.
            updatePadding(bottom = max(navbarInsets.bottom, defaultDialogBottomInset))
        }
    }

    override fun onConfigurationChanged() {
        super.onConfigurationChanged()
        setupInsets()
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -77,11 +77,15 @@ open class SystemUIBottomSheetDialog(
        configurationController?.removeCallback(onConfigChanged)
    }

    /** Can be overridden by subclasses to receive config changed events. */
    open fun onConfigurationChanged() {}

    private val onConfigChanged =
        object : ConfigurationListener {
            override fun onConfigChanged(newConfig: Configuration?) {
                super.onConfigChanged(newConfig)
                setupEdgeToEdge()
                onConfigurationChanged()
            }
        }
}
+24 −0
Original line number Diff line number Diff line
@@ -13,13 +13,17 @@
 */
package com.android.systemui.statusbar.phone

import android.content.res.Configuration
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper.RunWithLooper
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.mockito.mock
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import org.junit.Before
import org.junit.runner.RunWith
@@ -31,6 +35,7 @@ import org.mockito.Mockito.verify
class SystemUIBottomSheetDialogTest : SysuiTestCase() {

    private val configurationController = mock<ConfigurationController>()
    private val config = mock<Configuration>()

    private lateinit var dialog: SystemUIBottomSheetDialog

@@ -53,4 +58,23 @@ class SystemUIBottomSheetDialogTest : SysuiTestCase() {

        verify(configurationController).removeCallback(any())
    }

    @Test
    fun onConfigurationChanged_calledInSubclass() {
        var onConfigChangedCalled = false
        val subclass =
            object : SystemUIBottomSheetDialog(mContext, configurationController) {
                override fun onConfigurationChanged() {
                    onConfigChangedCalled = true
                }
            }

        subclass.show()

        val captor = argumentCaptor<ConfigurationController.ConfigurationListener>()
        verify(configurationController).addCallback(capture(captor))
        captor.value.onConfigChanged(config)

        assertThat(onConfigChangedCalled).isTrue()
    }
}