Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +23 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.focusable import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.gestures.detectHorizontalDragGestures import androidx.compose.foundation.gestures.snapping.SnapPosition Loading Loading @@ -72,6 +73,7 @@ import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyGridLayoutInfo import androidx.compose.foundation.lazy.grid.LazyGridScope import androidx.compose.foundation.lazy.grid.LazyGridState import androidx.compose.foundation.lazy.grid.LazyHorizontalGrid Loading Loading @@ -1017,6 +1019,9 @@ private fun BoxScope.CommunalHubLazyGrid( } else { null } val isVisible by remember { derivedStateOf { gridState.layoutInfo.isIndexVisible(index) } } if (viewModel.isEditMode && dragDropState != null) { val isItemDragging = dragDropState.draggingItemKey == item.key val outlineAlpha by Loading Loading @@ -1084,6 +1089,7 @@ private fun BoxScope.CommunalHubLazyGrid( interactionHandler = interactionHandler, widgetSection = widgetSection, resizeableItemFrameViewModel = resizeableItemFrameViewModel, isVisible = isVisible, ) } } Loading @@ -1108,6 +1114,7 @@ private fun BoxScope.CommunalHubLazyGrid( widgetSection = widgetSection, resizeableItemFrameViewModel = resizeableItemFrameViewModel, contentScope = contentScope, isVisible = isVisible, ) } } Loading Loading @@ -1367,6 +1374,7 @@ private fun CommunalContent( widgetSection: CommunalAppWidgetSection, resizeableItemFrameViewModel: ResizeableItemFrameViewModel, contentScope: ContentScope? = null, isVisible: Boolean, ) { when (model) { is CommunalContentModel.WidgetContent.Widget -> Loading @@ -1381,6 +1389,7 @@ private fun CommunalContent( contentListState, widgetSection, resizeableItemFrameViewModel, isVisible, ) is CommunalContentModel.WidgetPlaceholder -> HighlightedItem(modifier) is CommunalContentModel.WidgetContent.DisabledWidget -> Loading Loading @@ -1516,6 +1525,7 @@ private fun WidgetContent( contentListState: ContentListState, widgetSection: CommunalAppWidgetSection, resizeableItemFrameViewModel: ResizeableItemFrameViewModel, isVisible: Boolean, ) { val coroutineScope = rememberCoroutineScope() val context = LocalContext.current Loading Loading @@ -1653,6 +1663,7 @@ private fun WidgetContent( model = model, size = size, modifier = Modifier.fillMaxSize().allowGestures(allowed = !viewModel.isEditMode), isVisible = isVisible, ) } if ( Loading Loading @@ -2269,6 +2280,18 @@ private fun calculatePercentVisible(state: LazyGridState, index: Int): Float { } } private fun LazyGridLayoutInfo.isIndexVisible(index: Int) = visibleItemsInfo .firstOrNull { it.index == index } ?.let { item -> val (start, end) = when (orientation) { Orientation.Vertical -> item.offset.y to item.offset.y + item.size.height Orientation.Horizontal -> item.offset.x to item.offset.x + item.size.width } start >= viewportStartOffset && end <= viewportEndOffset } ?: false private object Colors { val DisabledColorFilter by lazy { disabledColorMatrix() } Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/GlanceableHubWidgetManagerServiceTest.kt +3 −0 Original line number Diff line number Diff line Loading @@ -166,6 +166,9 @@ class GlanceableHubWidgetManagerServiceTest : SysuiTestCase() { appWidgetHostListener.onViewDataChanged(1) verify(listener).onViewDataChanged(1) appWidgetHostListener.collectWidgetEvent() verify(listener).collectWidgetEvent() } @Test Loading packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/sections/CommunalAppWidgetSection.kt +2 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ constructor( openWidgetEditor: () -> Unit, model: CommunalContentModel.WidgetContent.Widget, size: SizeF, isVisible: Boolean, modifier: Modifier = Modifier, ) { val viewModel = rememberViewModel("$TAG#viewModel") { viewModelFactory.create() } Loading Loading @@ -112,6 +113,7 @@ constructor( view.setTag(LISTENER_TAG, model.appWidgetId) } viewModel.updateSize(size, view) if (isVisible) view.startVisibilityTracking() else view.stopVisibilityTracking() }, modifier = modifier, // For reusing composition in lazy lists. Loading packages/SystemUI/src/com/android/systemui/communal/widgets/AppWidgetHostListenerDelegate.kt +9 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetEvent import android.appwidget.AppWidgetHost.AppWidgetHostListener import android.appwidget.AppWidgetProviderInfo import android.widget.RemoteViews Loading Loading @@ -55,4 +56,12 @@ constructor( override fun onViewDataChanged(viewId: Int) { mainScope.launchTraced("$tag#onViewDataChanged") { listener.onViewDataChanged(viewId) } } override fun collectWidgetEvent(): AppWidgetEvent? { if (!android.appwidget.flags.Flags.engagementMetrics()) { return null } // collectWidgetEvent does not need to run on the main thread. return listener.collectWidgetEvent() } } packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHost.kt +1 −1 Original line number Diff line number Diff line Loading @@ -98,8 +98,8 @@ class CommunalAppWidgetHost( } override fun stopListening() { super.stopListening() backgroundScope.launch { super.stopListening() synchronized(observers) { observers.forEach { observer -> observer.onHostStopListening() } } Loading Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +23 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.focusable import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.gestures.detectHorizontalDragGestures import androidx.compose.foundation.gestures.snapping.SnapPosition Loading Loading @@ -72,6 +73,7 @@ import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyGridLayoutInfo import androidx.compose.foundation.lazy.grid.LazyGridScope import androidx.compose.foundation.lazy.grid.LazyGridState import androidx.compose.foundation.lazy.grid.LazyHorizontalGrid Loading Loading @@ -1017,6 +1019,9 @@ private fun BoxScope.CommunalHubLazyGrid( } else { null } val isVisible by remember { derivedStateOf { gridState.layoutInfo.isIndexVisible(index) } } if (viewModel.isEditMode && dragDropState != null) { val isItemDragging = dragDropState.draggingItemKey == item.key val outlineAlpha by Loading Loading @@ -1084,6 +1089,7 @@ private fun BoxScope.CommunalHubLazyGrid( interactionHandler = interactionHandler, widgetSection = widgetSection, resizeableItemFrameViewModel = resizeableItemFrameViewModel, isVisible = isVisible, ) } } Loading @@ -1108,6 +1114,7 @@ private fun BoxScope.CommunalHubLazyGrid( widgetSection = widgetSection, resizeableItemFrameViewModel = resizeableItemFrameViewModel, contentScope = contentScope, isVisible = isVisible, ) } } Loading Loading @@ -1367,6 +1374,7 @@ private fun CommunalContent( widgetSection: CommunalAppWidgetSection, resizeableItemFrameViewModel: ResizeableItemFrameViewModel, contentScope: ContentScope? = null, isVisible: Boolean, ) { when (model) { is CommunalContentModel.WidgetContent.Widget -> Loading @@ -1381,6 +1389,7 @@ private fun CommunalContent( contentListState, widgetSection, resizeableItemFrameViewModel, isVisible, ) is CommunalContentModel.WidgetPlaceholder -> HighlightedItem(modifier) is CommunalContentModel.WidgetContent.DisabledWidget -> Loading Loading @@ -1516,6 +1525,7 @@ private fun WidgetContent( contentListState: ContentListState, widgetSection: CommunalAppWidgetSection, resizeableItemFrameViewModel: ResizeableItemFrameViewModel, isVisible: Boolean, ) { val coroutineScope = rememberCoroutineScope() val context = LocalContext.current Loading Loading @@ -1653,6 +1663,7 @@ private fun WidgetContent( model = model, size = size, modifier = Modifier.fillMaxSize().allowGestures(allowed = !viewModel.isEditMode), isVisible = isVisible, ) } if ( Loading Loading @@ -2269,6 +2280,18 @@ private fun calculatePercentVisible(state: LazyGridState, index: Int): Float { } } private fun LazyGridLayoutInfo.isIndexVisible(index: Int) = visibleItemsInfo .firstOrNull { it.index == index } ?.let { item -> val (start, end) = when (orientation) { Orientation.Vertical -> item.offset.y to item.offset.y + item.size.height Orientation.Horizontal -> item.offset.x to item.offset.x + item.size.width } start >= viewportStartOffset && end <= viewportEndOffset } ?: false private object Colors { val DisabledColorFilter by lazy { disabledColorMatrix() } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/GlanceableHubWidgetManagerServiceTest.kt +3 −0 Original line number Diff line number Diff line Loading @@ -166,6 +166,9 @@ class GlanceableHubWidgetManagerServiceTest : SysuiTestCase() { appWidgetHostListener.onViewDataChanged(1) verify(listener).onViewDataChanged(1) appWidgetHostListener.collectWidgetEvent() verify(listener).collectWidgetEvent() } @Test Loading
packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/sections/CommunalAppWidgetSection.kt +2 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ constructor( openWidgetEditor: () -> Unit, model: CommunalContentModel.WidgetContent.Widget, size: SizeF, isVisible: Boolean, modifier: Modifier = Modifier, ) { val viewModel = rememberViewModel("$TAG#viewModel") { viewModelFactory.create() } Loading Loading @@ -112,6 +113,7 @@ constructor( view.setTag(LISTENER_TAG, model.appWidgetId) } viewModel.updateSize(size, view) if (isVisible) view.startVisibilityTracking() else view.stopVisibilityTracking() }, modifier = modifier, // For reusing composition in lazy lists. Loading
packages/SystemUI/src/com/android/systemui/communal/widgets/AppWidgetHostListenerDelegate.kt +9 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetEvent import android.appwidget.AppWidgetHost.AppWidgetHostListener import android.appwidget.AppWidgetProviderInfo import android.widget.RemoteViews Loading Loading @@ -55,4 +56,12 @@ constructor( override fun onViewDataChanged(viewId: Int) { mainScope.launchTraced("$tag#onViewDataChanged") { listener.onViewDataChanged(viewId) } } override fun collectWidgetEvent(): AppWidgetEvent? { if (!android.appwidget.flags.Flags.engagementMetrics()) { return null } // collectWidgetEvent does not need to run on the main thread. return listener.collectWidgetEvent() } }
packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHost.kt +1 −1 Original line number Diff line number Diff line Loading @@ -98,8 +98,8 @@ class CommunalAppWidgetHost( } override fun stopListening() { super.stopListening() backgroundScope.launch { super.stopListening() synchronized(observers) { observers.forEach { observer -> observer.onHostStopListening() } } Loading