set correct icon when voice input key is on keyboard, but no voice input method is available

This commit is contained in:
Helium314 2024-06-14 18:59:37 +02:00
parent 5d0341195e
commit f7b12757ed
2 changed files with 18 additions and 3 deletions

View file

@ -22,6 +22,8 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.floris.PopupSet;
import helium314.keyboard.latin.common.Constants; import helium314.keyboard.latin.common.Constants;
import helium314.keyboard.latin.common.StringUtils; import helium314.keyboard.latin.common.StringUtils;
import helium314.keyboard.latin.utils.PopupKeysUtilsKt; 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.Arrays;
import java.util.Locale; import java.util.Locale;
@ -207,10 +209,11 @@ public class Key implements Comparable<Key> {
mPopupKeys = null; mPopupKeys = null;
mPopupKeysColumnAndFlags = 0; mPopupKeysColumnAndFlags = 0;
mLabel = label; mLabel = label;
mOptionalAttributes = OptionalAttributes.newInstance(outputText, KeyCode.NOT_SPECIFIED, null, 0, 0);
mCode = code; mCode = code;
mEnabled = (code != KeyCode.NOT_SPECIFIED); mEnabled = (code != KeyCode.NOT_SPECIFIED);
mIconName = iconName; 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. // Horizontal gap is divided equally to both sides of the key.
mX = x + mHorizontalGap / 2; mX = x + mHorizontalGap / 2;
mY = y; mY = y;
@ -943,6 +946,12 @@ public class Key implements Comparable<Key> {
|| mBackgroundType == BACKGROUND_TYPE_STICKY_ON; || 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 { public static class Spacer extends Key {
private Spacer(KeyParams keyParams) { private Spacer(KeyParams keyParams) {
super(keyParams); super(keyParams);
@ -1180,8 +1189,8 @@ public class Key implements Comparable<Key> {
? StringUtils.toTitleCaseOfKeyCode(altCodeInAttr, localeForUpcasing) ? StringUtils.toTitleCaseOfKeyCode(altCodeInAttr, localeForUpcasing)
: altCodeInAttr; : altCodeInAttr;
mOptionalAttributes = OptionalAttributes.newInstance(outputText, altCode, mOptionalAttributes = OptionalAttributes.newInstance(outputText, altCode,
// disabled icon only ever for old version of shortcut key, visual insets can be replaced with spacer // disabled icon only shortcut / voice key, visual insets can be replaced with spacer
null, 0, 0); mIconName == null ? null : getDisabledIconName(mIconName), 0, 0);
// KeyVisualAttributes for a key essentially are what the theme has, but on a per-key base // 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 // could be used e.g. for having a color gradient on key color
mKeyVisualAttributes = null; mKeyVisualAttributes = null;

View file

@ -24,6 +24,7 @@ import helium314.keyboard.keyboard.emoji.OnKeyEventListener;
import helium314.keyboard.keyboard.internal.KeyDrawParams; import helium314.keyboard.keyboard.internal.KeyDrawParams;
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode; import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode;
import helium314.keyboard.latin.R; import helium314.keyboard.latin.R;
import helium314.keyboard.latin.RichInputMethodManager;
import helium314.keyboard.latin.common.Constants; import helium314.keyboard.latin.common.Constants;
import helium314.keyboard.latin.common.CoordinateUtils; import helium314.keyboard.latin.common.CoordinateUtils;
@ -107,6 +108,11 @@ public class PopupKeysKeyboardView extends KeyboardView implements PopupKeysPane
} else { } else {
mAccessibilityDelegate = null; mAccessibilityDelegate = null;
} }
final Key shortcutKey = keyboard.getKey(KeyCode.VOICE_INPUT);
if (shortcutKey != null) {
shortcutKey.setEnabled(RichInputMethodManager.getInstance().isShortcutImeReady());
invalidateKey(shortcutKey);
}
} }
/** /**