1
0
Fork 0

fixed missing virtual key labels on devices with no emoji support

This commit is contained in:
sspanak 2024-06-19 17:58:14 +03:00 committed by Dimo Karaivanov
parent 077aac9b1a
commit 390085e4b3
12 changed files with 109 additions and 25 deletions

View file

@ -15,9 +15,10 @@ public class SettingsStore extends SettingsUI {
public final static int DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME = 250; // ms public final static int DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME = 250; // ms
public final static byte SLOW_QUERY_TIME = 50; // ms public final static byte SLOW_QUERY_TIME = 50; // ms
public final static int SOFT_KEY_REPEAT_DELAY = 40; // 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 int SOFT_KEY_TITLE_SIZE = 18; // sp
public final static float SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_SIZE = 0.72f; public final static float SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE = 0.55f;
public final static float SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_SIZE = 0.8f; 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_MAX = 20;
public final static int SUGGESTIONS_MIN = 8; public final static int SUGGESTIONS_MIN = 8;
public final static int SUGGESTIONS_SELECT_ANIMATION_DURATION = 66; public final static int SUGGESTIONS_SELECT_ANIMATION_DURATION = 66;

View file

@ -4,8 +4,8 @@ import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.KeyEvent; import android.view.KeyEvent;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.languages.LanguageKind; import io.github.sspanak.tt9.languages.LanguageKind;
import io.github.sspanak.tt9.util.Characters;
public class SoftBackspaceKey extends SoftKey { public class SoftBackspaceKey extends SoftKey {
@ -44,16 +44,21 @@ public class SoftBackspaceKey extends SoftKey {
return false; return false;
} }
@Override
protected int getNoEmojiTitle() {
return R.string.virtual_key_del;
}
@Override @Override
protected String getTitle() { protected String getTitle() {
return LanguageKind.isRTL(tt9 != null ? tt9.getLanguage() : null) ? "" : "";
}
@Override
public void render() {
super.render();
if (tt9 != null) { if (tt9 != null) {
setEnabled(!tt9.isVoiceInputActive()); setEnabled(!tt9.isVoiceInputActive());
} }
if (Characters.noEmojiSupported()) {
return "Del";
}
return LanguageKind.isRTL(tt9 != null ? tt9.getLanguage() : null) ? "" : "";
} }
} }

View file

