Merge "Display smartspace in lockscreen preview" into udc-dev

This commit is contained in:
Brad Hinegardner
2023-04-21 17:39:47 +00:00
committed by Android (Google) Code Review
3 changed files with 107 additions and 17 deletions

View File

@@ -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"

View File

@@ -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) {
setUpClock(rootView) setupSmartspace(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) {
?.events val largeClock = clockController.clock?.largeClock
?.onTargetRegionChanged(KeyguardClockSwitch.getLargeClockRegion(parentView))
clockView?.let { parentView.removeView(it) } largeClock
clockView = ?.events
clockController.clock?.largeClock?.view?.apply { ?.onTargetRegionChanged(KeyguardClockSwitch.getLargeClockRegion(parentView))
clockView?.let { parentView.removeView(it) }
clockView = 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 {

View File

@@ -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)
} }