From d39cbecb404378d267391be6767d89ecd4aaaa93 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Mon, 16 Apr 2018 19:35:13 +0100 Subject: [PATCH] Use config_longPressVibePattern as heavy click fallback. Rather than using the regular click effect as the fallback, use the long press pattern since heavy click is the new effect for long press. This also lets us distinguish the two effects in the configuration. Bug: 77863933 Test: long-press on something, feel the effect Change-Id: Ie22d064cbdd2d33702180cb528d743e75ff8ae63 --- .../com/android/server/VibratorService.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 66c2b073af33e..83d2bf7320c50 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -286,23 +286,28 @@ public class VibratorService extends IVibratorService.Stub filter.addAction(Intent.ACTION_SCREEN_OFF); context.registerReceiver(mIntentReceiver, filter); - long[] clickEffectTimings = getLongIntArray(context.getResources(), + VibrationEffect clickEffect = createEffectFromResource( com.android.internal.R.array.config_virtualKeyVibePattern); - VibrationEffect clickEffect = createEffect(clickEffectTimings); VibrationEffect doubleClickEffect = VibrationEffect.createWaveform( DOUBLE_CLICK_EFFECT_FALLBACK_TIMINGS, -1 /*repeatIndex*/); - long[] tickEffectTimings = getLongIntArray(context.getResources(), + VibrationEffect heavyClickEffect = createEffectFromResource( + com.android.internal.R.array.config_longPressVibePattern); + VibrationEffect tickEffect = createEffectFromResource( com.android.internal.R.array.config_clockTickVibePattern); - VibrationEffect tickEffect = createEffect(tickEffectTimings); mFallbackEffects = new SparseArray(); mFallbackEffects.put(VibrationEffect.EFFECT_CLICK, clickEffect); mFallbackEffects.put(VibrationEffect.EFFECT_DOUBLE_CLICK, doubleClickEffect); mFallbackEffects.put(VibrationEffect.EFFECT_TICK, tickEffect); - mFallbackEffects.put(VibrationEffect.EFFECT_HEAVY_CLICK, clickEffect); + mFallbackEffects.put(VibrationEffect.EFFECT_HEAVY_CLICK, heavyClickEffect); } - private static VibrationEffect createEffect(long[] timings) { + private VibrationEffect createEffectFromResource(int resId) { + long[] timings = getLongIntArray(mContext.getResources(), resId); + return createEffectFromTimings(timings); + } + + private static VibrationEffect createEffectFromTimings(long[] timings) { if (timings == null || timings.length == 0) { return null; } else if (timings.length == 1) {