From 7f1161218e11f3a4c6095114aac9dbdce49b2ecd Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 12 May 2024 14:09:43 +0200 Subject: [PATCH] fix some issues with key texts and icons fixes #750 --- .../helium314/keyboard/keyboard/KeyboardView.java | 12 +++++++++++- .../internal/keyboard_parser/KeyboardParser.kt | 6 +++++- .../internal/keyboard_parser/floris/TextKeyData.kt | 12 ++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java index f2bcb143..d5b38fb3 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java @@ -430,7 +430,13 @@ public class KeyboardView extends View { paint.setTextAlign(Align.CENTER); } if (key.needsAutoXScale()) { - final float ratio = Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / TypefaceUtils.getStringWidth(label, paint)); + final int width; + if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags)) { + // make sure the text stays inside bounds of background drawable + Drawable bg = key.selectBackgroundDrawable(mKeyBackground, mFunctionalKeyBackground, mSpacebarBackground, mActionKeyBackground); + width = Math.min(bg.getBounds().bottom, bg.getBounds().right); + } else width = keyWidth; + final float ratio = Math.min(1.0f, (width * MAX_LABEL_RATIO) / TypefaceUtils.getStringWidth(label, paint)); if (key.needsAutoScale()) { final float autoSize = paint.getTextSize() * ratio; paint.setTextSize(autoSize); @@ -442,6 +448,8 @@ public class KeyboardView extends View { if (key.isEnabled()) { if (StringUtils.mightBeEmoji(label)) paint.setColor(key.selectTextColor(params) | 0xFF000000); // ignore alpha for emojis (though actually color isn't applied anyway and we could just set white) + else if (key.hasActionKeyBackground()) + paint.setColor(mColors.get(ColorType.ACTION_KEY_ICON)); else paint.setColor(key.selectTextColor(params)); // Set a drop shadow for the text if the shadow radius is positive value. @@ -644,6 +652,8 @@ public class KeyboardView extends View { } else if (key.getCode() == Constants.CODE_SPACE || key.getCode() == KeyCode.ZWNJ) { // set color of default number pad space bar icon for Holo style, or for zero-width non-joiner (zwnj) on some layouts like nepal mColors.setColor(icon, ColorType.KEY_ICON); + } else { + mColors.setColor(icon, ColorType.KEY_TEXT); } } diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt index 75dda2fd..60958811 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/KeyboardParser.kt @@ -9,6 +9,7 @@ import androidx.annotation.StringRes import helium314.keyboard.keyboard.Key import helium314.keyboard.keyboard.Key.KeyParams import helium314.keyboard.keyboard.KeyboardId +import helium314.keyboard.keyboard.KeyboardTheme import helium314.keyboard.keyboard.internal.KeyboardIconsSet import helium314.keyboard.keyboard.internal.KeyboardParams import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyData @@ -315,7 +316,10 @@ abstract class KeyboardParser(private val params: KeyboardParams, private val co newLabel = "${getActionKeyLabel()}|${getActionKeyCode()}", newPopup = popup.merge(getActionKeyPopupKeys()?.let { SimplePopups(it) }), // the label change is messing with toKeyParams, so we need to supply the appropriate BG type here - newType = type ?: KeyType.ENTER_EDITING + newType = type ?: KeyType.ENTER_EDITING, + newLabelFlags = Key.LABEL_FLAGS_PRESERVE_CASE or Key.LABEL_FLAGS_AUTO_X_SCALE or + Key.LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO or Key.LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR or + Key.LABEL_FLAGS_HAS_POPUP_HINT or KeyboardTheme.getThemeActionAndEmojiKeyLabelFlags(params.mThemeId) ) else -> { // this is ugly... diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt index d1d7c2ca..77e7f997 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt @@ -251,7 +251,7 @@ sealed interface KeyData : AbstractKeyData { KeyLabel.SYMBOL_ALPHA, KeyLabel.SYMBOL, KeyLabel.ALPHA, KeyLabel.COMMA, KeyLabel.PERIOD, KeyLabel.DELETE, KeyLabel.EMOJI, KeyLabel.COM, KeyLabel.LANGUAGE_SWITCH, KeyLabel.NUMPAD -> return Key.BACKGROUND_TYPE_FUNCTIONAL KeyLabel.SPACE, KeyLabel.ZWNJ -> return Key.BACKGROUND_TYPE_SPACEBAR - KeyLabel.ACTION -> return Key.BACKGROUND_TYPE_ACTION +// KeyLabel.ACTION -> return Key.BACKGROUND_TYPE_ACTION KeyLabel.SHIFT -> return getShiftBackground(params) } if (type == KeyType.PLACEHOLDER) return Key.BACKGROUND_TYPE_EMPTY @@ -313,11 +313,11 @@ sealed interface KeyData : AbstractKeyData { return when (label) { KeyLabel.ALPHA, KeyLabel.SYMBOL_ALPHA, KeyLabel.SYMBOL -> Key.LABEL_FLAGS_PRESERVE_CASE or Key.LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR KeyLabel.PERIOD, KeyLabel.COMMA -> Key.LABEL_FLAGS_HAS_POPUP_HINT // todo: period also has defaultLabelFlags -> when is this relevant? - KeyLabel.ACTION -> { - Key.LABEL_FLAGS_PRESERVE_CASE or Key.LABEL_FLAGS_AUTO_X_SCALE or - Key.LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO or Key.LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR or - Key.LABEL_FLAGS_HAS_POPUP_HINT or KeyboardTheme.getThemeActionAndEmojiKeyLabelFlags(params.mThemeId) - } +// KeyLabel.ACTION -> { +// Key.LABEL_FLAGS_PRESERVE_CASE or Key.LABEL_FLAGS_AUTO_X_SCALE or +// Key.LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO or Key.LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR or +// Key.LABEL_FLAGS_HAS_POPUP_HINT or KeyboardTheme.getThemeActionAndEmojiKeyLabelFlags(params.mThemeId) +// } KeyLabel.SPACE -> if (params.mId.isNumberLayout) Key.LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM else 0 KeyLabel.SHIFT -> Key.LABEL_FLAGS_PRESERVE_CASE or if (!params.mId.isAlphabetKeyboard) Key.LABEL_FLAGS_FOLLOW_FUNCTIONAL_TEXT_COLOR else 0 KeyLabel.EMOJI -> KeyboardTheme.getThemeActionAndEmojiKeyLabelFlags(params.mThemeId)