From 1a1c0ec9108f1b63219d5f0e7df0ef5e4282573c Mon Sep 17 00:00:00 2001 From: sspanak Date: Tue, 24 Jan 2023 07:58:29 +0200 Subject: [PATCH] added longer initial repeat delay for the on-screen backspace --- .../sspanak/tt9/ime/SoftKeyHandler.java | 23 ++++++++++++++----- .../tt9/preferences/SettingsStore.java | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/io/github/sspanak/tt9/ime/SoftKeyHandler.java b/src/io/github/sspanak/tt9/ime/SoftKeyHandler.java index 01064ba1..0e110132 100644 --- a/src/io/github/sspanak/tt9/ime/SoftKeyHandler.java +++ b/src/io/github/sspanak/tt9/ime/SoftKeyHandler.java @@ -17,7 +17,6 @@ class SoftKeyHandler implements View.OnTouchListener { private final TraditionalT9 tt9; private View view = null; - private static final int BACKSPACE_DEBOUNCE_TIME = 40; private long lastBackspaceCall = 0; public SoftKeyHandler(TraditionalT9 tt9) { @@ -104,18 +103,26 @@ class SoftKeyHandler implements View.OnTouchListener { } - protected boolean handleBackspaceHold() { - if (System.currentTimeMillis() - lastBackspaceCall < BACKSPACE_DEBOUNCE_TIME) { + private boolean handleBackspaceHold() { + if (System.currentTimeMillis() - lastBackspaceCall < tt9.settings.getSoftKeyRepeatDelay()) { return true; } boolean handled = tt9.onBackspace(); - lastBackspaceCall = System.currentTimeMillis(); + + long now = System.currentTimeMillis(); + lastBackspaceCall = lastBackspaceCall == 0 ? tt9.settings.getSoftKeyInitialDelay() + now : now; return handled; } + private boolean handleBackspaceUp() { + lastBackspaceCall = 0; + return true; + } + + @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); @@ -131,8 +138,12 @@ class SoftKeyHandler implements View.OnTouchListener { return view.performClick(); } - if (buttonId == R.id.main_right && action == MotionEvent.AXIS_PRESSURE) { - return handleBackspaceHold(); + if (buttonId == R.id.main_right) { + if (action == MotionEvent.AXIS_PRESSURE) { + return handleBackspaceHold(); + } else if (action == MotionEvent.ACTION_UP) { + return handleBackspaceUp(); + } } return false; diff --git a/src/io/github/sspanak/tt9/preferences/SettingsStore.java b/src/io/github/sspanak/tt9/preferences/SettingsStore.java index 3c50b1f9..f3829e47 100644 --- a/src/io/github/sspanak/tt9/preferences/SettingsStore.java +++ b/src/io/github/sspanak/tt9/preferences/SettingsStore.java @@ -224,6 +224,9 @@ public class SettingsStore { public int getSuggestionSelectAnimationDuration() { return 66; } public int getSuggestionTranslateAnimationDuration() { return 0; } + public int getSoftKeyInitialDelay() { return 250; /* ms */ } + public int getSoftKeyRepeatDelay() { return 40; /* ms */ } + /************* add word, last word *************/