swiping the on-screen Input Mode key switches to the previous keyboard
This commit is contained in:
parent
57d4041391
commit
c908ac1c33
3 changed files with 46 additions and 2 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package io.github.sspanak.tt9.ime;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.db.DataStore;
|
||||
import io.github.sspanak.tt9.db.words.DictionaryLoader;
|
||||
|
|
@ -9,6 +11,8 @@ import io.github.sspanak.tt9.languages.LanguageCollection;
|
|||
import io.github.sspanak.tt9.ui.UI;
|
||||
import io.github.sspanak.tt9.ui.dialogs.AddWordDialog;
|
||||
import io.github.sspanak.tt9.util.Clipboard;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
import io.github.sspanak.tt9.util.SystemSettings;
|
||||
import io.github.sspanak.tt9.util.Ternary;
|
||||
|
||||
abstract public class CommandHandler extends TextEditingHandler {
|
||||
|
|
@ -109,6 +113,23 @@ abstract public class CommandHandler extends TextEditingHandler {
|
|||
}
|
||||
|
||||
|
||||
public void nextKeyboard() {
|
||||
suggestionOps.cancelDelayedAccept();
|
||||
stopVoiceInput();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
switchToPreviousInputMethod();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
switchInputMethod(SystemSettings.getPreviousIME(this));
|
||||
} catch (Exception e) {
|
||||
Logger.d(getClass().getSimpleName(), "Could not switch to previous input method. " + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void nextInputMode() {
|
||||
if (mInputMode.isPassthrough() || voiceInputOps.isListening()) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import android.util.AttributeSet;
|
|||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
|
||||
public class SoftKeyInputMode extends SoftKey {
|
||||
public class SoftKeyInputMode extends SwipeableKey {
|
||||
public SoftKeyInputMode(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
|
@ -31,7 +31,14 @@ public class SoftKeyInputMode extends SoftKey {
|
|||
|
||||
@Override
|
||||
protected boolean handleRelease() {
|
||||
return validateTT9Handler() && tt9.onKeyNextInputMode(false);
|
||||
return notSwiped() && validateTT9Handler() && tt9.onKeyNextInputMode(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleEndSwipeX(float position, float delta) {
|
||||
if (validateTT9Handler()) {
|
||||
tt9.nextKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import android.provider.Settings;
|
|||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
|
|
@ -51,4 +53,18 @@ public class SystemSettings {
|
|||
|
||||
return country.isEmpty() ? language : language + "_" + country;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getPreviousIME(Context context) {
|
||||
inputManager = inputManager == null ? (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE) : inputManager;
|
||||
packageName = packageName == null ? context.getPackageName() : packageName;
|
||||
|
||||
for (final InputMethodInfo imeInfo : inputManager.getEnabledInputMethodList()) {
|
||||
if (!packageName.equals(imeInfo.getPackageName())) {
|
||||
return imeInfo.getId();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue