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

Commit 8bf3a9ad authored by Brad Hinegardner's avatar Brad Hinegardner
Browse files

Display smartspace in lockscreen preview

Bug: b/271338533
Test: manual - smartspace shows up in proper screen location on landscape and portrait accross various devices
Test: manual - smartspace has correct alpha when selecting custom lockscreen shortcuts
Test: manual - smartspace can hide and show when requested to do so
Test: manual - after clock is set up, the smartspace hides or shows based on whether or not the clock has date or weather in it
Change-Id: Ib5cc63239df86de48f021c55571b4285594a3e8e
parent 5fb1e0aa
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -17,7 +17,9 @@


package com.android.systemui.shared.quickaffordance.shared.model
package com.android.systemui.shared.quickaffordance.shared.model


object KeyguardQuickAffordancePreviewConstants {
object KeyguardPreviewConstants {
    const val MESSAGE_ID_HIDE_SMART_SPACE = 1111
    const val KEY_HIDE_SMART_SPACE = "hide_smart_space"
    const val MESSAGE_ID_SLOT_SELECTED = 1337
    const val MESSAGE_ID_SLOT_SELECTED = 1337
    const val KEY_SLOT_ID = "slot_id"
    const val KEY_SLOT_ID = "slot_id"
    const val KEY_INITIALLY_SELECTED_SLOT_ID = "initially_selected_slot_id"
    const val KEY_INITIALLY_SELECTED_SLOT_ID = "initially_selected_slot_id"
+96 −13
Original line number Original line Diff line number Diff line
@@ -39,7 +39,8 @@ import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.ui.viewmodel.KeyguardBottomAreaViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardBottomAreaViewModel
import com.android.systemui.shared.clocks.ClockRegistry
import com.android.systemui.shared.clocks.ClockRegistry
import com.android.systemui.shared.clocks.shared.model.ClockPreviewConstants
import com.android.systemui.shared.clocks.shared.model.ClockPreviewConstants
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import com.android.systemui.statusbar.phone.KeyguardBottomAreaView
import com.android.systemui.statusbar.phone.KeyguardBottomAreaView
import dagger.assisted.Assisted
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import dagger.assisted.AssistedInject
@@ -59,6 +60,7 @@ constructor(
    private val clockController: ClockEventController,
    private val clockController: ClockEventController,
    private val clockRegistry: ClockRegistry,
    private val clockRegistry: ClockRegistry,
    private val broadcastDispatcher: BroadcastDispatcher,
    private val broadcastDispatcher: BroadcastDispatcher,
    private val lockscreenSmartspaceController: LockscreenSmartspaceController,
    @Assisted bundle: Bundle,
    @Assisted bundle: Bundle,
) {
) {


@@ -67,7 +69,7 @@ constructor(
    private val height: Int = bundle.getInt(KEY_VIEW_HEIGHT)
    private val height: Int = bundle.getInt(KEY_VIEW_HEIGHT)
    private val shouldHighlightSelectedAffordance: Boolean =
    private val shouldHighlightSelectedAffordance: Boolean =
        bundle.getBoolean(
        bundle.getBoolean(
            KeyguardQuickAffordancePreviewConstants.KEY_HIGHLIGHT_QUICK_AFFORDANCES,
            KeyguardPreviewConstants.KEY_HIGHLIGHT_QUICK_AFFORDANCES,
            false,
            false,
        )
        )
    private val shouldHideClock: Boolean =
    private val shouldHideClock: Boolean =
@@ -79,6 +81,7 @@ constructor(
        get() = host.surfacePackage
        get() = host.surfacePackage


    private var clockView: View? = null
    private var clockView: View? = null
    private var smartSpaceView: View? = null


    private val disposables = mutableSetOf<DisposableHandle>()
    private val disposables = mutableSetOf<DisposableHandle>()
    private var isDestroyed = false
    private var isDestroyed = false
@@ -87,7 +90,7 @@ constructor(
        bottomAreaViewModel.enablePreviewMode(
        bottomAreaViewModel.enablePreviewMode(
            initiallySelectedSlotId =
            initiallySelectedSlotId =
                bundle.getString(
                bundle.getString(
                    KeyguardQuickAffordancePreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID,
                    KeyguardPreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID,
                ),
                ),
            shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance,
            shouldHighlightSelectedAffordance = shouldHighlightSelectedAffordance,
        )
        )
@@ -108,9 +111,10 @@ constructor(
            val rootView = FrameLayout(context)
            val rootView = FrameLayout(context)


            setUpBottomArea(rootView)
            setUpBottomArea(rootView)
            if (!shouldHideClock) {

            setupSmartspace(rootView)

            setUpClock(rootView)
            setUpClock(rootView)
            }


            rootView.measure(
            rootView.measure(
                View.MeasureSpec.makeMeasureSpec(
                View.MeasureSpec.makeMeasureSpec(
@@ -147,9 +151,62 @@ constructor(


    fun destroy() {
    fun destroy() {
        isDestroyed = true
        isDestroyed = true
        lockscreenSmartspaceController.disconnect()
        disposables.forEach { it.dispose() }
        disposables.forEach { it.dispose() }
    }
    }


    fun hideSmartspace(hide: Boolean) {
        smartSpaceView?.visibility = if (hide) View.INVISIBLE else View.VISIBLE
    }

    /**
     * This sets up and shows a non-interactive smart space
     *
     * The top padding is as follows:
     *    Status bar height + clock top margin + keyguard smart space top offset
     *
     * The start padding is as follows:
     *    Clock padding start + Below clock padding start
     *
     * The end padding is as follows:
     *    Below clock padding end
     */
    private fun setupSmartspace(parentView: ViewGroup) {
        if (!lockscreenSmartspaceController.isEnabled() ||
                !lockscreenSmartspaceController.isDateWeatherDecoupled()) {
            return
        }

        smartSpaceView = lockscreenSmartspaceController.buildAndConnectDateView(parentView)

        val topPadding: Int = with(context.resources) {
            getDimensionPixelSize(R.dimen.status_bar_header_height_keyguard) +
                    getDimensionPixelSize(R.dimen.keyguard_smartspace_top_offset) +
                    getDimensionPixelSize(R.dimen.keyguard_clock_top_margin)
        }

        val startPadding: Int = with(context.resources) {
            getDimensionPixelSize(R.dimen.clock_padding_start) +
                    getDimensionPixelSize(R.dimen.below_clock_padding_start)
        }

        val endPadding: Int = context.resources
                .getDimensionPixelSize(R.dimen.below_clock_padding_end)

        smartSpaceView?.let {
            it.setPaddingRelative(startPadding, topPadding, endPadding, 0)
            it.isClickable = false

            parentView.addView(
                    it,
                    FrameLayout.LayoutParams(
                            FrameLayout.LayoutParams.MATCH_PARENT,
                            FrameLayout.LayoutParams.WRAP_CONTENT,
                    ),
            )
        }
    }

    private fun setUpBottomArea(parentView: ViewGroup) {
    private fun setUpBottomArea(parentView: ViewGroup) {
        val bottomAreaView =
        val bottomAreaView =
            LayoutInflater.from(context)
            LayoutInflater.from(context)
@@ -202,22 +259,48 @@ constructor(
        disposables.add(DisposableHandle { broadcastDispatcher.unregisterReceiver(receiver) })
        disposables.add(DisposableHandle { broadcastDispatcher.unregisterReceiver(receiver) })


        onClockChanged(parentView)
        onClockChanged(parentView)

        updateSmartspaceWithSetupClock()
    }
    }


    private fun onClockChanged(parentView: ViewGroup) {
    private fun onClockChanged(parentView: ViewGroup) {
        clockController.clock = clockRegistry.createCurrentClock()
        clockController.clock = clockRegistry.createCurrentClock()
        clockController.clock

            ?.largeClock
        if (!shouldHideClock) {
            val largeClock = clockController.clock?.largeClock

            largeClock
                ?.events
                ?.events
                ?.onTargetRegionChanged(KeyguardClockSwitch.getLargeClockRegion(parentView))
                ?.onTargetRegionChanged(KeyguardClockSwitch.getLargeClockRegion(parentView))

            clockView?.let { parentView.removeView(it) }
            clockView?.let { parentView.removeView(it) }
        clockView =
            clockView = largeClock?.view?.apply {
            clockController.clock?.largeClock?.view?.apply {
                if (shouldHighlightSelectedAffordance) {
                if (shouldHighlightSelectedAffordance) {
                    alpha = DIM_ALPHA
                    alpha = DIM_ALPHA
                }
                }
                parentView.addView(this)
                parentView.addView(this)
                visibility = View.VISIBLE
            }
        } else {
            clockView?.visibility = View.GONE
        }
    }
    }

    /**
     * Updates smart space after clock is set up. Used to show or hide smartspace with the right
     * opacity based on the clock after setup.
     */
    private fun updateSmartspaceWithSetupClock() {
        val hasCustomWeatherDataDisplay =
                clockController
                        .clock
                        ?.largeClock
                        ?.config
                        ?.hasCustomWeatherDataDisplay == true

        hideSmartspace(hasCustomWeatherDataDisplay)

        smartSpaceView?.alpha = if (shouldHighlightSelectedAffordance) DIM_ALPHA else 1.0f
    }
    }


    companion object {
    companion object {
+8 −3
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants
import javax.inject.Inject
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineScope
@@ -114,13 +114,18 @@ constructor(
            }
            }


            when (message.what) {
            when (message.what) {
                KeyguardQuickAffordancePreviewConstants.MESSAGE_ID_SLOT_SELECTED -> {
                KeyguardPreviewConstants.MESSAGE_ID_SLOT_SELECTED -> {
                    message.data
                    message.data
                        .getString(
                        .getString(
                            KeyguardQuickAffordancePreviewConstants.KEY_SLOT_ID,
                            KeyguardPreviewConstants.KEY_SLOT_ID,
                        )
                        )
                        ?.let { slotId -> renderer.onSlotSelected(slotId = slotId) }
                        ?.let { slotId -> renderer.onSlotSelected(slotId = slotId) }
                }
                }
                KeyguardPreviewConstants.MESSAGE_ID_HIDE_SMART_SPACE -> {
                    message.data
                        .getBoolean(KeyguardPreviewConstants.KEY_HIDE_SMART_SPACE)
                        .let { hide -> renderer.hideSmartspace(hide) }
                }
                else -> requestDestruction(this)
                else -> requestDestruction(this)
            }
            }