From dc5dcce81678f7377ef7f37bd18b840cc014f260 Mon Sep 17 00:00:00 2001 From: Dimo Karaivanov Date: Thu, 24 Aug 2023 17:36:23 +0300 Subject: [PATCH] added the ability to type special characters in 123 mode --- docs/user-manual.md | 4 +- .../github/sspanak/tt9/ime/modes/Mode123.java | 37 +++++++++++++++++-- .../tt9/ui/main/keys/SoftNumberKey.java | 10 ++--- .../tt9/ui/main/keys/SoftPunctuationKey.java | 25 ------------- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/docs/user-manual.md b/docs/user-manual.md index de1cb6454..8057bab45 100644 --- a/docs/user-manual.md +++ b/docs/user-manual.md @@ -73,7 +73,7 @@ _**NB2:** In messaging applications, you need to enable their "Send with ENTER" #### 0-key: - **In 123 mode:** - **Press:** type "0". - - **Hold:** type "+". + - **Hold:** type special/math characters. - **In ABC mode:** - **Press:** type space, newline or special/math characters. - **Hold:** type "0". @@ -83,7 +83,7 @@ _**NB2:** In messaging applications, you need to enable their "Send with ENTER" - **Hold:** type "0". #### 1- to 9-key: -- **In 123 mode:** type the respective number. +- **In 123 mode:** type the respective number or hold to type punctuation. - **In ABC and Predictive mode:** type a letter/punctuation character or hold to type the respective number. #### Add Word Key (Default: Press ✱): diff --git a/src/io/github/sspanak/tt9/ime/modes/Mode123.java b/src/io/github/sspanak/tt9/ime/modes/Mode123.java index 48035b3d6..367412eaf 100644 --- a/src/io/github/sspanak/tt9/ime/modes/Mode123.java +++ b/src/io/github/sspanak/tt9/ime/modes/Mode123.java @@ -2,21 +2,50 @@ import androidx.annotation.NonNull; +import java.util.ArrayList; +import java.util.Collections; + +import io.github.sspanak.tt9.languages.Characters; + public class Mode123 extends ModePassthrough { @Override public int getId() { return MODE_123; } @Override @NonNull public String toString() { return "123"; } @Override public final boolean is123() { return true; } @Override public boolean isPassthrough() { return false; } + @Override public int getSequenceLength() { return 1; } + @Override public boolean shouldAcceptPreviousSuggestion(int nextKey) { return true; } + + private final ArrayList> KEY_CHARACTERS = new ArrayList<>(); - @Override public void reset() { - super.reset(); - autoAcceptTimeout = 0; + public Mode123() { + // 0-key + KEY_CHARACTERS.add(new ArrayList<>(Collections.singletonList("+"))); + for (String character : Characters.Special) { + if (!character.equals("+") && !character.equals("\n")) { + KEY_CHARACTERS.get(0).add(character); + } + } + + // 1-key + KEY_CHARACTERS.add(new ArrayList<>(Collections.singletonList("."))); + for (String character : Characters.PunctuationEnglish) { + if (!character.equals(".")) { + KEY_CHARACTERS.get(1).add(character); + } + } } @Override public boolean onNumber(int number, boolean hold, int repeat) { reset(); - suggestions.add((number == 0 && hold) ? "+" : String.valueOf(number)); + + if (hold && number < KEY_CHARACTERS.size()) { + suggestions.addAll(KEY_CHARACTERS.get(number)); + } else { + autoAcceptTimeout = 0; + suggestions.add(String.valueOf(number)); + } + return true; } diff --git a/src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java b/src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java index a698c0bd3..4ec78d1f6 100644 --- a/src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java +++ b/src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java @@ -73,16 +73,16 @@ protected String getSubTitle() { } } - // no special labels in 123 mode - if (tt9.getInputMode() == InputMode.MODE_123) { - return null; - } - // 1 if (number == 1) { return ",:-)"; } + // no other special labels in 123 mode + if (tt9.getInputMode() == InputMode.MODE_123) { + return null; + } + // 2-9 Language language = LanguageCollection.getLanguage(tt9.getApplicationContext(), tt9.getSettings().getInputLanguage()); if (language == null) { diff --git a/src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java b/src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java index 073eeea94..734e0a9d5 100644 --- a/src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java +++ b/src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java @@ -19,20 +19,6 @@ public SoftPunctuationKey(Context context, AttributeSet attrs, int defStyleAttr) super(context, attrs, defStyleAttr); } - @Override - protected boolean handleHold() { - if (tt9 == null || tt9.getInputMode() != InputMode.MODE_123) { - return super.handleHold(); - } - - preventRepeat(); - int keyId = getId(); - if (keyId == R.id.soft_key_punctuation_1) return tt9.onText(","); - if (keyId == R.id.soft_key_punctuation_2) return tt9.onText("."); - - return false; - } - @Override protected boolean handleRelease() { if (!validateTT9Handler()) { @@ -68,15 +54,4 @@ protected String getTitle() { return "PUNC"; } - - @Override - protected String getSubTitle() { - int keyId = getId(); - if (tt9 != null && tt9.getInputMode() == InputMode.MODE_123) { - if (keyId == R.id.soft_key_punctuation_1) return ","; - if (keyId == R.id.soft_key_punctuation_2) return "."; - } - - return null; - } }