inactive virtual keys are now properly displayed as disabled
This commit is contained in:
parent
0a1aed88d5
commit
077aac9b1a
11 changed files with 110 additions and 8 deletions
|
|
@ -70,7 +70,7 @@ abstract public class CommandHandler extends VoiceHandler {
|
||||||
|
|
||||||
|
|
||||||
public void addWord() {
|
public void addWord() {
|
||||||
if (mInputMode.isNumeric() || voiceInputOps.isListening()) {
|
if (voiceInputOps.isListening()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package io.github.sspanak.tt9.ime;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import io.github.sspanak.tt9.ime.modes.ModeABC;
|
||||||
import io.github.sspanak.tt9.ime.voice.VoiceInputOps;
|
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;
|
||||||
|
|
@ -12,6 +13,10 @@ abstract public class MainViewHandler extends HotkeyHandler {
|
||||||
return mInputMode.getTextCase();
|
return mInputMode.getTextCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isInputModeABC() {
|
||||||
|
return mInputMode.getClass().equals(ModeABC.class);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInputModeNumeric() {
|
public boolean isInputModeNumeric() {
|
||||||
return mInputMode.is123();
|
return mInputMode.is123();
|
||||||
}
|
}
|
||||||
|
|
@ -28,6 +33,10 @@ abstract public class MainViewHandler extends HotkeyHandler {
|
||||||
return mInputMode.is123() && inputType.isPhoneNumber();
|
return mInputMode.is123() && inputType.isPhoneNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isVoiceInputActive() {
|
||||||
|
return voiceInputOps != null && voiceInputOps.isListening();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isVoiceInputMissing() {
|
public boolean isVoiceInputMissing() {
|
||||||
return !(new VoiceInputOps(this, null, null, null)).isAvailable();
|
return !(new VoiceInputOps(this, null, null, null)).isAvailable();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@ abstract class VoiceHandler extends TypingHandler {
|
||||||
|
|
||||||
|
|
||||||
private void onVoiceInputStarted() {
|
private void onVoiceInputStarted() {
|
||||||
|
if (!mainView.isCommandPaletteShown()) {
|
||||||
|
mainView.render(); // disable the function keys
|
||||||
|
}
|
||||||
statusBar.setText(voiceInputOps);
|
statusBar.setText(voiceInputOps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,13 +67,16 @@ abstract class VoiceHandler extends TypingHandler {
|
||||||
private void onVoiceInputStopped(String text) {
|
private void onVoiceInputStopped(String text) {
|
||||||
onText(text, false);
|
onText(text, false);
|
||||||
resetStatus();
|
resetStatus();
|
||||||
|
if (!mainView.isCommandPaletteShown()) {
|
||||||
|
mainView.render(); // re-enable the function keys
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void onVoiceInputError(VoiceInputError error) {
|
private void onVoiceInputError(VoiceInputError error) {
|
||||||
if (error.isIrrelevantToUser()) {
|
if (error.isIrrelevantToUser()) {
|
||||||
Logger.i(LOG_TAG, "Ignoring voice input. " + error.debugMessage);
|
Logger.i(LOG_TAG, "Ignoring voice input. " + error.debugMessage);
|
||||||
resetStatus();
|
resetStatus(); // re-enable the function keys
|
||||||
} else {
|
} else {
|
||||||
Logger.e(LOG_TAG, "Failed to listen. " + error.debugMessage);
|
Logger.e(LOG_TAG, "Failed to listen. " + error.debugMessage);
|
||||||
statusBar.setError(error.toString());
|
statusBar.setError(error.toString());
|
||||||
|
|
@ -78,5 +84,9 @@ abstract class VoiceHandler extends TypingHandler {
|
||||||
RequestPermissionDialog.show(this);
|
RequestPermissionDialog.show(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mainView.isCommandPaletteShown()) {
|
||||||
|
mainView.render(); // re-enable the function keys
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,14 @@ public class SoftBackspaceKey extends SoftKey {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle() {
|
protected String getTitle() {
|
||||||
|
if (tt9 != null) {
|
||||||
|
setEnabled(!tt9.isVoiceInputActive());
|
||||||
|
}
|
||||||
|
|
||||||
if (Characters.noEmojiSupported()) {
|
if (Characters.noEmojiSupported()) {
|
||||||
return "Del";
|
return "Del";
|
||||||
}
|
}
|
||||||
|
|
||||||
return LanguageKind.isRTL(tt9.getLanguage()) ? "⌦" : "⌫";
|
return LanguageKind.isRTL(tt9 != null ? tt9.getLanguage() : null) ? "⌦" : "⌫";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,4 +39,13 @@ public class SoftFilterKey extends SoftKey {
|
||||||
protected String getSubTitle() {
|
protected String getSubTitle() {
|
||||||
return "FLTR";
|
return "FLTR";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
super.render();
|
||||||
|
if (tt9 != null) {
|
||||||
|
setEnabled(!tt9.isInputModeNumeric() && !tt9.isInputModeABC() && !tt9.isVoiceInputActive());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,12 @@ public class SoftInputModeKey extends SoftKey {
|
||||||
protected boolean handleRelease() {
|
protected boolean handleRelease() {
|
||||||
return validateTT9Handler() && tt9.onKeyNextInputMode(false);
|
return validateTT9Handler() && tt9.onKeyNextInputMode(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
super.render();
|
||||||
|
if (tt9 != null) {
|
||||||
|
setEnabled(!tt9.isVoiceInputActive());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,9 +149,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
||||||
|
|
||||||
int keyId = getId();
|
int keyId = getId();
|
||||||
|
|
||||||
if (keyId == R.id.soft_key_add_word) { tt9.addWord(); return true; }
|
|
||||||
if (keyId == R.id.soft_key_command_palette) return tt9.onKeyCommandPalette(false);
|
if (keyId == R.id.soft_key_command_palette) return tt9.onKeyCommandPalette(false);
|
||||||
if (keyId == R.id.soft_key_language) return tt9.onKeyNextLanguage(false);
|
|
||||||
if (keyId == R.id.soft_key_settings) { tt9.showSettings(); return true; }
|
if (keyId == R.id.soft_key_settings) { tt9.showSettings(); return true; }
|
||||||
if (keyId == R.id.soft_key_voice_input) { tt9.toggleVoiceInput(); return true; }
|
if (keyId == R.id.soft_key_voice_input) { tt9.toggleVoiceInput(); return true; }
|
||||||
|
|
||||||
|
|
@ -167,6 +165,12 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
super.setEnabled(enabled);
|
||||||
|
setTextColor(getTextColors().withAlpha(enabled ? 255 : 80));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getTitle
|
* getTitle
|
||||||
* Generates the name of the key, for example: "OK", "Backspace", "1", etc...
|
* Generates the name of the key, for example: "OK", "Backspace", "1", etc...
|
||||||
|
|
@ -186,7 +190,6 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* render
|
* render
|
||||||
* Sets the key label using "getTitle()" and "getSubtitle()" or if they both
|
* Sets the key label using "getTitle()" and "getSubtitle()" or if they both
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
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
|
||||||
|
public void render() {
|
||||||
|
super.render();
|
||||||
|
if (tt9 != null) {
|
||||||
|
setEnabled(!tt9.isVoiceInputActive());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package io.github.sspanak.tt9.ui.main.keys;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class SoftKeyNextLanguage extends SoftKey {
|
||||||
|
public SoftKeyNextLanguage(Context context) { super(context); }
|
||||||
|
public SoftKeyNextLanguage(Context context, AttributeSet attrs) { super(context, attrs); }
|
||||||
|
public SoftKeyNextLanguage(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean handleRelease() {
|
||||||
|
return validateTT9Handler() && tt9.onKeyNextLanguage(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
super.render();
|
||||||
|
if (tt9 != null) {
|
||||||
|
setEnabled(!tt9.isInputModeNumeric() && !tt9.isVoiceInputActive());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -29,4 +29,13 @@ public class SoftOkKey extends SoftKey {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
super.render();
|
||||||
|
if (tt9 != null) {
|
||||||
|
setEnabled(!tt9.isVoiceInputActive());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@
|
||||||
android:layoutDirection="ltr"
|
android:layoutDirection="ltr"
|
||||||
tools:ignore="HardcodedText">
|
tools:ignore="HardcodedText">
|
||||||
|
|
||||||
<io.github.sspanak.tt9.ui.main.keys.SoftKey
|
<io.github.sspanak.tt9.ui.main.keys.SoftKeyAddWord
|
||||||
android:id="@+id/soft_key_add_word"
|
android:id="@+id/soft_key_add_word"
|
||||||
style="@android:style/Widget.Holo.Button.Borderless"
|
style="@android:style/Widget.Holo.Button.Borderless"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
@ -260,7 +260,7 @@
|
||||||
android:layoutDirection="ltr"
|
android:layoutDirection="ltr"
|
||||||
tools:ignore="HardcodedText">
|
tools:ignore="HardcodedText">
|
||||||
|
|
||||||
<io.github.sspanak.tt9.ui.main.keys.SoftKey
|
<io.github.sspanak.tt9.ui.main.keys.SoftKeyNextLanguage
|
||||||
android:id="@+id/soft_key_language"
|
android:id="@+id/soft_key_language"
|
||||||
style="@android:style/Widget.Holo.Button.Borderless"
|
style="@android:style/Widget.Holo.Button.Borderless"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue