1
0
Fork 0

Virtual keyboard minor bugfixes (#491)

* prevent incorrect keycodes when holding the virtual number keys

* fixed incorrect handling of unset hotkeys

* fixed touch listeners being assigned to the wrong virtual key sometimes
This commit is contained in:
Dimo Karaivanov 2024-04-17 17:23:40 +03:00
parent a42c1ed1ee
commit 6225448eee
7 changed files with 24 additions and 9 deletions

View file

@ -63,6 +63,10 @@ public abstract class HotkeyHandler extends TypingHandler {
public boolean onHotkey(int keyCode, boolean repeat, boolean validateOnly) {
if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
return false;
}
if (keyCode == settings.getKeyAddWord()) {
return onKeyAddWord(validateOnly);
}

View file

@ -1,6 +1,7 @@
package io.github.sspanak.tt9.preferences.settings;
import android.content.Context;
import android.view.KeyEvent;
import io.github.sspanak.tt9.preferences.screens.hotkeys.SectionKeymap;
@ -40,7 +41,7 @@ class SettingsHotkeys extends SettingsHacks {
public int getFunctionKey(String functionName) {
return getStringifiedInt(functionName, 0);
return getStringifiedInt(functionName, KeyEvent.KEYCODE_UNKNOWN);
}

View file

@ -23,6 +23,8 @@ import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.util.Logger;
public class SoftKey extends androidx.appcompat.widget.AppCompatButton implements View.OnTouchListener, View.OnLongClickListener {
private final String LOG_TAG = getClass().getSimpleName();
protected TraditionalT9 tt9;
protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE;
@ -63,8 +65,13 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
@Override
protected void onFinishInflate() {
super.onFinishInflate();
getRootView().setOnTouchListener(this);
getRootView().setOnLongClickListener(this);
View keyView = findViewById(getId());
if (keyView != null) {
keyView.setOnTouchListener(this);
keyView.setOnLongClickListener(this);
} else {
Logger.e(LOG_TAG, "Failed settings touch listeners. Cannot find SoftKey with ID: " + getId());
}
}
@Override
@ -94,7 +101,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
// sometimes this gets called twice, so we debounce the call to the repeating function
repeatHandler.removeCallbacks(this::repeatOnLongPress);
repeatHandler.postDelayed(this::repeatOnLongPress, 1);
repeatHandler.postDelayed(this::repeatOnLongPress, 5);
return true;
}
@ -155,7 +162,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
protected boolean validateTT9Handler() {
if (tt9 == null) {
Logger.w(getClass().getCanonicalName(), "Traditional T9 handler is not set. Ignoring key press.");
Logger.w(LOG_TAG, "Traditional T9 handler is not set. Ignoring key press.");
return false;
}

View file

@ -4,7 +4,7 @@ import android.content.Context;
import android.util.AttributeSet;
public class SoftKeyInputMode extends SoftKey {
public SoftKeyInputMode(Context context) {
public SoftKeyInputMode(Context context) {
super(context);
}

View file

@ -29,12 +29,13 @@ public class SoftNumberKey extends SoftKey {
@Override
protected boolean handleHold() {
if (tt9 == null) {
return super.handleHold();
int keyCode = Key.numberToCode(getUpsideDownNumber(getId()));
if (keyCode < 0 || !validateTT9Handler()) {
return false;
}
preventRepeat();
int keyCode = Key.numberToCode(getUpsideDownNumber(getId()));
tt9.onKeyLongPress(keyCode, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
tt9.onKeyUp(keyCode, new KeyEvent(KeyEvent.ACTION_UP, keyCode));

View file

@ -127,6 +127,7 @@
<io.github.sspanak.tt9.ui.main.keys.SoftBackspaceKey
style="@android:style/Widget.Holo.Button.Borderless"
android:id="@+id/soft_key_backspace"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="@dimen/numpad_control_key_layout_weight"

View file

@ -67,6 +67,7 @@
<io.github.sspanak.tt9.ui.main.keys.SoftBackspaceKey
style="@android:style/Widget.Holo.Button.Borderless"
android:id="@+id/soft_key_backspace"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"