1
0
Fork 0

fixed holding keys not working in some cases and removed the 'hold' function for some keys

This commit is contained in:
sspanak 2023-01-16 18:14:08 +02:00 committed by Dimo Karaivanov
parent 3fe35c8c9d
commit 61055c7b6b
4 changed files with 108 additions and 74 deletions

View file

@ -18,8 +18,10 @@ or get the APK from the [Releases Section](https://github.com/sspanak/tt9/releas
_If you own a phone with Android 2.2 up to 4.4, please refer to the original version of Traditional T9 from 2016._
## Using Traditional T9
If you just wish to install and use Traditional T9, check out the [user manual](docs/user-manual.md) for useful tips and a list of keypad shortcuts.
## How to use Traditional T9?
Before using Traditional T9 for the first time you would need to load a dictionary and configure it. After that, you could start typing right away in one of the three modes: Predictive, ABC or Numeric. And even if you have mastered the keypad back in the days, you would still find the Predictive mode now provides powerful and smart new ways of typing with even less key presses.
So make sure to read the initial setup and the hotkey tips in the [user manual](docs/user-manual.md).
## Contributing to the Project
As with many other open-source projects, this one is also maintained by its author in his free time. Any help in making Traditional T9 better will be highly appreciated. This includes:

View file

@ -51,7 +51,7 @@ _Predictive mode only._
#### 0-key:
- **In 123 mode:**
- **Press:**: type "0".
- **Press:** type "0".
- **Hold:** type "+".
- **In ABC mode:**
- **Press:** type space, newline or special/math characters.
@ -104,4 +104,3 @@ On the Settings screen, you can choose languages for typing, configure the keypa
To access it:
- Start typing in a text field to wake up TT9.
- Use the on-screen gear button or press the Settings Key.
-

View file

@ -145,20 +145,24 @@ abstract class KeyPadHandler extends InputMethodService {
return false;
}
// start tracking key hold
if (keyCode == KeyEvent.KEYCODE_0 || shouldTrackNumPress()) {
event.startTracking();
}
// holding "0" is important in all cases
if (keyCode == KeyEvent.KEYCODE_0) {
event.startTracking();
return true;
}
// In dialer fields we only handle "0", when held, and convert it to "+"
// In dialer fields we just want passthrough, but we do handle holding "0",
// to convert it to "+".
if (mEditing == EDITING_DIALER) {
return false;
}
// start tracking key hold
if (shouldTrackNumPress() || isSpecialFunctionKey(-keyCode)) {
event.startTracking();
return true;
}
if (
isSpecialFunctionKey(keyCode)
|| keyCode == KeyEvent.KEYCODE_STAR

View file

@ -28,73 +28,11 @@ public class SectionKeymap {
private final Collection<DropDownPreference> items;
private final SettingsStore settings;
public SectionKeymap(Collection<DropDownPreference> dropDowns, Context context, SettingsStore settings) {
items = dropDowns;
this.settings = settings;
Resources resources = context.getResources();
KEYS.put(String.valueOf(0), resources.getString(R.string.key_none));
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_BACK), resources.getString(R.string.key_back));
KEYS.put(String.valueOf(KeyEvent.KEYCODE_CALL), resources.getString(R.string.key_call));
}
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_CALL),
resources.getString(R.string.key_call) + " " + resources.getString(R.string.key_hold_key)
);
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_DEL)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_DEL), resources.getString(R.string.key_delete));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_DEL),
resources.getString(R.string.key_delete) + " " + resources.getString(R.string.key_hold_key)
);
}
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_F1)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_F1), resources.getString(R.string.key_f1));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_F1),
resources.getString(R.string.key_f1) + " " + resources.getString(R.string.key_hold_key)
);
}
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_F2)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_F2), resources.getString(R.string.key_f2));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_F2),
resources.getString(R.string.key_f2) + " " + resources.getString(R.string.key_hold_key)
);
}
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_F3)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_F3), resources.getString(R.string.key_f3));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_F3),
resources.getString(R.string.key_f3) + " " + resources.getString(R.string.key_hold_key)
);
}
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_F4)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_F4), resources.getString(R.string.key_f4));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_F4),
resources.getString(R.string.key_f4) + " " + resources.getString(R.string.key_hold_key)
);
}
if (ViewConfiguration.get(context).hasPermanentMenuKey()) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_MENU), resources.getString(R.string.key_menu));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_MENU),
resources.getString(R.string.key_menu) + " " + resources.getString(R.string.key_hold_key)
);
}
KEYS.put(String.valueOf(KeyEvent.KEYCODE_POUND), resources.getString(R.string.key_pound));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_POUND),
resources.getString(R.string.key_pound) + " " + resources.getString(R.string.key_hold_key)
);
KEYS.put(String.valueOf(KeyEvent.KEYCODE_STAR), resources.getString(R.string.key_star));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_STAR),
resources.getString(R.string.key_star) + " " + resources.getString(R.string.key_hold_key)
);
generateKeyList(context);
}
@ -122,6 +60,97 @@ public class SectionKeymap {
}
/**
* generateKeyList
* Generates the key list to be used in each dropdown.
*
* NOTE: Some dropdowns do not support some keys,but filtering is performed
* in populate(), not here.
*
* NOTE 2: Holding is deliberately skipped for most of the keys. It's because
* when a function is assigned only to the "hold" state, the "short press" state
* also gets consumed in KeyPadHandler, effectively disabling the default function of the key.
* However, this may be confusing from user perspective, so in order to avoid lengthy
* explanations in the documentation (that no one reads), the problem is avoided by
* simply not causing it.
*
* So, if adding support for new keys, think twice whether to add the "hold" variant as well.
*/
private void generateKeyList(Context context) {
Resources resources = context.getResources();
KEYS.put(String.valueOf(0), resources.getString(R.string.key_none));
// BACK
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_BACK), resources.getString(R.string.key_back));
}
// CALL
KEYS.put(String.valueOf(KeyEvent.KEYCODE_CALL), resources.getString(R.string.key_call));
// DELETE / BACKSPACE
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_DEL)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_DEL), resources.getString(R.string.key_delete));
}
// F1
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_F1)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_F1), resources.getString(R.string.key_f1));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_F1),
resources.getString(R.string.key_f1) + " " + resources.getString(R.string.key_hold_key)
);
}
// F2
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_F2)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_F2), resources.getString(R.string.key_f2));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_F2),
resources.getString(R.string.key_f2) + " " + resources.getString(R.string.key_hold_key)
);
}
// F3
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_F3)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_F3), resources.getString(R.string.key_f3));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_F3),
resources.getString(R.string.key_f3) + " " + resources.getString(R.string.key_hold_key)
);
}
// F4
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_F4)) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_F4), resources.getString(R.string.key_f4));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_F4),
resources.getString(R.string.key_f4) + " " + resources.getString(R.string.key_hold_key)
);
}
// MENU
if (ViewConfiguration.get(context).hasPermanentMenuKey()) {
KEYS.put(String.valueOf(KeyEvent.KEYCODE_MENU), resources.getString(R.string.key_menu));
}
// #
KEYS.put(String.valueOf(KeyEvent.KEYCODE_POUND), resources.getString(R.string.key_pound));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_POUND),
resources.getString(R.string.key_pound) + " " + resources.getString(R.string.key_hold_key)
);
// *
KEYS.put(String.valueOf(KeyEvent.KEYCODE_STAR), resources.getString(R.string.key_star));
KEYS.put(
String.valueOf(-KeyEvent.KEYCODE_STAR),
resources.getString(R.string.key_star) + " " + resources.getString(R.string.key_hold_key)
);
}
private void populateOtherItems(DropDownPreference itemToSkip) {
for (DropDownPreference item : items) {
if (itemToSkip != null && item != null && Objects.equals(itemToSkip.getKey(), item.getKey())) {