Skip to content

Add Haptic PWLE samples #308

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ExocetResearch
Copy link

What?

Update User Interface - Haptics with latest PWLE API/Samples. (Spring/Rocket)

Why?

To demonstrate how to use the Basic, and Advanced PWLE Haptic APIs.

How?

Added a Spring, and Rocket example to the Haptics menu/navigation

Testing?

This has been tested, and been confirmed to be a good example of how to use the APIs. This is similar and to possibly be referenced in the PWLE Documentation.

Copy link

google-cla bot commented Jun 3, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @ExocetResearch, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request adds two new haptic examples, Spring and Rocket, to the existing Haptics demo. These examples demonstrate the use of PWLE (Piecewise Linear Envelope) haptic APIs. The Spring example simulates a bouncing spring with haptic feedback, while the Rocket example simulates a rocket launch with corresponding haptic effects. The changes include new composable functions for the Spring and Rocket examples, along with associated view models and routes. The compileSdk and targetSdk have also been updated to 36.

Highlights

  • New Haptic Examples: Adds Spring and Rocket examples to showcase PWLE haptic APIs.
  • UI Updates: Introduces new composable functions (SpringRoute, RocketRoute) and updates the UI to include these examples in the Haptics menu.
  • ViewModel Implementation: Implements SpringViewModel and RocketViewModel to manage the state and logic for the new haptic examples.
  • Build Configuration Update: Updates compileSdk and targetSdk to 36 in the haptics build.gradle.kts file.

Changelog

Click here to see the changelog
  • app/src/main/java/com/example/platform/app/SampleDemo.kt
    • Imports the new Spring and Rocket composables.
    • Adds Spring and Rocket demos to the SAMPLE_DEMOS list, including descriptions, documentation links, and tags.
  • samples/user-interface/haptics/build.gradle.kts
    • Updates compileSdk and targetSdk to 36.
  • samples/user-interface/haptics/src/main/java/com/example/platform/ui/haptics/Haptics.kt
    • Imports SpringRoute, SpringViewModel, RocketRoute, and RocketViewModel.
    • Adds Spring() and Rocket() composable functions to the Haptics screen.
  • samples/user-interface/haptics/src/main/java/com/example/platform/ui/haptics/rocket/RocketRoute.kt
    • Creates RocketRoute composable to handle the rocket launch animation and haptic feedback.
    • Implements playEnvelopeVibration function to generate haptic effects using PWLE APIs.
  • samples/user-interface/haptics/src/main/java/com/example/platform/ui/haptics/rocket/RocketViewModel.kt
    • Creates RocketViewModel to manage the state and logic for the Rocket example.
    • Includes checks for device support and provides a ViewModelProvider.Factory.
  • samples/user-interface/haptics/src/main/java/com/example/platform/ui/haptics/spring/SpringRoute.kt
    • Creates SpringRoute composable to handle the spring animation and haptic feedback.
    • Implements playEnvelopeVibration function to generate haptic effects using PWLE APIs.
  • samples/user-interface/haptics/src/main/java/com/example/platform/ui/haptics/spring/SpringViewModel.kt
    • Creates SpringViewModel to manage the state and logic for the Spring example.
    • Includes checks for device support and provides a ViewModelProvider.Factory.
  • samples/user-interface/haptics/src/main/res/values/strings.xml
    • Adds new string resources for Spring and Rocket examples, including titles and descriptions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A spring and a rocket,
Haptics take flight with code,
Touch the digital.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces two new haptic samples, "Spring" and "Rocket", to demonstrate Piecewise Linear Envelope (PWLE) APIs. The additions are valuable for showcasing these new haptic capabilities. The implementation of the animations and haptic feedback is generally well done.

I've identified a few areas for improvement, primarily concerning code clarity, robustness, and adherence to Android development best practices. These are detailed in the specific comments below. Addressing these points will enhance the quality and maintainability of the sample code.

No explicit style guide was provided, so feedback regarding style adheres to common Kotlin coding conventions (e.g., avoiding unnecessary semicolons, using kotlin.math) and Android development best practices (e.g., using string resources, null safety, accessibility considerations).

Summary of Findings

  • Unused Variable: RocketRoute.kt: The state variable rocketYStartPosition appears to be unused after assignment.
  • Accessibility: RocketRoute.kt: The contentDescription for the rocket image is static and should be dynamic for better accessibility.
  • Null Safety: RocketViewModel.kt & SpringViewModel.kt: Use of !! for getSystemService could be safer. SpringRoute.kt: Potential NPE when accessing vibrator.envelopeEffectInfo without a null check.
  • Hardcoded UI String: SpringRoute.kt: UI text "Tap to restart" is hardcoded instead of using a string resource.
  • Import Order (Low Severity - Not Commented): SampleDemo.kt: Import order for new haptic samples could be consistently alphabetical.
  • Generic Documentation Link (Low Severity - Not Commented): SampleDemo.kt: The documentation link for haptics is generic; a more specific link to PWLE documentation, if available, would be more helpful.
  • Missing Newline (Low Severity - Not Commented): Haptics.kt: File is missing a newline character at the end.
  • Kotlin Idioms (Low Severity - Not Commented): RocketRoute.kt: Unnecessary semicolons. SpringRoute.kt: Use kotlin.math.PI instead of java.lang.Math.PI.
  • Unused Imports (Low Severity - Not Commented): RocketRoute.kt and SpringRoute.kt contain unused import statements.
  • Leftover Debug Code (Low Severity - Not Commented): SpringRoute.kt: A commented-out Log.e statement should be removed.
  • Potentially Unused String Resource (Low Severity - Not Commented): strings.xml: The string spring_tap_to_drop might be unused in the current implementation.

Merge Readiness

This pull request adds excellent examples for the new PWLE haptic APIs. The core functionality is well-implemented. However, before merging, I recommend addressing the medium-severity issues identified in the review comments. These changes will improve the code's robustness, maintainability, and adherence to best practices. I am not authorized to approve pull requests, so please ensure further review and approval as per your team's process after these changes are considered.

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

Successfully merging this pull request may close these issues.

1 participant