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

Commit be9b8400 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update notification PWLE patterns for default and fallback" into sc-v2-dev

parents d5296edb 0ce82d08
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ public final class VibratorHelper {

    private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};
    private static final int VIBRATE_PATTERN_MAXLEN = 8 * 2 + 1; // up to eight bumps
    private static final int CHIRP_LEVEL_DURATION_MILLIS = 100;
    private static final int DEFAULT_CHIRP_RAMP_DURATION_MILLIS = 100;
    private static final int FALLBACK_CHIRP_RAMP_DURATION_MILLIS = 50;

    private final Vibrator mVibrator;
    private final long[] mDefaultPattern;
@@ -102,6 +105,9 @@ public final class VibratorHelper {
     * @param insistent {@code true} if the vibration should loop until it is cancelled.
     */
    public VibrationEffect createFallbackVibration(boolean insistent) {
        if (mVibrator.hasFrequencyControl()) {
            return createChirpVibration(FALLBACK_CHIRP_RAMP_DURATION_MILLIS, insistent);
        }
        return createWaveformVibration(mFallbackPattern, insistent);
    }

@@ -111,9 +117,32 @@ public final class VibratorHelper {
     * @param insistent {@code true} if the vibration should loop until it is cancelled.
     */
    public VibrationEffect createDefaultVibration(boolean insistent) {
        if (mVibrator.hasFrequencyControl()) {
            return createChirpVibration(DEFAULT_CHIRP_RAMP_DURATION_MILLIS, insistent);
        }
        return createWaveformVibration(mDefaultPattern, insistent);
    }

    private static VibrationEffect createChirpVibration(int rampDuration, boolean insistent) {
        VibrationEffect.WaveformBuilder waveformBuilder = VibrationEffect.startWaveform()
                .addStep(/* amplitude= */ 0, /* frequency= */ -0.85f, /* duration= */ 0)
                .addRamp(/* amplitude= */ 1, /* frequency= */ -0.25f, rampDuration)
                .addStep(/* amplitude= */ 1, /* frequency= */ -0.25f, CHIRP_LEVEL_DURATION_MILLIS)
                .addRamp(/* amplitude= */ 0, /* frequency= */ -0.85f, rampDuration);

        if (insistent) {
            return waveformBuilder
                    .addStep(/* amplitude= */ 0, CHIRP_LEVEL_DURATION_MILLIS)
                    .build(/* repeat= */ 0);
        }

        VibrationEffect singleBeat = waveformBuilder.build();
        return VibrationEffect.startComposition()
                .addEffect(singleBeat)
                .addEffect(singleBeat, /* delay= */ CHIRP_LEVEL_DURATION_MILLIS)
                .compose();
    }

    private static long[] getLongArray(Resources resources, int resId, int maxLength, long[] def) {
        int[] ar = resources.getIntArray(resId);
        if (ar == null) {