From 390085e4b3d99fda2457d2a0b615c61deb9f8bd2 Mon Sep 17 00:00:00 2001 From: sspanak Date: Wed, 19 Jun 2024 17:58:14 +0300 Subject: [PATCH] fixed missing virtual key labels on devices with no emoji support --- .../preferences/settings/SettingsStore.java | 7 +++-- .../tt9/ui/main/keys/SoftBackspaceKey.java | 19 +++++++----- .../tt9/ui/main/keys/SoftCommandKey.java | 16 ++++++++-- .../tt9/ui/main/keys/SoftFilterKey.java | 4 +-- .../tt9/ui/main/keys/SoftInputModeKey.java | 8 ++++- .../sspanak/tt9/ui/main/keys/SoftKey.java | 30 +++++++++++++++---- .../ui/main/keys/SoftKeyCommandPalette.java | 17 +++++++++++ .../tt9/ui/main/keys/SoftKeySettings.java | 18 +++++++++++ .../tt9/ui/main/keys/SoftNumberKey.java | 4 +-- app/src/main/res/layout/main_numpad.xml | 3 +- app/src/main/res/layout/main_small.xml | 2 +- app/src/main/res/values/strings.xml | 6 ++++ 12 files changed, 109 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKeyCommandPalette.java create mode 100644 app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKeySettings.java diff --git a/app/src/main/java/io/github/sspanak/tt9/preferences/settings/SettingsStore.java b/app/src/main/java/io/github/sspanak/tt9/preferences/settings/SettingsStore.java index a4aeadc8..1590a357 100644 --- a/app/src/main/java/io/github/sspanak/tt9/preferences/settings/SettingsStore.java +++ b/app/src/main/java/io/github/sspanak/tt9/preferences/settings/SettingsStore.java @@ -15,9 +15,10 @@ public class SettingsStore extends SettingsUI { public final static int DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME = 250; // ms public final static byte SLOW_QUERY_TIME = 50; // ms public final static int SOFT_KEY_REPEAT_DELAY = 40; // ms - public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE = 0.55f; - public final static float SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_SIZE = 0.72f; - public final static float SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_SIZE = 0.8f; + 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; + public final static float SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE = 0.8f; public final static int SUGGESTIONS_MAX = 20; public final static int SUGGESTIONS_MIN = 8; public final static int SUGGESTIONS_SELECT_ANIMATION_DURATION = 66; diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftBackspaceKey.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftBackspaceKey.java index e7a4d018..b82ef380 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftBackspaceKey.java +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftBackspaceKey.java @@ -4,8 +4,8 @@ import android.content.Context; import android.util.AttributeSet; import android.view.KeyEvent; +import io.github.sspanak.tt9.R; import io.github.sspanak.tt9.languages.LanguageKind; -import io.github.sspanak.tt9.util.Characters; public class SoftBackspaceKey extends SoftKey { @@ -44,16 +44,21 @@ public class SoftBackspaceKey extends SoftKey { return false; } + @Override + protected int getNoEmojiTitle() { + return R.string.virtual_key_del; + } + @Override protected String getTitle() { + return LanguageKind.isRTL(tt9 != null ? tt9.getLanguage() : null) ? "⌦" : "⌫"; + } + + @Override + public void render() { + super.render(); if (tt9 != null) { setEnabled(!tt9.isVoiceInputActive()); } - - if (Characters.noEmojiSupported()) { - return "Del"; - } - - return LanguageKind.isRTL(tt9 != null ? tt9.getLanguage() : null) ? "⌦" : "⌫"; } } diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftCommandKey.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftCommandKey.java index 7db77fdc..65b8197b 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftCommandKey.java +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftCommandKey.java @@ -3,6 +3,10 @@ package io.github.sspanak.tt9.ui.main.keys; import android.content.Context; import android.util.AttributeSet; +import io.github.sspanak.tt9.R; +import io.github.sspanak.tt9.preferences.settings.SettingsStore; +import io.github.sspanak.tt9.util.Characters; + public class SoftCommandKey extends SoftNumberKey { public SoftCommandKey(Context context) { super(context);} public SoftCommandKey(Context context, AttributeSet attrs) { super(context, attrs);} @@ -13,15 +17,23 @@ public class SoftCommandKey extends SoftNumberKey { return getNumber(getId()) + ""; } + + private String getTextSubTitle(int resId) { + setTextSize(SettingsStore.SOFT_KEY_TITLE_SIZE); + return getContext().getString(resId); + } + @Override protected String getSubTitle() { int number = getNumber(getId()); + boolean noIconSupport = Characters.noEmojiSupported(); + switch (number) { case 0: - return "⌨"; + return noIconSupport ? getTextSubTitle(R.string.virtual_key_change_keyboard) : "⌨"; case 1: - return "⚙"; + return noIconSupport ? getTextSubTitle(R.string.virtual_key_settings) : "⚙"; case 2: return "+"; case 3: diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftFilterKey.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftFilterKey.java index a77c22ec..638f2c1b 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftFilterKey.java +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftFilterKey.java @@ -11,8 +11,8 @@ public class SoftFilterKey extends SoftKey { public SoftFilterKey(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFontSize(); } private void setFontSize() { - complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE / 0.85f; - complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_SIZE / 0.85f; + complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE / 0.85f; + complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE / 0.85f; } @Override diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftInputModeKey.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftInputModeKey.java index b39a2dd0..65cfcbdc 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftInputModeKey.java +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftInputModeKey.java @@ -3,6 +3,8 @@ package io.github.sspanak.tt9.ui.main.keys; import android.content.Context; import android.util.AttributeSet; +import io.github.sspanak.tt9.R; + public class SoftInputModeKey extends SoftKey { public SoftInputModeKey(Context context) { super(context); @@ -28,12 +30,16 @@ public class SoftInputModeKey extends SoftKey { return false; } - @Override protected boolean handleRelease() { return validateTT9Handler() && tt9.onKeyNextInputMode(false); } + @Override + protected int getNoEmojiTitle() { + return R.string.virtual_key_input_mode; + } + @Override public void render() { super.render(); diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKey.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKey.java index 2a413f2a..b4125522 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKey.java +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKey.java @@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat; import io.github.sspanak.tt9.R; import io.github.sspanak.tt9.ime.TraditionalT9; import io.github.sspanak.tt9.preferences.settings.SettingsStore; +import io.github.sspanak.tt9.util.Characters; import io.github.sspanak.tt9.util.Logger; public class SoftKey extends androidx.appcompat.widget.AppCompatButton implements View.OnTouchListener, View.OnLongClickListener { @@ -24,8 +25,8 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement protected TraditionalT9 tt9; - protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE; - protected float complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_SIZE; + protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE; + protected float complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE; private boolean hold = false; private boolean repeat = false; @@ -179,6 +180,13 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement return null; } + /** + * getNoEmojiTitle + * Generates a text representation of the key title, when emojis are not supported and getTitle() + * is meant to return an emoji. + */ + protected int getNoEmojiTitle() { return 0; } + /** * getSubTitle * Generates a String describing what the key does. @@ -190,6 +198,18 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement return null; } + /** + * Returns a meaningful key title depending on the current emoji support. + */ + private String getTitleCompat() { + if (Characters.noEmojiSupported() && getNoEmojiTitle() > 0) { + setTextSize(SettingsStore.SOFT_KEY_TITLE_SIZE); + return getContext().getString(getNoEmojiTitle()); + } else { + return getTitle(); + } + } + /** * render * Sets the key label using "getTitle()" and "getSubtitle()" or if they both @@ -200,7 +220,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement * have their font size adjusted to fit inside the key. */ public void render() { - String title = getTitle(); + String title = getTitleCompat(); String subtitle = getSubTitle(); if (title == null) { @@ -216,8 +236,8 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement sb.append('\n'); sb.append(subtitle); - float padding = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE; - if (complexLabelTitleSize == SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_SIZE) { + float padding = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE; + if (complexLabelTitleSize == SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE) { padding /= 10; } diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKeyCommandPalette.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKeyCommandPalette.java new file mode 100644 index 00000000..3a2ff838 --- /dev/null +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKeyCommandPalette.java @@ -0,0 +1,17 @@ +package io.github.sspanak.tt9.ui.main.keys; + +import android.content.Context; +import android.util.AttributeSet; + +import io.github.sspanak.tt9.R; + +public class SoftKeyCommandPalette extends SoftKey { + public SoftKeyCommandPalette(Context context) { super(context); } + public SoftKeyCommandPalette(Context context, AttributeSet attrs) { super(context, attrs); } + public SoftKeyCommandPalette(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } + + @Override + protected int getNoEmojiTitle() { + return R.string.virtual_key_command_palette; + } +} diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKeySettings.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKeySettings.java new file mode 100644 index 00000000..3be55e6e --- /dev/null +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftKeySettings.java @@ -0,0 +1,18 @@ +package io.github.sspanak.tt9.ui.main.keys; + +import android.content.Context; +import android.util.AttributeSet; + +import io.github.sspanak.tt9.R; + +public class SoftKeySettings extends SoftKey { + public SoftKeySettings(Context context) { super(context); } + public SoftKeySettings(Context context, AttributeSet attrs) { super(context, attrs); } + public SoftKeySettings(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } + + + @Override + protected int getNoEmojiTitle() { + return R.string.virtual_key_settings; + } +} diff --git a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java index 8c6b66f8..3cd995ec 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java +++ b/app/src/main/java/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java @@ -60,10 +60,10 @@ public class SoftNumberKey extends SoftKey { int number = getNumber(getId()); if (tt9 != null && !tt9.isInputModeNumeric() && LanguageKind.isArabic(tt9.getLanguage())) { - complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_SIZE; + complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE; return tt9.getLanguage().getKeyNumber(number); } else { - complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE; + complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE; return String.valueOf(number); } } diff --git a/app/src/main/res/layout/main_numpad.xml b/app/src/main/res/layout/main_numpad.xml index b04e1992..07a9db8d 100644 --- a/app/src/main/res/layout/main_numpad.xml +++ b/app/src/main/res/layout/main_numpad.xml @@ -83,7 +83,7 @@ android:layoutDirection="ltr" tools:ignore="HardcodedText,KeyboardInaccessibleWidget"> - diff --git a/app/src/main/res/layout/main_small.xml b/app/src/main/res/layout/main_small.xml index 2efaa893..562f155f 100644 --- a/app/src/main/res/layout/main_small.xml +++ b/app/src/main/res/layout/main_small.xml @@ -43,7 +43,7 @@ android:orientation="horizontal" tools:ignore="HardcodedText,KeyboardInaccessibleWidget"> - New Line Space + Kbd + Cmd + Del + Mode + Cfg + Speak Turning off the microphone… You must allow the microphone permission to use voice input.