@ -3,6 +3,10 @@ package io.github.sspanak.tt9.ui.main.keys;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; 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 class SoftCommandKey extends SoftNumberKey {
public SoftCommandKey(Context context) { super(context);} public SoftCommandKey(Context context) { super(context);}
public SoftCommandKey(Context context, AttributeSet attrs) { super(context, attrs);} public SoftCommandKey(Context context, AttributeSet attrs) { super(context, attrs);}
@ -13,15 +17,23 @@ public class SoftCommandKey extends SoftNumberKey {
return getNumber(getId()) + ""; return getNumber(getId()) + "";
} }
private String getTextSubTitle(int resId) {
setTextSize(SettingsStore.SOFT_KEY_TITLE_SIZE);
return getContext().getString(resId);
}
@Override @Override
protected String getSubTitle() { protected String getSubTitle() {
int number = getNumber(getId()); int number = getNumber(getId());
boolean noIconSupport = Characters.noEmojiSupported();
switch (number) { switch (number) {
case 0: case 0:
return ""; return noIconSupport ? getTextSubTitle(R.string.virtual_key_change_keyboard) : "";
case 1: case 1:
return ""; return noIconSupport ? getTextSubTitle(R.string.virtual_key_settings) : "";
case 2: case 2:
return ""; return "";
case 3: case 3:

View file

@ -11,8 +11,8 @@ public class SoftFilterKey extends SoftKey {
public SoftFilterKey(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFontSize(); } public SoftFilterKey(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFontSize(); }
private void setFontSize() { private void setFontSize() {
complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE / 0.85f; complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE / 0.85f;
complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_SIZE / 0.85f; complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE / 0.85f;
} }
@Override @Override

View file

@ -3,6 +3,8 @@ package io.github.sspanak.tt9.ui.main.keys;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import io.github.sspanak.tt9.R;
public class SoftInputModeKey extends SoftKey { public class SoftInputModeKey extends SoftKey {
public SoftInputModeKey(Context context) { public SoftInputModeKey(Context context) {
super(context); super(context);
@ -28,12 +30,16 @@ public class SoftInputModeKey extends SoftKey {
return false; return false;
} }
@Override @Override
protected boolean handleRelease() { protected boolean handleRelease() {
return validateTT9Handler() && tt9.onKeyNextInputMode(false); return validateTT9Handler() && tt9.onKeyNextInputMode(false);
} }
@Override
protected int getNoEmojiTitle() {
return R.string.virtual_key_input_mode;
}
@Override @Override
public void render() { public void render() {
super.render(); super.render();

View file

@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat;
import io.github.sspanak.tt9.R; import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.ime.TraditionalT9; import io.github.sspanak.tt9.ime.TraditionalT9;
import io.github.sspanak.tt9.preferences.settings.SettingsStore; import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.util.Characters;
import io.github.sspanak.tt9.util.Logger; import io.github.sspanak.tt9.util.Logger;
public class SoftKey extends androidx.appcompat.widget.AppCompatButton implements View.OnTouchListener, View.OnLongClickListener { 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 TraditionalT9 tt9;
protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE; protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
protected float complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_SIZE; protected float complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE;
private boolean hold = false; private boolean hold = false;
private boolean repeat = false; private boolean repeat = false;
@ -179,6 +180,13 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
return null; 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 * getSubTitle
* Generates a String describing what the key does. * Generates a String describing what the key does.
@ -190,6 +198,18 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
return null; 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 * 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
@ -200,7 +220,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
* have their font size adjusted to fit inside the key. * have their font size adjusted to fit inside the key.
*/ */
public void render() { public void render() {
String title = getTitle(); String title = getTitleCompat();
String subtitle = getSubTitle(); String subtitle = getSubTitle();
if (title == null) { if (title == null) {
@ -216,8 +236,8 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
sb.append('\n'); sb.append('\n');
sb.append(subtitle); sb.append(subtitle);
float padding = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE; float padding = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
if (complexLabelTitleSize == SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_SIZE) { if (complexLabelTitleSize == SettingsStore.SOFT_KEY_COMPLEX_LABEL_ARABIC_TITLE_RELATIVE_SIZE) {
padding /= 10; padding /= 10;
} }

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -60,10 +60,10 @@ public class SoftNumberKey extends SoftKey {
int number = getNumber(getId()); int number = getNumber(getId());
if (tt9 != null && !tt9.isInputModeNumeric() && LanguageKind.isArabic(tt9.getLanguage())) { 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); return tt9.getLanguage().getKeyNumber(number);
} else { } else {
complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_SIZE; complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
return String.valueOf(number); return String.valueOf(number);
} }
} }

View file

@ -83,7 +83,7 @@
android:layoutDirection="ltr" android:layoutDirection="ltr"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget"> tools:ignore="HardcodedText,KeyboardInaccessibleWidget">
<io.github.sspanak.tt9.ui.main.keys.SoftKey <io.github.sspanak.tt9.ui.main.keys.SoftKeySettings
android:id="@+id/soft_key_settings" android:id="@+id/soft_key_settings"
style="@android:style/Widget.Holo.Button.Borderless" style="@android:style/Widget.Holo.Button.Borderless"
android:layout_width="0dp" android:layout_width="0dp"
@ -131,7 +131,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="@dimen/numpad_control_key_layout_weight" android:layout_weight="@dimen/numpad_control_key_layout_weight"
android:text="⌫"
android:textSize="@dimen/soft_key_icon_size" /> android:textSize="@dimen/soft_key_icon_size" />
</LinearLayout> </LinearLayout>

View file

@ -43,7 +43,7 @@
android:orientation="horizontal" android:orientation="horizontal"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget"> tools:ignore="HardcodedText,KeyboardInaccessibleWidget">
<io.github.sspanak.tt9.ui.main.keys.SoftKey <io.github.sspanak.tt9.ui.main.keys.SoftKeyCommandPalette
android:id="@+id/soft_key_command_palette" android:id="@+id/soft_key_command_palette"
style="@android:style/Widget.Holo.Button.Borderless" style="@android:style/Widget.Holo.Button.Borderless"
android:layout_width="0dp" android:layout_width="0dp"

View file

@ -166,6 +166,12 @@
<string name="char_newline">New Line</string> <string name="char_newline">New Line</string>
<string name="char_space">Space</string> <string name="char_space">Space</string>
<string name="virtual_key_change_keyboard" translatable="false">Kbd</string>
<string name="virtual_key_command_palette" translatable="false">Cmd</string>
<string name="virtual_key_del" translatable="false">Del</string>
<string name="virtual_key_input_mode" translatable="false">Mode</string>
<string name="virtual_key_settings" translatable="false">Cfg</string>
<string name="voice_input_listening">Speak</string> <string name="voice_input_listening">Speak</string>
<string name="voice_input_stopping">Turning off the microphone…</string> <string name="voice_input_stopping">Turning off the microphone…</string>
<string name="voice_input_mic_permission_is_needed">You must allow the microphone permission to use voice input.</string> <string name="voice_input_mic_permission_is_needed">You must allow the microphone permission to use voice input.</string>