Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1706c6c authored by Matt Pietal's avatar Matt Pietal Committed by Automerger Merge Worker
Browse files

Merge "Controls UI - Haptics fixes" into rvc-dev am: a2d82aeb am: 5d3425d9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11687491

Change-Id: I98bb38861e7a77a0c4b4683552bc145f0a1932b8
parents 33dbe92a 5d3425d9
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -58,16 +58,14 @@ class ControlActionCoordinatorImpl @Inject constructor(

    override fun toggle(cvh: ControlViewHolder, templateId: String, isChecked: Boolean) {
        bouncerOrRun {
            val effect = if (!isChecked) Vibrations.toggleOnEffect else Vibrations.toggleOffEffect
            vibrate(effect)
            cvh.layout.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
            cvh.action(BooleanAction(templateId, !isChecked))
        }
    }

    override fun touch(cvh: ControlViewHolder, templateId: String, control: Control) {
        vibrate(Vibrations.toggleOnEffect)

        bouncerOrRun {
            cvh.layout.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
            if (cvh.usePanel()) {
                showDialog(cvh, control.getAppIntent().getIntent())
            } else {
+4 −2
Original line number Diff line number Diff line
@@ -231,9 +231,11 @@ class ToggleRangeBehavior : Behavior {

        rangeAnimator?.cancel()
        if (isDragging) {
            clipLayer.level = newLevel
            val isEdge = newLevel == MIN_LEVEL || newLevel == MAX_LEVEL
            if (clipLayer.level != newLevel) {
                cvh.controlActionCoordinator.drag(isEdge)
                clipLayer.level = newLevel
            }
        } else if (newLevel != clipLayer.level) {
            rangeAnimator = ValueAnimator.ofInt(cvh.clipLayer.level, newLevel).apply {
                addUpdateListener {
+0 −26
Original line number Diff line number Diff line
@@ -20,35 +20,9 @@ import android.os.VibrationEffect
import android.os.VibrationEffect.Composition.PRIMITIVE_TICK

object Vibrations {
    private const val TOGGLE_TICK_COUNT = 40

    val toggleOnEffect = initToggleOnEffect()
    val toggleOffEffect = initToggleOffEffect()
    val rangeEdgeEffect = initRangeEdgeEffect()
    val rangeMiddleEffect = initRangeMiddleEffect()

    private fun initToggleOnEffect(): VibrationEffect {
        val composition = VibrationEffect.startComposition()
        composition.addPrimitive(PRIMITIVE_TICK, 0.05f, 200)
        var i = 0
        while (i++ < TOGGLE_TICK_COUNT) {
            composition.addPrimitive(PRIMITIVE_TICK, 0.05f, 0)
        }
        composition.addPrimitive(PRIMITIVE_TICK, 0.5f, 100)
        return composition.compose()
    }

    private fun initToggleOffEffect(): VibrationEffect {
        val composition = VibrationEffect.startComposition()
        composition.addPrimitive(PRIMITIVE_TICK, 0.5f, 0)
        composition.addPrimitive(PRIMITIVE_TICK, 0.05f, 100)
        var i = 0
        while (i++ < TOGGLE_TICK_COUNT) {
            composition.addPrimitive(PRIMITIVE_TICK, 0.05f, 0)
        }
        return composition.compose()
    }

    private fun initRangeEdgeEffect(): VibrationEffect {
        val composition = VibrationEffect.startComposition()
        composition.addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 0.5f)