sm8250-common: 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:
parent
c943073afe
commit
1157082e8c
1 changed files with 10 additions and 4 deletions
|
@ -32,6 +32,12 @@ public class KeyHandler implements DeviceKeyHandler {
|
||||||
private static final int MODE_VIBRATION = 602;
|
private static final int MODE_VIBRATION = 602;
|
||||||
private static final int MODE_SILENCE = 603;
|
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 Context mContext;
|
||||||
private final AudioManager mAudioManager;
|
private final AudioManager mAudioManager;
|
||||||
private final Vibrator mVibrator;
|
private final Vibrator mVibrator;
|
||||||
|
@ -49,9 +55,11 @@ public class KeyHandler implements DeviceKeyHandler {
|
||||||
switch (scanCode) {
|
switch (scanCode) {
|
||||||
case MODE_NORMAL:
|
case MODE_NORMAL:
|
||||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL);
|
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL);
|
||||||
|
doHapticFeedback(MODE_NORMAL_EFFECT);
|
||||||
break;
|
break;
|
||||||
case MODE_VIBRATION:
|
case MODE_VIBRATION:
|
||||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_VIBRATE);
|
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_VIBRATE);
|
||||||
|
doHapticFeedback(MODE_VIBRATION_EFFECT);
|
||||||
break;
|
break;
|
||||||
case MODE_SILENCE:
|
case MODE_SILENCE:
|
||||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_SILENT);
|
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_SILENT);
|
||||||
|
@ -59,15 +67,13 @@ public class KeyHandler implements DeviceKeyHandler {
|
||||||
default:
|
default:
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
doHapticFeedback();
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doHapticFeedback() {
|
private void doHapticFeedback(VibrationEffect effect) {
|
||||||
if (mVibrator != null && mVibrator.hasVibrator()) {
|
if (mVibrator != null && mVibrator.hasVibrator()) {
|
||||||
mVibrator.vibrate(VibrationEffect.createOneShot(50,
|
mVibrator.vibrate(effect);
|
||||||
VibrationEffect.DEFAULT_AMPLITUDE));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue