Skip to content

Commit

Permalink
Adding device specific haptic constants for Samsung devices. (google#…
Browse files Browse the repository at this point in the history
…2035)

* Adding device specific constants for Samsung devices.

These constants should bring better consistency with views rotary experience
  • Loading branch information
Kpeved authored Feb 16, 2024
1 parent 059df3b commit 91b797b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,8 @@ public fun rememberDefaultRotaryHapticFeedback(): RotaryHapticFeedback =
LocalView.current.let { view -> remember { findDeviceSpecificHapticFeedback(view) } }

internal fun findDeviceSpecificHapticFeedback(view: View): RotaryHapticFeedback =
if (isGalaxyWatchClassic()) {
GalaxyWatchClassicHapticFeedback(view)
} else if (isGalaxyWatch()) {
DefaultRotaryHapticFeedback(view)
if (isGalaxyWatchClassic() || isGalaxyWatch()) {
GalaxyWatchHapticFeedback(view)
} else if (isWear3point5(view.context)) {
Wear3point5RotaryHapticFeedback(view)
} else if (isWear4AtLeast()) {
Expand Down Expand Up @@ -372,26 +370,26 @@ private class Wear4AtLeastRotaryHapticFeedback(private val view: View) : RotaryH
}

/**
* Implementation of [RotaryHapticFeedback] for Galaxy Watch 4 and 6 Classic
* Implementation of [RotaryHapticFeedback] for Galaxy Watches
*/
@ExperimentalHorologistApi
private class GalaxyWatchClassicHapticFeedback(private val view: View) : RotaryHapticFeedback {
private class GalaxyWatchHapticFeedback(private val view: View) : RotaryHapticFeedback {

@ExperimentalHorologistApi
override fun performHapticFeedback(
type: RotaryHapticsType,
) {
when (type) {
RotaryHapticsType.ScrollItemFocus -> {
// No haptic for scroll snap ( we have physical bezel)
view.performHapticFeedback(102)
}

RotaryHapticsType.ScrollTick -> {
// No haptic for scroll tick ( we have physical bezel)
view.performHapticFeedback(102)
}

RotaryHapticsType.ScrollLimit -> {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
view.performHapticFeedback(50107)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class HapticsTest {

val hapticFeedback = getHapticFeedback()

assertThat(hapticFeedback.javaClass.simpleName).isEqualTo("GalaxyWatchClassicHapticFeedback")
assertThat(hapticFeedback.javaClass.simpleName).isEqualTo("GalaxyWatchHapticFeedback")
}

@Test
Expand All @@ -128,7 +128,7 @@ class HapticsTest {

val hapticFeedback = getHapticFeedback()

assertThat(hapticFeedback.javaClass.simpleName).isEqualTo("DefaultRotaryHapticFeedback")
assertThat(hapticFeedback.javaClass.simpleName).isEqualTo("GalaxyWatchHapticFeedback")
}

private fun getHapticFeedback(): RotaryHapticFeedback {
Expand Down

0 comments on commit 91b797b

Please sign in to comment.