Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/help-tools.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static convertHeaders(markdown) {
}

def header = line.replaceAll("^#+", "").trim()
def anchor = header.toLowerCase().replaceAll("[^a-z0-9]+", "-")
def anchor = header.toLowerCase().replaceAll("[^a-z0-9]+", "-").replaceAll("[\\-]+\$", "")

return "<h${headerNumber} id=\"${anchor}\">${header}</h${headerNumber}>"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,16 @@ public static void insertWordPairs(@NonNull SQLiteDatabase db, int langId, Colle
return;
}

StringBuilder sql = new StringBuilder(
"INSERT INTO " + Tables.getWordPairs(langId) + " (word1, word2, sequence2) VALUES"
);

for (WordPair pair : pairs) {
db.insert(Tables.getWordPairs(langId), null, pair.toContentValues());
sql.append(pair.toSqlRow()).append(",");
}

sql.setLength(sql.length() - 1);

db.execSQL(sql.toString());
}
}
18 changes: 6 additions & 12 deletions app/src/main/java/io/github/sspanak/tt9/db/wordPairs/WordPair.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.sspanak.tt9.db.wordPairs;

import android.content.ContentValues;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand Down Expand Up @@ -31,7 +29,7 @@ boolean isInvalid() {
|| word1.isEmpty() || word2.isEmpty()
|| (word1.length() > SettingsStore.WORD_PAIR_MAX_WORD_LENGTH && word2.length() > SettingsStore.WORD_PAIR_MAX_WORD_LENGTH)
|| word1.equals(word2)
|| sequence2 == null || word2.length() != sequence2.length()
|| sequence2 == null || word2.length() != sequence2.length() || !(new Text(sequence2).isNumeric())
|| !(new Text(word1).isAlphabetic()) || !(new Text(word2).isAlphabetic());
}

Expand All @@ -42,15 +40,6 @@ public String getWord2() {
}


public ContentValues toContentValues() {
ContentValues values = new ContentValues();
values.put("word1", word1);
values.put("word2", word2);
values.put("sequence2", sequence2);
return values;
}


