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

Commit affa2060 authored by Andreas Agvard's avatar Andreas Agvard Committed by Android (Google) Code Review
Browse files

Merge "Added utility function to VibratorWrapper for generating Assist hapic" into udc-qpr-dev

parents 6e1e11bb edd9c96e
Loading
Loading
Loading
Loading
+34 −7
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.launcher3.util;

import static android.os.VibrationEffect.createPredefined;
import static android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED;

import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;

@@ -68,6 +69,9 @@ public class VibratorWrapper {
    @Nullable
    private final VibrationEffect mBumpEffect;

    @Nullable
    private final VibrationEffect mAssistEffect;

    private long mLastDragTime;
    private final int mThresholdUntilNextDragCallMillis;

@@ -125,6 +129,19 @@ public class VibratorWrapper {
            mBumpEffect = null;
            mThresholdUntilNextDragCallMillis = 0;
        }

        if (Utilities.ATLEAST_R && mVibrator.areAllPrimitivesSupported(
                VibrationEffect.Composition.PRIMITIVE_QUICK_RISE,
                VibrationEffect.Composition.PRIMITIVE_TICK)) {
            // quiet ramp, short pause, then sharp tick
            mAssistEffect = VibrationEffect.startComposition()
                    .addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, 0.25f)
                    .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 1f, 50)
                    .compose();
        } else {
            // fallback for devices without composition support
            mAssistEffect = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK);
        }
    }

    /**
@@ -166,6 +183,15 @@ public class VibratorWrapper {
        }
    }

    /**
     * The assist haptic is used to be called when an assistant is invoked
     */
    public void vibrateForAssist() {
        if (mAssistEffect != null) {
            vibrate(mAssistEffect);
        }
    }

    /**
     * This should be used to cancel a haptic in case where the haptic shouldn't be vibrating. For
     * example, when no animation is happening but a vibrator happens to be vibrating still. Need
@@ -176,6 +202,7 @@ public class VibratorWrapper {
        // reset dragTexture timestamp to be able to play dragTexture again whenever cancelled
        mLastDragTime = 0;
    }

    private boolean isHapticFeedbackEnabled(ContentResolver resolver) {
        return Settings.System.getInt(resolver, HAPTIC_FEEDBACK_ENABLED, 0) == 1;
    }