From 7ba34c7a6cbcd8fe386bbe4b8cbb0d0f2df9ea25 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Mon, 8 Jul 2024 17:11:32 -0700 Subject: Move CommunalSwipeDetector. This changelist moves the class closer to the associated usage. Fixes: 351913024 Test: verified builds and run (simple refactor) Flag: EXEMPT refactor Change-Id: Ib1c18a195221ec45e8a37bf1827bc27daf150a1d --- .../communal/ui/compose/CommunalContainer.kt | 1 - .../animation/scene/CommunalSwipeDetector.kt | 56 ------------------- .../communal/ui/compose/CommunalSwipeDetector.kt | 62 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 57 deletions(-) delete mode 100644 packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/CommunalSwipeDetector.kt create mode 100644 packages/SystemUI/compose/scene/src/com/android/systemui/communal/ui/compose/CommunalSwipeDetector.kt diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt index d0466313cf81..43d51c37aa36 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt @@ -28,7 +28,6 @@ import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.android.compose.animation.scene.Back -import com.android.compose.animation.scene.CommunalSwipeDetector import com.android.compose.animation.scene.Edge import com.android.compose.animation.scene.ElementKey import com.android.compose.animation.scene.ElementMatcher diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/CommunalSwipeDetector.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/CommunalSwipeDetector.kt deleted file mode 100644 index 7be34cabfaf8..000000000000 --- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/CommunalSwipeDetector.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.compose.animation.scene - -import androidx.compose.foundation.gestures.Orientation -import androidx.compose.ui.input.pointer.PointerInputChange -import androidx.compose.ui.input.pointer.positionChange -import androidx.compose.ui.unit.Density -import androidx.compose.ui.unit.IntOffset -import androidx.compose.ui.unit.IntSize -import kotlin.math.abs - -private const val TRAVEL_RATIO_THRESHOLD = .5f - -/** - * {@link CommunalSwipeDetector} provides an implementation of {@link SwipeDetector} and {@link - * SwipeSourceDetector} to enable fullscreen swipe handling to transition to and from the glanceable - * hub. - */ -class CommunalSwipeDetector(private var lastDirection: SwipeSource? = null) : - SwipeSourceDetector, SwipeDetector { - override fun source( - layoutSize: IntSize, - position: IntOffset, - density: Density, - orientation: Orientation - ): SwipeSource? { - return lastDirection - } - - override fun detectSwipe(change: PointerInputChange): Boolean { - if (change.positionChange().x > 0) { - lastDirection = Edge.Left - } else { - lastDirection = Edge.Right - } - - // Determine whether the ratio of the distance traveled horizontally to the distance - // traveled vertically exceeds the threshold. - return abs(change.positionChange().x / change.positionChange().y) > TRAVEL_RATIO_THRESHOLD - } -} diff --git a/packages/SystemUI/compose/scene/src/com/android/systemui/communal/ui/compose/CommunalSwipeDetector.kt b/packages/SystemUI/compose/scene/src/com/android/systemui/communal/ui/compose/CommunalSwipeDetector.kt new file mode 100644 index 000000000000..3fda9b85a5c2 --- /dev/null +++ b/packages/SystemUI/compose/scene/src/com/android/systemui/communal/ui/compose/CommunalSwipeDetector.kt @@ -0,0 +1,62 @@ +/* + * 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 androidx.compose.foundation.gestures.Orientation +import androidx.compose.ui.input.pointer.PointerInputChange +import androidx.compose.ui.input.pointer.positionChange +import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.unit.IntSize +import com.android.compose.animation.scene.Edge +import com.android.compose.animation.scene.SwipeDetector +import com.android.compose.animation.scene.SwipeSource +import com.android.compose.animation.scene.SwipeSourceDetector +import kotlin.math.abs + +/** + * {@link CommunalSwipeDetector} provides an implementation of {@link SwipeDetector} and {@link + * SwipeSourceDetector} to enable fullscreen swipe handling to transition to and from the glanceable + * hub. + */ +class CommunalSwipeDetector(private var lastDirection: SwipeSource? = null) : + SwipeSourceDetector, SwipeDetector { + companion object { + private const val TRAVEL_RATIO_THRESHOLD = .5f + } + + override fun source( + layoutSize: IntSize, + position: IntOffset, + density: Density, + orientation: Orientation + ): SwipeSource? { + return lastDirection + } + + override fun detectSwipe(change: PointerInputChange): Boolean { + if (change.positionChange().x > 0) { + lastDirection = Edge.Left + } else { + lastDirection = Edge.Right + } + + // Determine whether the ratio of the distance traveled horizontally to the distance + // traveled vertically exceeds the threshold. + return abs(change.positionChange().x / change.positionChange().y) > TRAVEL_RATIO_THRESHOLD + } +} -- cgit v1.2.3-59-g8ed1b