@Override
public int hashCode() {
if (hash == null) {
Expand All @@ -67,6 +56,11 @@ public boolean equals(@Nullable Object obj) {
}


public String toSqlRow() {
return "('" + word1 + "','" + word2 + "','" + sequence2 + "')";
}


@NonNull
@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
abstract public class AbstractHandler extends InputMethodService {
// hardware key handlers
abstract protected Ternary onBack();
abstract public boolean onBackspace(boolean hold);
abstract public boolean onBackspace(int repeat);
abstract public boolean onHotkey(int keyCode, boolean repeat, boolean validateOnly);
abstract protected boolean onNumber(int key, boolean hold, int repeat);
abstract public boolean onOK();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected void nextTextCase() {
String firstSuggestionAfter = mInputMode.getSuggestions().get(0);

// this is a word and the text case has finally changed
if (!firstSuggestionAfter.equalsIgnoreCase(suggestionOps.get(0))) {
if (!firstSuggestionAfter.equals(suggestionOps.get(0))) {
break;
}
}
Expand Down
23 changes: 0 additions & 23 deletions app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public boolean onHotkey(int keyCode, boolean repeat, boolean validateOnly) {
return onKeyScrollSuggestion(validateOnly, false);
}

if (keyCode == settings.getKeyTab()) {
return onKeyTab(validateOnly);
}

if (keyCode == settings.getKeySelectKeyboard()) {
return onKeySelectKeyboard(validateOnly);
}
Expand Down Expand Up @@ -298,25 +294,6 @@ public boolean onKeyNextInputMode(boolean validateOnly) {
}


public boolean onKeyTab(boolean validateOnly) {
if (shouldBeOff()) {
return false;
}

if (validateOnly) {
return true;
}

if (inputType.isMultilineText()) {
return onText("\t", validateOnly);
} else {
textField.sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
}

return true;
}


private boolean onKeySelectKeyboard(boolean validateOnly) {
if (!isInputViewShown() || shouldBeOff()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {

// "backspace" key must repeat its function when held down, so we handle it in a special way
if (Key.isBackspace(settings, keyCode)) {
if (
(settings.getBackspaceAcceleration() && event.getRepeatCount() > 0 && event.getRepeatCount() % SettingsStore.BACKSPACE_ACCELERATION_HARD_KEY_REPEAT_DEBOUNCE == 0 && onBackspace(true))
|| (settings.getBackspaceAcceleration() && event.getRepeatCount() > 0)
|| onBackspace(false)
) {
if (onBackspace(event.getRepeatCount())) {
return Key.setHandled(KeyEvent.KEYCODE_DEL, true);
} else {
Key.setHandled(KeyEvent.KEYCODE_DEL, false);
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.sspanak.tt9.ime.modes.ModePredictive;
import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.languages.LanguageCollection;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.UI;
import io.github.sspanak.tt9.util.Text;

Expand Down Expand Up @@ -109,7 +110,7 @@ protected void onFinishTyping() {


@Override
public boolean onBackspace(boolean hold) {
public boolean onBackspace(int repeat) {
// Dialer fields seem to handle backspace on their own and we must ignore it,
// otherwise, keyDown race condition occur for all keys.
if (mInputMode.isPassthrough()) {
Expand All @@ -124,17 +125,21 @@ public boolean onBackspace(boolean hold) {
suggestionOps.cancelDelayedAccept();
resetKeyRepeat();

if (!hold && mInputMode.onBackspace()) {
if (settings.getBackspaceAcceleration() && repeat > 0 && repeat % SettingsStore.BACKSPACE_ACCELERATION_REPEAT_DEBOUNCE != 0) {
return true;
}

if (repeat == 0 && mInputMode.onBackspace()) {
getSuggestions();
} else {
suggestionOps.commitCurrent(false);
mInputMode.reset();

int prevChars = hold ? Math.max(textField.getPaddedWordBeforeCursorLength(), 1) : 1;
textField.deleteChars(prevChars);
int charsToDelete = settings.getBackspaceAcceleration() && repeat > 0 ? Math.max(textField.getPaddedWordBeforeCursorLength(), 1) : 1;
textField.deleteChars(charsToDelete);
}

if (settings.getBackspaceRecomposing() && !hold && suggestionOps.isEmpty()) {
if (settings.getBackspaceRecomposing() && repeat == 0 && suggestionOps.isEmpty()) {
final String previousWord = textField.getWordBeforeCursor(mLanguage, 0, false);
if (mInputMode.recompose(previousWord) && textField.recompose(previousWord)) {
getSuggestions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import androidx.annotation.NonNull;

import java.util.ArrayList;

import io.github.sspanak.tt9.hacks.InputType;
import io.github.sspanak.tt9.ime.modes.InputMode;
import io.github.sspanak.tt9.languages.Language;
Expand Down Expand Up @@ -124,11 +126,12 @@ public Text getTextBeforeCursor() {
}

int endIndex = before.length();
ArrayList<String> punctuation = language.getKeyCharacters(1);

for (int i = before.length() - 1; i >= 0; i--) {
char currentLetter = before.charAt(i);

if (stopAtPunctuation && language.getKeyCharacters(1).contains(currentLetter + "")) {
if (stopAtPunctuation && punctuation.contains(String.valueOf(currentLetter))) {
return "";
}

Expand All @@ -137,7 +140,7 @@ public Text getTextBeforeCursor() {
&& !(currentLetter == '\'' && (LanguageKind.isHebrew(language) || LanguageKind.isUkrainian(language)))
) {
if (skipWords-- <= 0 || i == 0) {
return before.substring(i + 1, endIndex);
return i + 1 >= endIndex ? "" : before.substring(i + 1, endIndex);
} else {
endIndex = i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.util.ArrayList;

import io.github.sspanak.tt9.db.DataStore;
import io.github.sspanak.tt9.hacks.InputType;
import io.github.sspanak.tt9.ime.helpers.TextField;
import io.github.sspanak.tt9.ime.modes.helpers.AutoSpace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public static void setDefault(SettingsStore settings) {

defaultKeys.put(SectionKeymap.ITEM_NEXT_INPUT_MODE, KeyEvent.KEYCODE_POUND);
defaultKeys.put(SectionKeymap.ITEM_NEXT_LANGUAGE, -KeyEvent.KEYCODE_POUND); // negative means "hold"
defaultKeys.put(SectionKeymap.ITEM_TAB, KeyEvent.KEYCODE_UNKNOWN);
defaultKeys.put(SectionKeymap.ITEM_SELECT_KEYBOARD, KeyEvent.KEYCODE_UNKNOWN);
defaultKeys.put(SectionKeymap.ITEM_SHOW_SETTINGS, KeyEvent.KEYCODE_UNKNOWN);
defaultKeys.put(SectionKeymap.ITEM_VOICE_INPUT, KeyEvent.KEYCODE_UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public void onCreate() {
findPreference(SectionKeymap.ITEM_NEXT_SUGGESTION),
findPreference(SectionKeymap.ITEM_NEXT_INPUT_MODE),
findPreference(SectionKeymap.ITEM_NEXT_LANGUAGE),
findPreference(SectionKeymap.ITEM_TAB),
findPreference(SectionKeymap.ITEM_SELECT_KEYBOARD),
findPreference(SectionKeymap.ITEM_SHOW_SETTINGS),
findPreference(SectionKeymap.ITEM_VOICE_INPUT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class SectionKeymap {
public static final String ITEM_NEXT_SUGGESTION = "key_next_suggestion";
public static final String ITEM_NEXT_INPUT_MODE = "key_next_input_mode";
public static final String ITEM_NEXT_LANGUAGE = "key_next_language";
public static final String ITEM_TAB = "key_tab";
public static final String ITEM_SELECT_KEYBOARD = "key_select_keyboard";
public static final String ITEM_SHOW_SETTINGS = "key_show_settings";
public static final String ITEM_VOICE_INPUT = "key_voice_input";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public int getKeyNextInputMode() {
public int getKeyNextLanguage() {
return getFunctionKey(SectionKeymap.ITEM_NEXT_LANGUAGE);
}
public int getKeyTab() {
return getFunctionKey(SectionKeymap.ITEM_TAB);
}
public int getKeySelectKeyboard() {
return getFunctionKey(SectionKeymap.ITEM_SELECT_KEYBOARD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class SettingsStore extends SettingsUI {

/************* internal settings *************/
public static final int BACKSPACE_ACCELERATION_MAX_CHARS = 20;
public static final int BACKSPACE_ACCELERATION_HARD_KEY_REPEAT_DEBOUNCE = 5;
public static final int BACKSPACE_ACCELERATION_REPEAT_DEBOUNCE = 5;
public final static int CLIPBOARD_PREVIEW_LENGTH = 20;
public final static int CUSTOM_WORDS_IMPORT_MAX_LINES = 250;
public final static int CUSTOM_WORDS_MAX = 1000;
Expand All @@ -22,7 +22,6 @@ public class SettingsStore extends SettingsUI {
public final static byte SLOW_QUERY_TIME = 50; // ms
public final static int SOFT_KEY_DOUBLE_CLICK_DELAY = 500; // ms
public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms
public final static int SOFT_KEY_BACKSPACE_ACCELERATION_REPEAT_DELAY = SOFT_KEY_REPEAT_DELAY * BACKSPACE_ACCELERATION_HARD_KEY_REPEAT_DEBOUNCE; // ms
public final static int SOFT_KEY_TITLE_SIZE = 18; // sp
public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE = 0.55f;
public final static float SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE = 0.72f;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/github/sspanak/tt9/ui/Vibration.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.main.keys.SoftKey;
import io.github.sspanak.tt9.ui.main.keys.SoftNumberKey;
import io.github.sspanak.tt9.ui.main.keys.SoftKeyNumber;

public class Vibration {
@NonNull private final SettingsStore settings;
Expand All @@ -24,7 +24,7 @@ public static int getNoVibration() {
}

public static int getPressVibration(SoftKey key) {
return key instanceof SoftNumberKey ? HapticFeedbackConstants.KEYBOARD_TAP : HapticFeedbackConstants.VIRTUAL_KEY;
return key instanceof SoftKeyNumber ? HapticFeedbackConstants.KEYBOARD_TAP : HapticFeedbackConstants.VIRTUAL_KEY;
}

public static int getHoldVibration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.hacks.DeviceInfo;
import io.github.sspanak.tt9.ime.TraditionalT9;
import io.github.sspanak.tt9.ui.main.keys.SoftCommandKey;
import io.github.sspanak.tt9.ui.main.keys.SoftKey;
import io.github.sspanak.tt9.ui.main.keys.SoftKeyFn;
import io.github.sspanak.tt9.ui.main.keys.SoftKeyNumber;
import io.github.sspanak.tt9.ui.main.keys.SoftKeyPunctuation;
import io.github.sspanak.tt9.ui.main.keys.SoftKeySettings;
import io.github.sspanak.tt9.ui.main.keys.SoftNumberKey;
import io.github.sspanak.tt9.ui.main.keys.SoftPunctuationKey;

class MainLayoutNumpad extends BaseMainLayout {
private boolean isTextEditingShown = false;
Expand Down Expand Up @@ -95,15 +95,15 @@ void showTextEditingPalette() {

if (keyId == R.id.soft_key_0) {
key.setEnabled(tt9 != null && !tt9.isInputModeNumeric());
} else if (key.getClass().equals(SoftNumberKey.class)) {
} else if (key.getClass().equals(SoftKeyNumber.class)) {
key.setVisibility(View.GONE);
}

if (key.getClass().equals(SoftPunctuationKey.class)) {
if (key.getClass().equals(SoftKeyPunctuation.class)) {
key.setVisibility(View.INVISIBLE);
}

if (key.getClass().equals(SoftCommandKey.class)) {
if (key.getClass().equals(SoftKeyFn.class)) {
key.setVisibility(View.VISIBLE);
}

Expand All @@ -127,12 +127,12 @@ void hideTextEditingPalette() {
isTextEditingShown = false;

for (SoftKey key : getKeys()) {
if (key.getClass().equals(SoftNumberKey.class) || key.getClass().equals(SoftPunctuationKey.class)) {
if (key.getClass().equals(SoftKeyNumber.class) || key.getClass().equals(SoftKeyPunctuation.class)) {
key.setVisibility(View.VISIBLE);
key.setEnabled(true);
}

if (key.getClass().equals(SoftCommandKey.class)) {
if (key.getClass().equals(SoftKeyFn.class)) {
key.setVisibility(View.GONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,11 @@ private void repeatOnLongPress() {
handleHold();
lastPressedKey = ignoreLastPressedKey ? -1 : getId();
repeatHandler.removeCallbacks(this::repeatOnLongPress);
repeatHandler.postDelayed(this::repeatOnLongPress, getLongPressRepeatDelay());
repeatHandler.postDelayed(this::repeatOnLongPress, SettingsStore.SOFT_KEY_REPEAT_DELAY);
}
}


/**
* Returns the delay between repeated calls to "handleHold()" when the SoftKey is being held.
* Used in "repeatOnLongPress()".
*/
protected int getLongPressRepeatDelay() {
return SettingsStore.SOFT_KEY_REPEAT_DELAY;
}


/**
* preventRepeat
* Prevents "handleHold()" from being called repeatedly when the SoftKey is being held.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.sspanak.tt9.ui.main.keys;

import android.content.Context;
import android.util.AttributeSet;

public class SoftKeyAddWord extends SoftKey {
public SoftKeyAddWord(Context context) { super(context); }
public SoftKeyAddWord(Context context, AttributeSet attrs) { super(context, attrs); }
public SoftKeyAddWord(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }

@Override
protected boolean handleRelease() {
if (validateTT9Handler()) {
tt9.addWord();
return true;
}

return false;
}

@Override
protected String getTitle() {
return "+";
}

@Override
public void render() {
super.render();
if (tt9 != null) {
setEnabled(!tt9.isVoiceInputActive());
}
}
}
Loading