code cleanup: moved the SuggestionOps to the Helpers package
This commit is contained in:
parent
bd7f33b786
commit
973b967c20
5 changed files with 23 additions and 23 deletions
|
|
@ -5,6 +5,7 @@ import android.view.View;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
|
|
||||||
|
import io.github.sspanak.tt9.ime.helpers.SuggestionOps;
|
||||||
import io.github.sspanak.tt9.ime.modes.InputMode;
|
import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||||
|
|
||||||
abstract public class AbstractHandler extends InputMethodService {
|
abstract public class AbstractHandler extends InputMethodService {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import io.github.sspanak.tt9.ime.voice.VoiceInputOps;
|
||||||
import io.github.sspanak.tt9.languages.Language;
|
import io.github.sspanak.tt9.languages.Language;
|
||||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
|
|
||||||
abstract public class MainViewOps extends HotkeyHandler {
|
abstract public class MainViewHandler extends HotkeyHandler {
|
||||||
/**** Informational methods for the on-screen keyboard ****/
|
/**** Informational methods for the on-screen keyboard ****/
|
||||||
public int getTextCase() {
|
public int getTextCase() {
|
||||||
return mInputMode.getTextCase();
|
return mInputMode.getTextCase();
|
||||||
|
|
@ -18,7 +18,7 @@ import io.github.sspanak.tt9.ui.UI;
|
||||||
import io.github.sspanak.tt9.ui.dialogs.PopupDialog;
|
import io.github.sspanak.tt9.ui.dialogs.PopupDialog;
|
||||||
import io.github.sspanak.tt9.util.Logger;
|
import io.github.sspanak.tt9.util.Logger;
|
||||||
|
|
||||||
public class TraditionalT9 extends MainViewOps {
|
public class TraditionalT9 extends MainViewHandler {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Handler normalizationHandler = new Handler(Looper.getMainLooper());
|
private final Handler normalizationHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
|
@ -105,7 +105,6 @@ public class TraditionalT9 extends MainViewOps {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInit() {
|
protected void onInit() {
|
||||||
Logger.setLevel(settings.getLogLevel());
|
Logger.setLevel(settings.getLogLevel());
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import io.github.sspanak.tt9.db.DictionaryLoader;
|
||||||
import io.github.sspanak.tt9.hacks.AppHacks;
|
import io.github.sspanak.tt9.hacks.AppHacks;
|
||||||
import io.github.sspanak.tt9.hacks.InputType;
|
import io.github.sspanak.tt9.hacks.InputType;
|
||||||
import io.github.sspanak.tt9.ime.helpers.InputModeValidator;
|
import io.github.sspanak.tt9.ime.helpers.InputModeValidator;
|
||||||
|
import io.github.sspanak.tt9.ime.helpers.SuggestionOps;
|
||||||
import io.github.sspanak.tt9.ime.helpers.TextField;
|
import io.github.sspanak.tt9.ime.helpers.TextField;
|
||||||
import io.github.sspanak.tt9.ime.modes.InputMode;
|
import io.github.sspanak.tt9.ime.modes.InputMode;
|
||||||
import io.github.sspanak.tt9.ime.modes.ModePredictive;
|
import io.github.sspanak.tt9.ime.modes.ModePredictive;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package io.github.sspanak.tt9.ime;
|
package io.github.sspanak.tt9.ime.helpers;
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
@ -8,7 +8,6 @@ import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import io.github.sspanak.tt9.ime.helpers.TextField;
|
|
||||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
import io.github.sspanak.tt9.ui.tray.SuggestionsBar;
|
import io.github.sspanak.tt9.ui.tray.SuggestionsBar;
|
||||||
import io.github.sspanak.tt9.util.ConsumerCompat;
|
import io.github.sspanak.tt9.util.ConsumerCompat;
|
||||||
|
|
@ -20,7 +19,7 @@ public class SuggestionOps {
|
||||||
@NonNull private TextField textField;
|
@NonNull private TextField textField;
|
||||||
|
|
||||||
|
|
||||||
SuggestionOps(@NonNull SettingsStore settings, View mainView, @NonNull ConsumerCompat<String> onDelayedAccept, @NonNull Runnable onSuggestionClick) {
|
public SuggestionOps(@NonNull SettingsStore settings, View mainView, @NonNull ConsumerCompat<String> onDelayedAccept, @NonNull Runnable onSuggestionClick) {
|
||||||
delayedAcceptHandler = new Handler(Looper.getMainLooper());
|
delayedAcceptHandler = new Handler(Looper.getMainLooper());
|
||||||
this.onDelayedAccept = onDelayedAccept;
|
this.onDelayedAccept = onDelayedAccept;
|
||||||
|
|
||||||
|
|
@ -29,44 +28,44 @@ public class SuggestionOps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setTextField(@NonNull TextField textField) {
|
public void setTextField(@NonNull TextField textField) {
|
||||||
this.textField = textField;
|
this.textField = textField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return suggestionBar.isEmpty();
|
return suggestionBar.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String get(int index) {
|
public String get(int index) {
|
||||||
return suggestionBar.getSuggestion(index);
|
return suggestionBar.getSuggestion(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void clear() {
|
public void clear() {
|
||||||
set(null);
|
set(null);
|
||||||
textField.setComposingText("");
|
textField.setComposingText("");
|
||||||
textField.finishComposingText();
|
textField.finishComposingText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void set(ArrayList<String> suggestions) {
|
public void set(ArrayList<String> suggestions) {
|
||||||
suggestionBar.setSuggestions(suggestions, 0);
|
suggestionBar.setSuggestions(suggestions, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void set(ArrayList<String> suggestions, int selectIndex) {
|
public void set(ArrayList<String> suggestions, int selectIndex) {
|
||||||
suggestionBar.setSuggestions(suggestions, selectIndex);
|
suggestionBar.setSuggestions(suggestions, selectIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void scrollTo(int index) {
|
public void scrollTo(int index) {
|
||||||
suggestionBar.scrollToSuggestion(index);
|
suggestionBar.scrollToSuggestion(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String acceptCurrent() {
|
public String acceptCurrent() {
|
||||||
String word = getCurrent();
|
String word = getCurrent();
|
||||||
if (!word.isEmpty()) {
|
if (!word.isEmpty()) {
|
||||||
commitCurrent(true);
|
commitCurrent(true);
|
||||||
|
|
@ -76,7 +75,7 @@ public class SuggestionOps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String acceptIncomplete() {
|
public String acceptIncomplete() {
|
||||||
String currentWord = this.getCurrent();
|
String currentWord = this.getCurrent();
|
||||||
commitCurrent(false);
|
commitCurrent(false);
|
||||||
|
|
||||||
|
|
@ -84,7 +83,7 @@ public class SuggestionOps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String acceptPrevious(int sequenceLength) {
|
public String acceptPrevious(int sequenceLength) {
|
||||||
if (sequenceLength <= 0) {
|
if (sequenceLength <= 0) {
|
||||||
set(null);
|
set(null);
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +94,7 @@ public class SuggestionOps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void commitCurrent(boolean entireSuggestion) {
|
public void commitCurrent(boolean entireSuggestion) {
|
||||||
if (!suggestionBar.isEmpty()) {
|
if (!suggestionBar.isEmpty()) {
|
||||||
if (entireSuggestion) {
|
if (entireSuggestion) {
|
||||||
textField.setComposingText(getCurrent());
|
textField.setComposingText(getCurrent());
|
||||||
|
|
@ -107,17 +106,17 @@ public class SuggestionOps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getCurrentIndex() {
|
public int getCurrentIndex() {
|
||||||
return suggestionBar.getCurrentIndex();
|
return suggestionBar.getCurrentIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String getCurrent() {
|
public String getCurrent() {
|
||||||
return get(suggestionBar.getCurrentIndex());
|
return get(suggestionBar.getCurrentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String getCurrent(int maxLength) {
|
public String getCurrent(int maxLength) {
|
||||||
if (maxLength == 0 || suggestionBar.isEmpty()) {
|
if (maxLength == 0 || suggestionBar.isEmpty()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +130,7 @@ public class SuggestionOps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean scheduleDelayedAccept(int delay) {
|
public boolean scheduleDelayedAccept(int delay) {
|
||||||
cancelDelayedAccept();
|
cancelDelayedAccept();
|
||||||
|
|
||||||
if (suggestionBar.isEmpty()) {
|
if (suggestionBar.isEmpty()) {
|
||||||
|
|
@ -149,12 +148,12 @@ public class SuggestionOps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cancelDelayedAccept() {
|
public void cancelDelayedAccept() {
|
||||||
delayedAcceptHandler.removeCallbacksAndMessages(null);
|
delayedAcceptHandler.removeCallbacksAndMessages(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setDarkTheme(boolean yes) {
|
public void setDarkTheme(boolean yes) {
|
||||||
suggestionBar.setDarkTheme(yes);
|
suggestionBar.setDarkTheme(yes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue