Skip to content

Migrate Create custom haptic effects snippets - #1093

Draft
hamen wants to merge 4 commits into
android:mainfrom
hamen:morgillo/custom-haptic-effects
Draft

hamen wants to merge 4 commits into
android:mainfrom
hamen:morgillo/custom-haptic-effects

Conversation

@hamen

@hamen hamen commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Code snippets are for:

List of modifications:

  • Custom haptic effects page: Added 16 Kotlin snippets for custom vibration patterns, vibration compositions (Resist, Expand, Wobble, Bounce), and waveform envelopes (BasicEnvelopeBuilder, WaveformEnvelopeBuilder, BouncingSpringAnimation, RocketLaunchAnimation, LavaBeats).
  • Custom haptic effects page: Repaired compilation and syntax issues (Java-in-Kotlin void/type declarations in repeating pattern, variable name and spread operator in arePrimitivesSupported, missing closing brace in ExpandScreen clickable lambda, rampUpDurationMs identifier and Long type compatibility in RocketLaunchAnimation).
  • Custom haptic effects page: Added background color resource in views/src/main/res/values/colors.xml and enabled Compose support in views/build.gradle.kts.
  • Declared android.permission.VIBRATE in the views manifest, which every vibrate() call needs.

Deviations from the page:

  • BouncingSpringAnimation calls DrawSpring(springX, springY). The page calls DrawSpring(mutableStateOf(springX), mutableStateOf(springY)), which creates two state objects on every recomposition. The page text needs the same change.
  • RocketLaunchAnimation reads the background with colorResource(R.color.background). The page uses Color(context.getColor(R.color.background)), which is not configuration-aware and can return a stale value after a configuration change. The LocalContext.current lookup goes with it.
  • arePrimitivesSupported() takes a vararg, so the Kotlin snippet passes *primitives. The page omits the spread operator, and that version does not compile.

Snippets not migrated:

  • 11 duplicate Java snippets, since the page is served Kotlin-first.

hamen and others added 4 commits September 14, 2026 15:23
Every Vibrator.vibrate() call in CustomHapticEffects.kt failed lint with
MissingPermission, because the views manifest declared no permission at
all. That was 17 of the 21 lint errors on this branch.
The page creates two state objects on every recomposition, in
DrawSpring(mutableStateOf(springX), mutableStateOf(springY)). Pass the
values, and let the placeholder take Dp. That is what UnrememberedMutableState
exists to catch.

The page reads a colour with context.getColor() through LocalContext, which
is not configuration-aware. Use colorResource() instead, which drops the
LocalContext lookup with it.

arePrimitivesSupported() takes a vararg, so the Kotlin snippet needs the
spread operator, and lint cannot follow it to the constants. The page omits
the spread, and that version does not compile. Suppress WrongConstant on the
function, outside the region tag, so the page snippet is unchanged.
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