Skip to content
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

Merged
merged 11 commits into from
Nov 1, 2023

Conversation

Irineu333
Copy link
Member

@Irineu333 Irineu333 commented Sep 30, 2023

Closes #12

Improvements

Implement haptic feedback, according to the issue #12

  • click vibration for clickable view
  • short vibration for non-clickable

@Irineu333 Irineu333 added the feature New feature or request label Sep 30, 2023
@Irineu333 Irineu333 added this to the MVP milestone Sep 30, 2023
@Irineu333 Irineu333 requested a review from PatrykMis September 30, 2023 03:11
@Irineu333 Irineu333 self-assigned this Sep 30, 2023
@Irineu333 Irineu333 force-pushed the feature/ISSUE12-implement-haptic-feedback branch 3 times, most recently from 282c0dc to 8960133 Compare September 30, 2023 23:36
@Irineu333
Copy link
Member Author

Irineu333 commented Sep 30, 2023

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.

@Irineu333 Irineu333 force-pushed the feature/ISSUE12-implement-haptic-feedback branch 3 times, most recently from ad4d37c to 9a8e169 Compare October 1, 2023 00:21
@Irineu333 Irineu333 force-pushed the feature/ISSUE12-implement-haptic-feedback branch from 9a8e169 to cf9be18 Compare October 1, 2023 00:22
@Irineu333 Irineu333 linked an issue Oct 2, 2023 that may be closed by this pull request
@PatrykMis
Copy link
Collaborator

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.

Copy link
Collaborator

@PatrykMis PatrykMis left a 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+.

@PatrykMis
Copy link
Collaborator

PatrykMis commented Oct 7, 2023

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
@Irineu333
Copy link
Member Author

@PatrykMis Did it work properly? Is distinguishing between the vibrations still an issue? We need to map this out.

@Irineu333 Irineu333 merged commit 385baf2 into develop Nov 1, 2023
1 check passed
@Irineu333 Irineu333 deleted the feature/ISSUE12-implement-haptic-feedback branch November 1, 2023 04:38
@PatrykMis
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement haptic feedback
2 participants