-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement haptic feedback #59
Conversation
282c0dc
to
8960133
Compare
I implemented the predefined effects as @PatrykMis suggested, but they are for api 29 (android 10), which only represents 72% of the android user base, so with the help of Chat GPT I found the equivalent petterns to support smaller apis for a while longer. |
ad4d37c
to
9a8e169
Compare
9a8e169
to
cf9be18
Compare
This does not work (does not vibrate) for me at all, at the current stage. Android 13 (API 33). It worked before refactor, I will try to check what cause the problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're not final adjustments as specified vibrations may still almost be indistinguisheable on most devices; however they enable haptic feedback for Android 13+.
For me, the following works the best: fun vibrateEffectHeavyClick(vibrator: Vibrator) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
vibrator.vibrate(
VibrationEffect.createPredefined(
VibrationEffect.EFFECT_HEAVY_CLICK
),
VibrationAttributes.createForUsage(
VibrationAttributes.USAGE_ACCESSIBILITY
)
)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
vibrator.vibrate(
VibrationEffect.createPredefined(
VibrationEffect.EFFECT_HEAVY_CLICK
)
)
} else {
@Suppress("deprecation")
vibrator.vibrate(
LegacyVibrationEffect.HeavyClick.pattern,
REPEAT
)
}
}
fun vibrateEffectTick(vibrator: Vibrator) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
vibrator.vibrate(
VibrationEffect.createOneShot(
50, 100
),
VibrationAttributes.createForUsage(
VibrationAttributes.USAGE_ACCESSIBILITY
)
)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
vibrator.vibrate(
VibrationEffect.createOneShot(
50, 100
)
)
} else {
... Now the code should be adjusted for Android APIs <29 if you'd like support such unsupported devices. My all devices have Android 11+ so I can't test :( |
…-feedback' into feature/ISSUE12-implement-haptic-feedback # Conflicts: # app/src/main/AndroidManifest.xml # app/src/main/res/xml-v26/accessibility_service_config.xml # app/src/main/res/xml-v31/accessibility_service_config.xml # app/src/main/res/xml/accessibility_service_config.xml
@PatrykMis Did it work properly? Is distinguishing between the vibrations still an issue? We need to map this out. |
For me it's distinguishable enough (android 13 and 14). We could improve it slightly someday when we get user input, especially from those using Android <13. |
Closes #12
Improvements
Implement haptic feedback, according to the issue #12