Skip to content

Commit

Permalink
added the ability to type special characters in 123 mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sspanak committed Aug 24, 2023
1 parent 54b2abd commit dc5dcce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
4 changes: 2 additions & 2 deletions docs/user-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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 ✱):
Expand Down
37 changes: 33 additions & 4 deletions src/io/github/sspanak/tt9/ime/modes/Mode123.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayList<String>> 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;
}

Expand Down
10 changes: 5 additions & 5 deletions src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 0 additions & 25 deletions src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit dc5dcce

Please sign in to comment.