Skip to content

Commit

Permalink
allow customizing text on space bar
Browse files Browse the repository at this point in the history
fixes #956
fixes openboard-team#875 (set text to space)
  • Loading branch information
Helium314 committed Aug 28, 2024
1 parent 4ddfd2d commit 8ca65ae
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ public void updateShortcutKey(final boolean available) {
invalidateKey(shortcutKey);
}

// the whole language on spacebar thing could probably be simplified quite a bit
public void startDisplayLanguageOnSpacebar(final boolean subtypeChanged,
final int languageOnSpacebarFormatType,
final boolean hasMultipleEnabledIMEsOrSubtypes) {
Expand Down Expand Up @@ -799,13 +800,16 @@ private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Pa
paint.setTextAlign(Align.CENTER);
paint.setTypeface(Typeface.DEFAULT);
paint.setTextSize(mLanguageOnSpacebarTextSize);
final String languageText;
if (DebugFlags.DEBUG_ENABLED) {
final String customText = Settings.getInstance().getCurrent().mSpaceBarText;
final String spaceText;
if (!customText.isEmpty()) {
spaceText = customText;
} else if (DebugFlags.DEBUG_ENABLED) {
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
languageText = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width);
spaceText = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width);
// Draw language text with shadow
final float descent = paint.descent();
final float textHeight = -paint.ascent() + descent;
Expand All @@ -818,7 +822,11 @@ private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Pa
}
paint.setColor(mLanguageOnSpacebarTextColor);
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.setTextScaleX(1.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_SYMBOL_SPACE = "abc_after_symbol_space";
public static final String PREF_REMOVE_REDUNDANT_POPUPS = "remove_redundant_popups";
public static final String PREF_SPACE_BAR_TEXT = "space_bar_text";

// Emoji
public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class SettingsValues {
public final boolean mAlphaAfterClipHistoryEntry;
public final boolean mAlphaAfterSymbolAndSpace;
public final boolean mRemoveRedundantPopups;
public final String mSpaceBarText;

// From the input box
@NonNull
Expand Down Expand Up @@ -264,6 +265,7 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
mAlphaAfterClipHistoryEntry = prefs.getBoolean(Settings.PREF_ABC_AFTER_CLIP, false);
mAlphaAfterSymbolAndSpace = prefs.getBoolean(Settings.PREF_ABC_AFTER_SYMBOL_SPACE, true);
mRemoveRedundantPopups = prefs.getBoolean(Settings.PREF_REMOVE_REDUNDANT_POPUPS, true);
mSpaceBarText = prefs.getString(Settings.PREF_SPACE_BAR_TEXT, "");
}

public boolean isApplicationSpecifiedCompletionsOn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ private LanguageOnSpacebarUtils() {
// This utility class is not publicly instantiable.
}

public static int getLanguageOnSpacebarFormatType(
@NonNull final RichInputMethodSubtype subtype) {
public static int getLanguageOnSpacebarFormatType(@NonNull final RichInputMethodSubtype subtype) {
if (!Settings.getInstance().getCurrent().mSpaceBarText.isEmpty())
return FORMAT_TYPE_FULL_LOCALE;
if (subtype.isNoLanguage()) {
return FORMAT_TYPE_FULL_LOCALE;
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@
<string name="prefs_keyboard_height_scale">Keyboard height scale</string>
<!-- Title of the setting for setting bottom padding height -->
<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]
(UK) should be an abbreviation of United Kingdom to fit in the CHAR LIMIT. -->
<string name="subtype_en_GB">English (UK)</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/prefs_screen_appearance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
latin:minValue="0"
latin:maxValue="500" /> <!-- percentage -->

<EditTextPreference
android:key="space_bar_text"
android:title="@string/prefs_space_bar_text"
android:defaultValue=""
android:persistent="true" />

</PreferenceCategory>

</PreferenceScreen>

0 comments on commit 8ca65ae

Please sign in to comment.