From f7b12757ed3c72d3ac4cb790daa0095dceb2ab52 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Fri, 14 Jun 2024 18:59:37 +0200 Subject: [PATCH] set correct icon when voice input key is on keyboard, but no voice input method is available --- .../java/helium314/keyboard/keyboard/Key.java | 15 ++++++++++++--- .../keyboard/keyboard/PopupKeysKeyboardView.java | 6 ++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/Key.java b/app/src/main/java/helium314/keyboard/keyboard/Key.java index 5368ede70..6ba91d3cc 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Key.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Key.java @@ -22,6 +22,8 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.floris.PopupSet; import helium314.keyboard.latin.common.Constants; import helium314.keyboard.latin.common.StringUtils; import helium314.keyboard.latin.utils.PopupKeysUtilsKt; +import helium314.keyboard.latin.utils.ToolbarKey; +import helium314.keyboard.latin.utils.ToolbarUtilsKt; import java.util.Arrays; import java.util.Locale; @@ -207,10 +209,11 @@ public class Key implements Comparable { mPopupKeys = null; mPopupKeysColumnAndFlags = 0; mLabel = label; - mOptionalAttributes = OptionalAttributes.newInstance(outputText, KeyCode.NOT_SPECIFIED, null, 0, 0); mCode = code; mEnabled = (code != KeyCode.NOT_SPECIFIED); mIconName = iconName; + mOptionalAttributes = OptionalAttributes.newInstance(outputText, KeyCode.NOT_SPECIFIED, + mIconName == null ? null : getDisabledIconName(mIconName), 0, 0); // Horizontal gap is divided equally to both sides of the key. mX = x + mHorizontalGap / 2; mY = y; @@ -943,6 +946,12 @@ public class Key implements Comparable { || mBackgroundType == BACKGROUND_TYPE_STICKY_ON; } + @Nullable private static String getDisabledIconName(@NonNull final String iconName) { + if (iconName.equals(ToolbarUtilsKt.getToolbarKeyStrings().get(ToolbarKey.VOICE))) + return KeyboardIconsSet.NAME_SHORTCUT_KEY_DISABLED; + return null; + } + public static class Spacer extends Key { private Spacer(KeyParams keyParams) { super(keyParams); @@ -1180,8 +1189,8 @@ public class Key implements Comparable { ? StringUtils.toTitleCaseOfKeyCode(altCodeInAttr, localeForUpcasing) : altCodeInAttr; mOptionalAttributes = OptionalAttributes.newInstance(outputText, altCode, - // disabled icon only ever for old version of shortcut key, visual insets can be replaced with spacer - null, 0, 0); + // disabled icon only shortcut / voice key, visual insets can be replaced with spacer + mIconName == null ? null : getDisabledIconName(mIconName), 0, 0); // KeyVisualAttributes for a key essentially are what the theme has, but on a per-key base // could be used e.g. for having a color gradient on key color mKeyVisualAttributes = null; diff --git a/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboardView.java index ad642ff48..7d1735c08 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboardView.java @@ -24,6 +24,7 @@ import helium314.keyboard.keyboard.emoji.OnKeyEventListener; import helium314.keyboard.keyboard.internal.KeyDrawParams; import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode; import helium314.keyboard.latin.R; +import helium314.keyboard.latin.RichInputMethodManager; import helium314.keyboard.latin.common.Constants; import helium314.keyboard.latin.common.CoordinateUtils; @@ -107,6 +108,11 @@ public class PopupKeysKeyboardView extends KeyboardView implements PopupKeysPane } else { mAccessibilityDelegate = null; } + final Key shortcutKey = keyboard.getKey(KeyCode.VOICE_INPUT); + if (shortcutKey != null) { + shortcutKey.setEnabled(RichInputMethodManager.getInstance().isShortcutImeReady()); + invalidateKey(shortcutKey); + } } /**