mirror of
https://github.com/oplus-giulia-dev/android_hardware_oplus
synced 2025-11-04 22:05:34 +08:00
KeyHandler: Use mode specific vibration effects
NOTE: This change depends on following SystemUI change: - https://review.lineageos.org/c/305900 - https://android-review.googlesource.com/c/1648967 Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/3019 Change-Id: Ifc16a469311c4dd7ce9ef8633ab66546ef4e6ede
This commit is contained in:
@@ -32,6 +32,12 @@ public class KeyHandler implements DeviceKeyHandler {
|
||||
private static final int MODE_VIBRATION = 602;
|
||||
private static final int MODE_SILENCE = 603;
|
||||
|
||||
// Vibration effects
|
||||
private static final VibrationEffect MODE_NORMAL_EFFECT =
|
||||
VibrationEffect.createOneShot(250, VibrationEffect.DEFAULT_AMPLITUDE);
|
||||
private static final VibrationEffect MODE_VIBRATION_EFFECT =
|
||||
VibrationEffect.get(VibrationEffect.EFFECT_DOUBLE_CLICK);
|
||||
|
||||
private final Context mContext;
|
||||
private final AudioManager mAudioManager;
|
||||
private final Vibrator mVibrator;
|
||||
@@ -49,9 +55,11 @@ public class KeyHandler implements DeviceKeyHandler {
|
||||
switch (scanCode) {
|
||||
case MODE_NORMAL:
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL);
|
||||
doHapticFeedback(MODE_NORMAL_EFFECT);
|
||||
break;
|
||||
case MODE_VIBRATION:
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_VIBRATE);
|
||||
doHapticFeedback(MODE_VIBRATION_EFFECT);
|
||||
break;
|
||||
case MODE_SILENCE:
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_SILENT);
|
||||
@@ -59,15 +67,13 @@ public class KeyHandler implements DeviceKeyHandler {
|
||||
default:
|
||||
return event;
|
||||
}
|
||||
doHapticFeedback();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void doHapticFeedback() {
|
||||
private void doHapticFeedback(VibrationEffect effect) {
|
||||
if (mVibrator != null && mVibrator.hasVibrator()) {
|
||||
mVibrator.vibrate(VibrationEffect.createOneShot(50,
|
||||
VibrationEffect.DEFAULT_AMPLITUDE));
|
||||
mVibrator.vibrate(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user