1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.permissioncontroller.permission.ui.wear.elements.rotaryinput 18 19 import androidx.compose.ui.input.pointer.util.VelocityTracker1D 20 21 // This file is a copy of RotaryVelocityTracker.kt from Horologist (go/horologist), 22 // remove it once Wear Compose 1.4 is landed (b/325560444). 23 24 /** A wrapper around VelocityTracker1D to provide support for rotary input. */ 25 class RotaryVelocityTracker { 26 private var velocityTracker: VelocityTracker1D = VelocityTracker1D(true) 27 28 /** Retrieve the last computed velocity. */ 29 val velocity: Float 30 get() = velocityTracker.calculateVelocity() 31 32 /** Start tracking motion. */ startnull33 fun start(currentTime: Long) { 34 velocityTracker.resetTracking() 35 velocityTracker.addDataPoint(currentTime, 0f) 36 } 37 38 /** Continue tracking motion as the input rotates. */ movenull39 fun move(currentTime: Long, delta: Float) { 40 velocityTracker.addDataPoint(currentTime, delta) 41 } 42 43 /** Stop tracking motion. */ endnull44 fun end() { 45 velocityTracker.resetTracking() 46 } 47 } 48