From a9e5f879d8fe6fd9755bede14a2ba66beea5a80e Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sat, 15 Mar 2025 15:35:55 +0100 Subject: [PATCH] better way of determining whether a key should have action key background mostly relevant for popups fixes #1008 --- .../java/helium314/keyboard/keyboard/Key.java | 18 ++++++------------ .../keyboard/keyboard/KeyboardView.java | 2 +- .../keyboard/keyboard/MainKeyboardView.java | 2 +- .../keyboard/keyboard/PopupKeysKeyboard.java | 3 ++- .../keyboard/internal/PopupKeySpec.java | 8 +++----- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/Key.java b/app/src/main/java/helium314/keyboard/keyboard/Key.java index 3d0917976..c80c1eb3b 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/Key.java +++ b/app/src/main/java/helium314/keyboard/keyboard/Key.java @@ -24,6 +24,7 @@ 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 kotlin.collections.ArraysKt; import java.util.Arrays; import java.util.Locale; @@ -919,7 +920,7 @@ public class Key implements Comparable { @NonNull final Drawable spacebarBackground, @NonNull final Drawable actionKeyBackground) { final Drawable background; - if (isAccentColored()) { + if (hasActionKeyBackground()) { background = actionKeyBackground; } else if (hasFunctionalBackground()) { background = functionalKeyBackground; @@ -933,17 +934,10 @@ public class Key implements Comparable { return background; } - public final boolean isAccentColored() { - if (hasActionKeyBackground()) return true; - final String iconName = getIconName(); - if (iconName == null) return false; - // todo: other way of identifying the color? - // this should be done differently, as users can set any icon now - // how is the background drawable selected? can we use the same way? - return iconName.equals(KeyboardIconsSet.NAME_NEXT_KEY) - || iconName.equals(KeyboardIconsSet.NAME_PREVIOUS_KEY) - || iconName.equals("clipboard_action_key") - || iconName.equals("emoji_action_key"); + public final boolean hasActionKeyPopups() { + if (!hasActionKeyBackground()) return false; + // only use the special action key popups for action colored keys, and only for icon popups + return ArraysKt.none(getPopupKeys(), (key) -> key.mIconName == null); } public boolean hasFunctionalBackground() { diff --git a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java index 1c484dfbb..2226e3600 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/KeyboardView.java @@ -610,7 +610,7 @@ public class KeyboardView extends View { } private void setKeyIconColor(Key key, Drawable icon, Keyboard keyboard) { - if (key.isAccentColored()) { + if (key.hasActionKeyBackground()) { mColors.setColor(icon, ColorType.ACTION_KEY_ICON); } else if (key.isShift() && keyboard != null) { if (keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED diff --git a/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java b/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java index 9239f5ea1..91807cdbd 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/MainKeyboardView.java @@ -505,7 +505,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy mPopupKeysKeyboardCache.put(key, popupKeysKeyboard); } - final View container = key.hasActionKeyBackground() ? mPopupKeysKeyboardForActionContainer + final View container = key.hasActionKeyPopups() ? mPopupKeysKeyboardForActionContainer : mPopupKeysKeyboardContainer; final PopupKeysKeyboardView popupKeysKeyboardView = container.findViewById(R.id.popup_keys_keyboard_view); diff --git a/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboard.java b/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboard.java index 113404375..645e420bb 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboard.java +++ b/app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboard.java @@ -328,12 +328,13 @@ public final class PopupKeysKeyboard extends Keyboard { final PopupKeysKeyboardParams params = mParams; final int popupKeyFlags = mParentKey.getPopupKeyLabelFlags(); final PopupKeySpec[] popupKeys = mParentKey.getPopupKeys(); + final int background = mParentKey.hasActionKeyPopups() ? Key.BACKGROUND_TYPE_ACTION : Key.BACKGROUND_TYPE_NORMAL; for (int n = 0; n < popupKeys.length; n++) { final PopupKeySpec popupKeySpec = popupKeys[n]; final int row = n / params.mNumColumns; final int x = params.getX(n, row); final int y = params.getY(row); - final Key key = popupKeySpec.buildKey(x, y, popupKeyFlags, params); + final Key key = popupKeySpec.buildKey(x, y, popupKeyFlags, background, params); params.markAsEdgeKey(key, row); params.onAddKey(key); diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/PopupKeySpec.java b/app/src/main/java/helium314/keyboard/keyboard/internal/PopupKeySpec.java index a1b41b79c..695a660af 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/PopupKeySpec.java +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/PopupKeySpec.java @@ -68,11 +68,9 @@ public final class PopupKeySpec { } @NonNull - public Key buildKey(final int x, final int y, final int labelFlags, - @NonNull final KeyboardParams params) { - return new Key(mLabel, mIconName, mCode, mOutputText, null /* hintLabel */, labelFlags, - Key.BACKGROUND_TYPE_NORMAL, x, y, params.mDefaultAbsoluteKeyWidth, params.mDefaultAbsoluteRowHeight, - params.mHorizontalGap, params.mVerticalGap); + public Key buildKey(final int x, final int y, final int labelFlags, final int background, @NonNull final KeyboardParams params) { + return new Key(mLabel, mIconName, mCode, mOutputText, null, labelFlags, background, x, y, + params.mDefaultAbsoluteKeyWidth, params.mDefaultAbsoluteRowHeight, params.mHorizontalGap, params.mVerticalGap); } @Override