You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement a convenience composable called rememberShakeDetectionState that will internally use rememberAccelerometerSensorState to get current values from the sensor and based on those values calculate whether the device was shaken or not.
rememberShakeDetectionState will return a @Stable class called ShakeDetectionState that exposes a State<Int> called shakeCount that refers to the number of times a valid shake has been triggered. Also expose a callback named onShakeSuccess or onHit using which a user could trigger an action.
This function also takes parameters like hitCount: Int and @FloatRange(from = 0.0, to 1.0) sensitivity: Float.
Here,
hitCount refers to the number of times the device has to be shaken before shakeCount is considered to be increased (it should default to 2 meaning the user has to shake his device 2 times before the shakeCount increases by 1)
and
sensitivity refers to the force by which the user has to shake the device for it to be considered a hit and the hitCount to increase (it will be a float value between 0f and 1f and the ShakeDetectionState class will expose a companion object that contains some default constant values for sensitivity such as ShakeDetectionState.SENSITIVITY_LOW, ShakeDetectionState.SENSITIVITY_MEDIUM, ShakeDetectionState.SENSITIVITY_HIGH).
Implement a convenience composable called
rememberShakeDetectionState
that will internally userememberAccelerometerSensorState
to get current values from the sensor and based on those values calculate whether the device was shaken or not.rememberShakeDetectionState
will return a@Stable
class calledShakeDetectionState
that exposes aState<Int>
calledshakeCount
that refers to the number of times a valid shake has been triggered. Also expose a callback namedonShakeSuccess
oronHit
using which a user could trigger an action.This function also takes parameters like
hitCount: Int
and@FloatRange(from = 0.0, to 1.0) sensitivity: Float
.Here,
hitCount
refers to the number of times the device has to be shaken beforeshakeCount
is considered to be increased (it should default to2
meaning the user has to shake his device 2 times before theshakeCount
increases by 1)and
sensitivity
refers to the force by which the user has to shake the device for it to be considered ahit
and thehitCount
to increase (it will be a float value between 0f and 1f and theShakeDetectionState
class will expose a companion object that contains some default constant values for sensitivity such asShakeDetectionState.SENSITIVITY_LOW
,ShakeDetectionState.SENSITIVITY_MEDIUM
,ShakeDetectionState.SENSITIVITY_HIGH
).Shake Detection Formula ref: https://stackoverflow.com/a/49282110
The text was updated successfully, but these errors were encountered: