Removed audio feedback on cursor move

Added methods to customize for cursor haptic feedback using TEXT_HANDLE_MOVE and CLOCK_TICK (API <27)
This commit is contained in:
Steffen.S 2024-08-09 10:09:50 +02:00
parent f796b99e7a
commit 9e3d989d80
3 changed files with 25 additions and 2 deletions

View file

@ -189,8 +189,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
}
}
//Maybe consider specifying some new KeyCode to prevent spamming of the default sound
latinIME.hapticAndAudioFeedback(KeyCode.NOT_SPECIFIED, 0)
latinIME.hapticCursorFeedback()
if (inputLogic.moveCursorByAndReturnIfInsideComposingWord(moveSteps)) {
// no need to finish input and restart suggestions if we're still in the word

View file

@ -8,6 +8,7 @@ package helium314.keyboard.latin;
import android.content.Context;
import android.media.AudioManager;
import android.os.Build;
import android.os.Vibrator;
import android.view.HapticFeedbackConstants;
import android.view.View;
@ -105,6 +106,23 @@ public final class AudioAndHapticFeedbackManager {
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
}
public void performHapticCursorFeedback(final View viewToPerformHapticFeedbackOn) {
if (!mSettingsValues.mVibrateOn) {
return;
}
if (viewToPerformHapticFeedbackOn != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
viewToPerformHapticFeedbackOn.performHapticFeedback(
HapticFeedbackConstants.TEXT_HANDLE_MOVE,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}else {
viewToPerformHapticFeedbackOn.performHapticFeedback(
HapticFeedbackConstants.CLOCK_TICK,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
}
}
public void onSettingsChanged(final SettingsValues settingsValues) {
mSettingsValues = settingsValues;

View file

@ -1747,6 +1747,12 @@ public class LatinIME extends InputMethodService implements
}
}
public void hapticCursorFeedback() {
final MainKeyboardView keyboardView = mKeyboardSwitcher.getMainKeyboardView();
final AudioAndHapticFeedbackManager feedbackManager = AudioAndHapticFeedbackManager.getInstance();
feedbackManager.performHapticCursorFeedback(keyboardView);
}
public void hapticAndAudioFeedback(final int code, final int repeatCount) {
final MainKeyboardView keyboardView = mKeyboardSwitcher.getMainKeyboardView();
if (keyboardView != null && keyboardView.isInDraggingFinger()) {