allow customizing text on space bar

fixes #956
fixes #875 (set text to space)
This commit is contained in:
Helium314 2024-08-28 22:08:00 +02:00
parent 4ddfd2d5a9
commit 8ca65aebc9
6 changed files with 27 additions and 7 deletions

View file

@ -659,6 +659,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
invalidateKey(shortcutKey); invalidateKey(shortcutKey);
} }
// the whole language on spacebar thing could probably be simplified quite a bit
public void startDisplayLanguageOnSpacebar(final boolean subtypeChanged, public void startDisplayLanguageOnSpacebar(final boolean subtypeChanged,
final int languageOnSpacebarFormatType, final int languageOnSpacebarFormatType,
final boolean hasMultipleEnabledIMEsOrSubtypes) { final boolean hasMultipleEnabledIMEsOrSubtypes) {
@ -799,13 +800,16 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
paint.setTypeface(Typeface.DEFAULT); paint.setTypeface(Typeface.DEFAULT);
paint.setTextSize(mLanguageOnSpacebarTextSize); paint.setTextSize(mLanguageOnSpacebarTextSize);
final String languageText; final String customText = Settings.getInstance().getCurrent().mSpaceBarText;
if (DebugFlags.DEBUG_ENABLED) { final String spaceText;
if (!customText.isEmpty()) {
spaceText = customText;
} else if (DebugFlags.DEBUG_ENABLED) {
final String l = KeyboardSwitcher.getInstance().getLocaleAndConfidenceInfo(); final String l = KeyboardSwitcher.getInstance().getLocaleAndConfidenceInfo();
languageText = l != null ? l : layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width); spaceText = l != null ? l : layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width);
} }
else else
languageText = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width); spaceText = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width);
// Draw language text with shadow // Draw language text with shadow
final float descent = paint.descent(); final float descent = paint.descent();
final float textHeight = -paint.ascent() + descent; final float textHeight = -paint.ascent() + descent;
@ -818,7 +822,11 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
} }
paint.setColor(mLanguageOnSpacebarTextColor); paint.setColor(mLanguageOnSpacebarTextColor);
paint.setAlpha(mLanguageOnSpacebarAnimAlpha); paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
canvas.drawText(languageText, width / 2f, baseline - descent, paint); if (!fitsTextIntoWidth(width, spaceText, paint)) {
final float textWidth = TypefaceUtils.getStringWidth(spaceText, paint);
paint.setTextScaleX((width - mLanguageOnSpacebarHorizontalMargin * 2) / textWidth);
}
canvas.drawText(spaceText, width / 2f, baseline - descent, paint);
paint.clearShadowLayer(); paint.clearShadowLayer();
paint.setTextScaleX(1.0f); paint.setTextScaleX(1.0f);
} }

View file

@ -164,6 +164,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_ABC_AFTER_CLIP = "abc_after_clip"; public static final String PREF_ABC_AFTER_CLIP = "abc_after_clip";
public static final String PREF_ABC_AFTER_SYMBOL_SPACE = "abc_after_symbol_space"; public static final String PREF_ABC_AFTER_SYMBOL_SPACE = "abc_after_symbol_space";
public static final String PREF_REMOVE_REDUNDANT_POPUPS = "remove_redundant_popups"; public static final String PREF_REMOVE_REDUNDANT_POPUPS = "remove_redundant_popups";
public static final String PREF_SPACE_BAR_TEXT = "space_bar_text";
// Emoji // Emoji
public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys"; public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys";

View file

@ -117,6 +117,7 @@ public class SettingsValues {
public final boolean mAlphaAfterClipHistoryEntry; public final boolean mAlphaAfterClipHistoryEntry;
public final boolean mAlphaAfterSymbolAndSpace; public final boolean mAlphaAfterSymbolAndSpace;
public final boolean mRemoveRedundantPopups; public final boolean mRemoveRedundantPopups;
public final String mSpaceBarText;
// From the input box // From the input box
@NonNull @NonNull
@ -264,6 +265,7 @@ public class SettingsValues {
mAlphaAfterClipHistoryEntry = prefs.getBoolean(Settings.PREF_ABC_AFTER_CLIP, false); mAlphaAfterClipHistoryEntry = prefs.getBoolean(Settings.PREF_ABC_AFTER_CLIP, false);
mAlphaAfterSymbolAndSpace = prefs.getBoolean(Settings.PREF_ABC_AFTER_SYMBOL_SPACE, true); mAlphaAfterSymbolAndSpace = prefs.getBoolean(Settings.PREF_ABC_AFTER_SYMBOL_SPACE, true);
mRemoveRedundantPopups = prefs.getBoolean(Settings.PREF_REMOVE_REDUNDANT_POPUPS, true); mRemoveRedundantPopups = prefs.getBoolean(Settings.PREF_REMOVE_REDUNDANT_POPUPS, true);
mSpaceBarText = prefs.getString(Settings.PREF_SPACE_BAR_TEXT, "");
} }
public boolean isApplicationSpecifiedCompletionsOn() { public boolean isApplicationSpecifiedCompletionsOn() {

View file

@ -32,8 +32,9 @@ public final class LanguageOnSpacebarUtils {
// This utility class is not publicly instantiable. // This utility class is not publicly instantiable.
} }
public static int getLanguageOnSpacebarFormatType( public static int getLanguageOnSpacebarFormatType(@NonNull final RichInputMethodSubtype subtype) {
@NonNull final RichInputMethodSubtype subtype) { if (!Settings.getInstance().getCurrent().mSpaceBarText.isEmpty())
return FORMAT_TYPE_FULL_LOCALE;
if (subtype.isNoLanguage()) { if (subtype.isNoLanguage()) {
return FORMAT_TYPE_FULL_LOCALE; return FORMAT_TYPE_FULL_LOCALE;
} }

View file

@ -305,6 +305,8 @@
<string name="prefs_keyboard_height_scale">Keyboard height scale</string> <string name="prefs_keyboard_height_scale">Keyboard height scale</string>
<!-- Title of the setting for setting bottom padding height --> <!-- Title of the setting for setting bottom padding height -->
<string name="prefs_bottom_padding_scale">Bottom padding scale</string> <string name="prefs_bottom_padding_scale">Bottom padding scale</string>
<!-- Title of the setting for customizing space bar text -->
<string name="prefs_space_bar_text">Custom text on space bar</string>
<!-- Description for English (UK) keyboard subtype [CHAR LIMIT=25] <!-- Description for English (UK) keyboard subtype [CHAR LIMIT=25]
(UK) should be an abbreviation of United Kingdom to fit in the CHAR LIMIT. --> (UK) should be an abbreviation of United Kingdom to fit in the CHAR LIMIT. -->
<string name="subtype_en_GB">English (UK)</string> <string name="subtype_en_GB">English (UK)</string>

View file

@ -101,6 +101,12 @@
latin:minValue="0" latin:minValue="0"
latin:maxValue="500" /> <!-- percentage --> latin:maxValue="500" /> <!-- percentage -->
<EditTextPreference
android:key="space_bar_text"
android:title="@string/prefs_space_bar_text"
android:defaultValue=""
android:persistent="true" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>