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:
parent
a42c1ed1ee
commit
6225448eee
7 changed files with 24 additions and 9 deletions
|
|
@ -63,6 +63,10 @@ public abstract class HotkeyHandler extends TypingHandler {
|
||||||
|
|
||||||
|
|
||||||
public boolean onHotkey(int keyCode, boolean repeat, boolean validateOnly) {
|
public boolean onHotkey(int keyCode, boolean repeat, boolean validateOnly) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (keyCode == settings.getKeyAddWord()) {
|
if (keyCode == settings.getKeyAddWord()) {
|
||||||
return onKeyAddWord(validateOnly);
|
return onKeyAddWord(validateOnly);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package io.github.sspanak.tt9.preferences.settings;
|
package io.github.sspanak.tt9.preferences.settings;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
import io.github.sspanak.tt9.preferences.screens.hotkeys.SectionKeymap;
|
import io.github.sspanak.tt9.preferences.screens.hotkeys.SectionKeymap;
|
||||||
|
|
||||||
|
|
@ -40,7 +41,7 @@ class SettingsHotkeys extends SettingsHacks {
|
||||||
|
|
||||||
|
|
||||||
public int getFunctionKey(String functionName) {
|
public int getFunctionKey(String functionName) {
|
||||||
return getStringifiedInt(functionName, 0);
|
return getStringifiedInt(functionName, KeyEvent.KEYCODE_UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
import io.github.sspanak.tt9.util.Logger;
|
import io.github.sspanak.tt9.util.Logger;
|
||||||
|
|
||||||
public class SoftKey extends androidx.appcompat.widget.AppCompatButton implements View.OnTouchListener, View.OnLongClickListener {
|
public class SoftKey extends androidx.appcompat.widget.AppCompatButton implements View.OnTouchListener, View.OnLongClickListener {
|
||||||
|
private final String LOG_TAG = getClass().getSimpleName();
|
||||||
|
|
||||||
protected TraditionalT9 tt9;
|
protected TraditionalT9 tt9;
|
||||||
|
|
||||||
protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE;
|
protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE;
|
||||||
|
|
@ -63,8 +65,13 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
||||||
@Override
|
@Override
|
||||||
protected void onFinishInflate() {
|
protected void onFinishInflate() {
|
||||||
super.onFinishInflate();
|
super.onFinishInflate();
|
||||||
getRootView().setOnTouchListener(this);
|
View keyView = findViewById(getId());
|
||||||
getRootView().setOnLongClickListener(this);
|
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
|
@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
|
// sometimes this gets called twice, so we debounce the call to the repeating function
|
||||||
repeatHandler.removeCallbacks(this::repeatOnLongPress);
|
repeatHandler.removeCallbacks(this::repeatOnLongPress);
|
||||||
repeatHandler.postDelayed(this::repeatOnLongPress, 1);
|
repeatHandler.postDelayed(this::repeatOnLongPress, 5);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,7 +162,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
||||||
|
|
||||||
protected boolean validateTT9Handler() {
|
protected boolean validateTT9Handler() {
|
||||||
if (tt9 == null) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
public class SoftKeyInputMode extends SoftKey {
|
public class SoftKeyInputMode extends SoftKey {
|
||||||
public SoftKeyInputMode(Context context) {
|
public SoftKeyInputMode(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,13 @@ public class SoftNumberKey extends SoftKey {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean handleHold() {
|
protected boolean handleHold() {
|
||||||
if (tt9 == null) {
|
int keyCode = Key.numberToCode(getUpsideDownNumber(getId()));
|
||||||
return super.handleHold();
|
if (keyCode < 0 || !validateTT9Handler()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
preventRepeat();
|
preventRepeat();
|
||||||
int keyCode = Key.numberToCode(getUpsideDownNumber(getId()));
|
|
||||||
tt9.onKeyLongPress(keyCode, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
tt9.onKeyLongPress(keyCode, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
||||||
tt9.onKeyUp(keyCode, new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
tt9.onKeyUp(keyCode, new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@
|
||||||
|
|
||||||
<io.github.sspanak.tt9.ui.main.keys.SoftBackspaceKey
|
<io.github.sspanak.tt9.ui.main.keys.SoftBackspaceKey
|
||||||
style="@android:style/Widget.Holo.Button.Borderless"
|
style="@android:style/Widget.Holo.Button.Borderless"
|
||||||
|
android:id="@+id/soft_key_backspace"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="@dimen/numpad_control_key_layout_weight"
|
android:layout_weight="@dimen/numpad_control_key_layout_weight"
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@
|
||||||
|
|
||||||
<io.github.sspanak.tt9.ui.main.keys.SoftBackspaceKey
|
<io.github.sspanak.tt9.ui.main.keys.SoftBackspaceKey
|
||||||
style="@android:style/Widget.Holo.Button.Borderless"
|
style="@android:style/Widget.Holo.Button.Borderless"
|
||||||
|
android:id="@+id/soft_key_backspace"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="3"
|
android:layout_weight="3"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue