Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +10 −9 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.util.SizeF import android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO import android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS import android.widget.FrameLayout import androidx.annotation.VisibleForTesting import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibilityScope import androidx.compose.animation.ExperimentalAnimationApi Loading Loading @@ -162,7 +163,6 @@ fun CommunalHub( var removeButtonCoordinates: LayoutCoordinates? by remember { mutableStateOf(null) } var toolbarSize: IntSize? by remember { mutableStateOf(null) } var gridCoordinates: LayoutCoordinates? by remember { mutableStateOf(null) } var isDraggingToRemove by remember { mutableStateOf(false) } val gridState = rememberLazyGridState() val contentListState = rememberContentListState(widgetConfigurator, communalContent, viewModel) val reorderingWidgets by viewModel.reorderingWidgets.collectAsStateWithLifecycle() Loading Loading @@ -250,12 +250,11 @@ fun CommunalHub( contentOffset = contentOffset, setGridCoordinates = { gridCoordinates = it }, updateDragPositionForRemove = { offset -> isDraggingToRemove = isPointerWithinCoordinates( isPointerWithinEnabledRemoveButton( removeEnabled = removeButtonEnabled, offset = gridCoordinates?.let { it.positionInWindow() + offset }, containerToCheck = removeButtonCoordinates ) isDraggingToRemove }, gridState = gridState, contentListState = contentListState, Loading Loading @@ -1200,11 +1199,13 @@ private fun beforeContentPadding(paddingValues: PaddingValues): ContentPaddingIn * Check whether the pointer position that the item is being dragged at is within the coordinates of * the remove button in the toolbar. Returns true if the item is removable. */ private fun isPointerWithinCoordinates( @VisibleForTesting fun isPointerWithinEnabledRemoveButton( removeEnabled: Boolean, offset: Offset?, containerToCheck: LayoutCoordinates? ): Boolean { if (offset == null || containerToCheck == null) { if (!removeEnabled || offset == null || containerToCheck == null) { return false } val container = containerToCheck.boundsInWindow() Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/compose/CommunalHubUtilsTest.kt 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.communal.ui.compose import android.testing.TestableLooper import androidx.compose.ui.geometry.Offset import androidx.compose.ui.layout.LayoutCoordinates import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock @RunWith(AndroidJUnit4::class) @TestableLooper.RunWithLooper(setAsMainLooper = true) @SmallTest class CommunalHubUtilsTest : SysuiTestCase() { @Test fun isPointerWithinEnabledRemoveButton_ensureDisabledStatePriority() { assertThat( isPointerWithinEnabledRemoveButton(false, mock<Offset>(), mock<LayoutCoordinates>()) ) .isFalse() } } Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +10 −9 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.util.SizeF import android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO import android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS import android.widget.FrameLayout import androidx.annotation.VisibleForTesting import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibilityScope import androidx.compose.animation.ExperimentalAnimationApi Loading Loading @@ -162,7 +163,6 @@ fun CommunalHub( var removeButtonCoordinates: LayoutCoordinates? by remember { mutableStateOf(null) } var toolbarSize: IntSize? by remember { mutableStateOf(null) } var gridCoordinates: LayoutCoordinates? by remember { mutableStateOf(null) } var isDraggingToRemove by remember { mutableStateOf(false) } val gridState = rememberLazyGridState() val contentListState = rememberContentListState(widgetConfigurator, communalContent, viewModel) val reorderingWidgets by viewModel.reorderingWidgets.collectAsStateWithLifecycle() Loading Loading @@ -250,12 +250,11 @@ fun CommunalHub( contentOffset = contentOffset, setGridCoordinates = { gridCoordinates = it }, updateDragPositionForRemove = { offset -> isDraggingToRemove = isPointerWithinCoordinates( isPointerWithinEnabledRemoveButton( removeEnabled = removeButtonEnabled, offset = gridCoordinates?.let { it.positionInWindow() + offset }, containerToCheck = removeButtonCoordinates ) isDraggingToRemove }, gridState = gridState, contentListState = contentListState, Loading Loading @@ -1200,11 +1199,13 @@ private fun beforeContentPadding(paddingValues: PaddingValues): ContentPaddingIn * Check whether the pointer position that the item is being dragged at is within the coordinates of * the remove button in the toolbar. Returns true if the item is removable. */ private fun isPointerWithinCoordinates( @VisibleForTesting fun isPointerWithinEnabledRemoveButton( removeEnabled: Boolean, offset: Offset?, containerToCheck: LayoutCoordinates? ): Boolean { if (offset == null || containerToCheck == null) { if (!removeEnabled || offset == null || containerToCheck == null) { return false } val container = containerToCheck.boundsInWindow() Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/compose/CommunalHubUtilsTest.kt 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.communal.ui.compose import android.testing.TestableLooper import androidx.compose.ui.geometry.Offset import androidx.compose.ui.layout.LayoutCoordinates import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock @RunWith(AndroidJUnit4::class) @TestableLooper.RunWithLooper(setAsMainLooper = true) @SmallTest class CommunalHubUtilsTest : SysuiTestCase() { @Test fun isPointerWithinEnabledRemoveButton_ensureDisabledStatePriority() { assertThat( isPointerWithinEnabledRemoveButton(false, mock<Offset>(), mock<LayoutCoordinates>()) ) .isFalse() } }