Loading packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/anc/ui/composable/AncButtonComponent.kt +9 −1 Original line number Diff line number Diff line Loading @@ -54,6 +54,13 @@ constructor( override fun VolumePanelComposeScope.Content(modifier: Modifier) { val slice by viewModel.buttonSlice.collectAsState() val label = stringResource(R.string.volume_panel_noise_control_title) val isClickable = viewModel.isClickable(slice) val onClick = if (isClickable) { { ancPopup.show(null) } } else { null } Column( modifier = modifier, verticalArrangement = Arrangement.spacedBy(12.dp), Loading @@ -69,8 +76,9 @@ constructor( } .clip(RoundedCornerShape(28.dp)), slice = slice, isEnabled = onClick != null, onWidthChanged = viewModel::onButtonSliceWidthChanged, onClick = { ancPopup.show(null) } onClick = onClick, ) Text( modifier = Modifier.clearAndSetSemantics {}, Loading packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/anc/ui/composable/SliceAndroidView.kt +10 −9 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.systemui.res.R fun SliceAndroidView( slice: Slice?, modifier: Modifier = Modifier, isEnabled: Boolean = true, onWidthChanged: ((Int) -> Unit)? = null, onClick: (() -> Unit)? = null, ) { Loading @@ -40,7 +41,6 @@ fun SliceAndroidView( factory = { context: Context -> ClickableSliceView( ContextThemeWrapper(context, R.style.Widget_SliceView_VolumePanel), onClick, ) .apply { mode = SliceView.MODE_LARGE Loading @@ -50,12 +50,14 @@ fun SliceAndroidView( if (onWidthChanged != null) { addOnLayoutChangeListener(OnWidthChangedLayoutListener(onWidthChanged)) } if (onClick != null) { setOnClickListener { onClick() } } } }, update = { sliceView: SliceView -> sliceView.slice = slice } update = { sliceView: ClickableSliceView -> sliceView.slice = slice sliceView.onClick = onClick sliceView.isEnabled = isEnabled sliceView.isClickable = isEnabled } ) } Loading Loading @@ -86,10 +88,9 @@ class OnWidthChangedLayoutListener(private val widthChanged: (Int) -> Unit) : * first. */ @SuppressLint("ViewConstructor") // only used in this class private class ClickableSliceView( context: Context, private val onClick: (() -> Unit)?, ) : SliceView(context) { private class ClickableSliceView(context: Context) : SliceView(context) { var onClick: (() -> Unit)? = null init { if (onClick != null) { Loading packages/SystemUI/src/com/android/systemui/volume/panel/component/anc/ui/viewmodel/AncViewModel.kt +27 −0 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package com.android.systemui.volume.panel.component.anc.ui.viewmodel import android.content.Intent import androidx.slice.Slice import androidx.slice.SliceItem import com.android.systemui.volume.panel.component.anc.domain.AncAvailabilityCriteria import com.android.systemui.volume.panel.component.anc.domain.interactor.AncSliceInteractor import com.android.systemui.volume.panel.component.anc.domain.model.AncSlices Loading Loading @@ -59,6 +61,31 @@ constructor( .map { it.buttonSlice } .stateIn(coroutineScope, SharingStarted.Eagerly, null) fun isClickable(slice: Slice?): Boolean { slice ?: return false val slices = ArrayDeque<SliceItem>() slices.addAll(slice.items) while (slices.isNotEmpty()) { val item: SliceItem = slices.removeFirst() when (item.format) { android.app.slice.SliceItem.FORMAT_ACTION -> { val itemActionIntent: Intent? = item.action?.intent if (itemActionIntent?.hasExtra(EXTRA_ANC_ENABLED) == true) { return itemActionIntent.getBooleanExtra(EXTRA_ANC_ENABLED, true) } } android.app.slice.SliceItem.FORMAT_SLICE -> { item.slice?.items?.let(slices::addAll) } } } return true } private companion object { const val EXTRA_ANC_ENABLED = "EXTRA_ANC_ENABLED" } /** Call this to update [popupSlice] width in a reaction to container size change. */ fun onPopupSliceWidthChanged(width: Int) { interactor.onPopupSliceWidthChanged(width) Loading Loading
packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/anc/ui/composable/AncButtonComponent.kt +9 −1 Original line number Diff line number Diff line Loading @@ -54,6 +54,13 @@ constructor( override fun VolumePanelComposeScope.Content(modifier: Modifier) { val slice by viewModel.buttonSlice.collectAsState() val label = stringResource(R.string.volume_panel_noise_control_title) val isClickable = viewModel.isClickable(slice) val onClick = if (isClickable) { { ancPopup.show(null) } } else { null } Column( modifier = modifier, verticalArrangement = Arrangement.spacedBy(12.dp), Loading @@ -69,8 +76,9 @@ constructor( } .clip(RoundedCornerShape(28.dp)), slice = slice, isEnabled = onClick != null, onWidthChanged = viewModel::onButtonSliceWidthChanged, onClick = { ancPopup.show(null) } onClick = onClick, ) Text( modifier = Modifier.clearAndSetSemantics {}, Loading
packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/anc/ui/composable/SliceAndroidView.kt +10 −9 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.systemui.res.R fun SliceAndroidView( slice: Slice?, modifier: Modifier = Modifier, isEnabled: Boolean = true, onWidthChanged: ((Int) -> Unit)? = null, onClick: (() -> Unit)? = null, ) { Loading @@ -40,7 +41,6 @@ fun SliceAndroidView( factory = { context: Context -> ClickableSliceView( ContextThemeWrapper(context, R.style.Widget_SliceView_VolumePanel), onClick, ) .apply { mode = SliceView.MODE_LARGE Loading @@ -50,12 +50,14 @@ fun SliceAndroidView( if (onWidthChanged != null) { addOnLayoutChangeListener(OnWidthChangedLayoutListener(onWidthChanged)) } if (onClick != null) { setOnClickListener { onClick() } } } }, update = { sliceView: SliceView -> sliceView.slice = slice } update = { sliceView: ClickableSliceView -> sliceView.slice = slice sliceView.onClick = onClick sliceView.isEnabled = isEnabled sliceView.isClickable = isEnabled } ) } Loading Loading @@ -86,10 +88,9 @@ class OnWidthChangedLayoutListener(private val widthChanged: (Int) -> Unit) : * first. */ @SuppressLint("ViewConstructor") // only used in this class private class ClickableSliceView( context: Context, private val onClick: (() -> Unit)?, ) : SliceView(context) { private class ClickableSliceView(context: Context) : SliceView(context) { var onClick: (() -> Unit)? = null init { if (onClick != null) { Loading
packages/SystemUI/src/com/android/systemui/volume/panel/component/anc/ui/viewmodel/AncViewModel.kt +27 −0 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package com.android.systemui.volume.panel.component.anc.ui.viewmodel import android.content.Intent import androidx.slice.Slice import androidx.slice.SliceItem import com.android.systemui.volume.panel.component.anc.domain.AncAvailabilityCriteria import com.android.systemui.volume.panel.component.anc.domain.interactor.AncSliceInteractor import com.android.systemui.volume.panel.component.anc.domain.model.AncSlices Loading Loading @@ -59,6 +61,31 @@ constructor( .map { it.buttonSlice } .stateIn(coroutineScope, SharingStarted.Eagerly, null) fun isClickable(slice: Slice?): Boolean { slice ?: return false val slices = ArrayDeque<SliceItem>() slices.addAll(slice.items) while (slices.isNotEmpty()) { val item: SliceItem = slices.removeFirst() when (item.format) { android.app.slice.SliceItem.FORMAT_ACTION -> { val itemActionIntent: Intent? = item.action?.intent if (itemActionIntent?.hasExtra(EXTRA_ANC_ENABLED) == true) { return itemActionIntent.getBooleanExtra(EXTRA_ANC_ENABLED, true) } } android.app.slice.SliceItem.FORMAT_SLICE -> { item.slice?.items?.let(slices::addAll) } } } return true } private companion object { const val EXTRA_ANC_ENABLED = "EXTRA_ANC_ENABLED" } /** Call this to update [popupSlice] width in a reaction to container size change. */ fun onPopupSliceWidthChanged(width: Int) { interactor.onPopupSliceWidthChanged(width) Loading