1
0
Fork 0

fixed recomposing one more time and simplified the Backspace logic greatly

This commit is contained in:
sspanak 2024-09-06 15:41:09 +03:00 committed by Dimo Karaivanov
parent 715b13d74a
commit a77f14cacb
6 changed files with 20 additions and 35 deletions

View file

@ -11,7 +11,7 @@ import io.github.sspanak.tt9.util.Ternary;
abstract public class AbstractHandler extends InputMethodService { abstract public class AbstractHandler extends InputMethodService {
// hardware key handlers // hardware key handlers
abstract protected Ternary onBack(); abstract protected Ternary onBack();
abstract public boolean onBackspace(boolean hold); abstract public boolean onBackspace(int repeat);
abstract public boolean onHotkey(int keyCode, boolean repeat, boolean validateOnly); abstract public boolean onHotkey(int keyCode, boolean repeat, boolean validateOnly);
abstract protected boolean onNumber(int key, boolean hold, int repeat); abstract protected boolean onNumber(int key, boolean hold, int repeat);
abstract public boolean onOK(); abstract public boolean onOK();

View file

@ -60,11 +60,7 @@ abstract class KeyPadHandler extends UiHandler {
// "backspace" key must repeat its function when held down, so we handle it in a special way // "backspace" key must repeat its function when held down, so we handle it in a special way
if (Key.isBackspace(settings, keyCode)) { if (Key.isBackspace(settings, keyCode)) {
if ( if (onBackspace(event.getRepeatCount())) {
(settings.getBackspaceAcceleration() && event.getRepeatCount() > 0 && event.getRepeatCount() % SettingsStore.BACKSPACE_ACCELERATION_HARD_KEY_REPEAT_DEBOUNCE == 0 && onBackspace(true))
|| (settings.getBackspaceAcceleration() && event.getRepeatCount() > 0)
|| onBackspace(false)
) {
return Key.setHandled(KeyEvent.KEYCODE_DEL, true); return Key.setHandled(KeyEvent.KEYCODE_DEL, true);
} else { } else {
Key.setHandled(KeyEvent.KEYCODE_DEL, false); Key.setHandled(KeyEvent.KEYCODE_DEL, false);

View file

@ -20,6 +20,7 @@ import io.github.sspanak.tt9.ime.modes.InputMode;
import io.github.sspanak.tt9.ime.modes.ModePredictive; import io.github.sspanak.tt9.ime.modes.ModePredictive;
import io.github.sspanak.tt9.languages.Language; import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.languages.LanguageCollection; import io.github.sspanak.tt9.languages.LanguageCollection;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.UI; import io.github.sspanak.tt9.ui.UI;
import io.github.sspanak.tt9.util.Text; import io.github.sspanak.tt9.util.Text;
@ -109,7 +110,7 @@ public abstract class TypingHandler extends KeyPadHandler {
@Override @Override
public boolean onBackspace(boolean hold) { public boolean onBackspace(int repeat) {
// Dialer fields seem to handle backspace on their own and we must ignore it, // Dialer fields seem to handle backspace on their own and we must ignore it,
// otherwise, keyDown race condition occur for all keys. // otherwise, keyDown race condition occur for all keys.
if (mInputMode.isPassthrough()) { if (mInputMode.isPassthrough()) {
@ -124,17 +125,21 @@ public abstract class TypingHandler extends KeyPadHandler {
suggestionOps.cancelDelayedAccept(); suggestionOps.cancelDelayedAccept();
resetKeyRepeat(); resetKeyRepeat();
if (!hold && mInputMode.onBackspace()) { if (settings.getBackspaceAcceleration() && repeat > 0 && repeat % SettingsStore.BACKSPACE_ACCELERATION_REPEAT_DEBOUNCE != 0) {
return true;
}
if (repeat == 0 && mInputMode.onBackspace()) {
getSuggestions(); getSuggestions();
} else { } else {
suggestionOps.commitCurrent(false); suggestionOps.commitCurrent(false);
mInputMode.reset(); mInputMode.reset();
int prevChars = hold ? Math.max(textField.getPaddedWordBeforeCursorLength(), 1) : 1; int charsToDelete = settings.getBackspaceAcceleration() && repeat > 0 ? Math.max(textField.getPaddedWordBeforeCursorLength(), 1) : 1;
textField.deleteChars(prevChars); textField.deleteChars(charsToDelete);
} }
if (settings.getBackspaceRecomposing() && !hold && suggestionOps.isEmpty()) { if (settings.getBackspaceRecomposing() && repeat == 0 && suggestionOps.isEmpty()) {
final String previousWord = textField.getWordBeforeCursor(mLanguage, 0, false); final String previousWord = textField.getWordBeforeCursor(mLanguage, 0, false);
if (mInputMode.recompose(previousWord) && textField.recompose(previousWord)) { if (mInputMode.recompose(previousWord) && textField.recompose(previousWord)) {
getSuggestions(); getSuggestions();

View file

@ -8,7 +8,7 @@ public class SettingsStore extends SettingsUI {
/************* internal settings *************/ /************* internal settings *************/
public static final int BACKSPACE_ACCELERATION_MAX_CHARS = 20; public static final int BACKSPACE_ACCELERATION_MAX_CHARS = 20;
public static final int BACKSPACE_ACCELERATION_HARD_KEY_REPEAT_DEBOUNCE = 5; public static final int BACKSPACE_ACCELERATION_REPEAT_DEBOUNCE = 5;
public final static int CLIPBOARD_PREVIEW_LENGTH = 20; public final static int CLIPBOARD_PREVIEW_LENGTH = 20;
public final static int CUSTOM_WORDS_IMPORT_MAX_LINES = 250; public final static int CUSTOM_WORDS_IMPORT_MAX_LINES = 250;
public final static int CUSTOM_WORDS_MAX = 1000; public final static int CUSTOM_WORDS_MAX = 1000;
@ -22,7 +22,6 @@ public class SettingsStore extends SettingsUI {
public final static byte SLOW_QUERY_TIME = 50; // ms public final static byte SLOW_QUERY_TIME = 50; // ms
public final static int SOFT_KEY_DOUBLE_CLICK_DELAY = 500; // ms public final static int SOFT_KEY_DOUBLE_CLICK_DELAY = 500; // ms
public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms
public final static int SOFT_KEY_BACKSPACE_ACCELERATION_REPEAT_DELAY = SOFT_KEY_REPEAT_DELAY * BACKSPACE_ACCELERATION_HARD_KEY_REPEAT_DEBOUNCE; // ms
public final static int SOFT_KEY_TITLE_SIZE = 18; // sp public final static int SOFT_KEY_TITLE_SIZE = 18; // sp
public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE = 0.55f; public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE = 0.55f;
public final static float SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE = 0.72f; public final static float SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE = 0.72f;

View file

@ -6,11 +6,10 @@ import android.view.KeyEvent;
import io.github.sspanak.tt9.R; import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.languages.LanguageKind; import io.github.sspanak.tt9.languages.LanguageKind;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.Vibration; import io.github.sspanak.tt9.ui.Vibration;
public class SoftBackspaceKey extends SoftKey { public class SoftBackspaceKey extends SoftKey {
private boolean hold; private int repeat = 0;
public SoftBackspaceKey(Context context) { public SoftBackspaceKey(Context context) {
super(context); super(context);
@ -27,30 +26,25 @@ public class SoftBackspaceKey extends SoftKey {
@Override @Override
final protected boolean handlePress() { final protected boolean handlePress() {
super.handlePress(); super.handlePress();
hold = false; repeat = 0;
return deleteText(); return deleteText();
} }
@Override @Override
final protected void handleHold() { final protected void handleHold() {
hold = true; repeat++;
deleteText(); deleteText();
} }
@Override @Override
final protected boolean handleRelease() { final protected boolean handleRelease() {
vibrate(hold ? Vibration.getReleaseVibration() : Vibration.getNoVibration()); vibrate(repeat > 0 ? Vibration.getReleaseVibration() : Vibration.getNoVibration());
hold = false; repeat = 0;
return true; return true;
} }
@Override
final protected int getLongPressRepeatDelay() {
return tt9 != null && tt9.getSettings().getBackspaceAcceleration() ? SettingsStore.SOFT_KEY_BACKSPACE_ACCELERATION_REPEAT_DELAY : super.getLongPressRepeatDelay();
}
private boolean deleteText() { private boolean deleteText() {
if (validateTT9Handler() && !tt9.onBackspace(hold && tt9.getSettings().getBackspaceAcceleration())) { if (validateTT9Handler() && !tt9.onBackspace(repeat)) {
// Limited or special numeric field (e.g. formatted money or dates) cannot always return // Limited or special numeric field (e.g. formatted money or dates) cannot always return
// the text length, therefore onBackspace() seems them as empty and does nothing. This results // the text length, therefore onBackspace() seems them as empty and does nothing. This results
// in fallback to the default hardware key action. Here we simulate the hardware BACKSPACE. // in fallback to the default hardware key action. Here we simulate the hardware BACKSPACE.

View file

@ -124,20 +124,11 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
handleHold(); handleHold();
lastPressedKey = ignoreLastPressedKey ? -1 : getId(); lastPressedKey = ignoreLastPressedKey ? -1 : getId();
repeatHandler.removeCallbacks(this::repeatOnLongPress); repeatHandler.removeCallbacks(this::repeatOnLongPress);
repeatHandler.postDelayed(this::repeatOnLongPress, getLongPressRepeatDelay()); repeatHandler.postDelayed(this::repeatOnLongPress, SettingsStore.SOFT_KEY_REPEAT_DELAY);
} }
} }
/**
* Returns the delay between repeated calls to "handleHold()" when the SoftKey is being held.
* Used in "repeatOnLongPress()".
*/
protected int getLongPressRepeatDelay() {
return SettingsStore.SOFT_KEY_REPEAT_DELAY;
}
/** /**
* preventRepeat * preventRepeat
* Prevents "handleHold()" from being called repeatedly when the SoftKey is being held. * Prevents "handleHold()" from being called repeatedly when the SoftKey is being held.