better way of determining whether a key should have action key background

mostly relevant for popups
fixes #1008
This commit is contained in:
Helium314 2025-03-15 15:35:55 +01:00
parent a6b6d1b659
commit a9e5f879d8
5 changed files with 13 additions and 20 deletions

View file

@ -24,6 +24,7 @@ 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.ToolbarKey;
import helium314.keyboard.latin.utils.ToolbarUtilsKt; import helium314.keyboard.latin.utils.ToolbarUtilsKt;
import kotlin.collections.ArraysKt;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
@ -919,7 +920,7 @@ public class Key implements Comparable<Key> {
@NonNull final Drawable spacebarBackground, @NonNull final Drawable spacebarBackground,
@NonNull final Drawable actionKeyBackground) { @NonNull final Drawable actionKeyBackground) {
final Drawable background; final Drawable background;
if (isAccentColored()) { if (hasActionKeyBackground()) {
background = actionKeyBackground; background = actionKeyBackground;
} else if (hasFunctionalBackground()) { } else if (hasFunctionalBackground()) {
background = functionalKeyBackground; background = functionalKeyBackground;
@ -933,17 +934,10 @@ public class Key implements Comparable<Key> {
return background; return background;
} }
public final boolean isAccentColored() { public final boolean hasActionKeyPopups() {
if (hasActionKeyBackground()) return true; if (!hasActionKeyBackground()) return false;
final String iconName = getIconName(); // only use the special action key popups for action colored keys, and only for icon popups
if (iconName == null) return false; return ArraysKt.none(getPopupKeys(), (key) -> key.mIconName == null);
// 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 boolean hasFunctionalBackground() { public boolean hasFunctionalBackground() {

View file

@ -610,7 +610,7 @@ public class KeyboardView extends View {
} }
private void setKeyIconColor(Key key, Drawable icon, Keyboard keyboard) { private void setKeyIconColor(Key key, Drawable icon, Keyboard keyboard) {
if (key.isAccentColored()) { if (key.hasActionKeyBackground()) {
mColors.setColor(icon, ColorType.ACTION_KEY_ICON); mColors.setColor(icon, ColorType.ACTION_KEY_ICON);
} else if (key.isShift() && keyboard != null) { } else if (key.isShift() && keyboard != null) {
if (keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED if (keyboard.mId.mElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED

View file

@ -505,7 +505,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
mPopupKeysKeyboardCache.put(key, popupKeysKeyboard); mPopupKeysKeyboardCache.put(key, popupKeysKeyboard);
} }
final View container = key.hasActionKeyBackground() ? mPopupKeysKeyboardForActionContainer final View container = key.hasActionKeyPopups() ? mPopupKeysKeyboardForActionContainer
: mPopupKeysKeyboardContainer; : mPopupKeysKeyboardContainer;
final PopupKeysKeyboardView popupKeysKeyboardView = final PopupKeysKeyboardView popupKeysKeyboardView =
container.findViewById(R.id.popup_keys_keyboard_view); container.findViewById(R.id.popup_keys_keyboard_view);

View file

@ -328,12 +328,13 @@ public final class PopupKeysKeyboard extends Keyboard {
final PopupKeysKeyboardParams params = mParams; final PopupKeysKeyboardParams params = mParams;
final int popupKeyFlags = mParentKey.getPopupKeyLabelFlags(); final int popupKeyFlags = mParentKey.getPopupKeyLabelFlags();
final PopupKeySpec[] popupKeys = mParentKey.getPopupKeys(); 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++) { for (int n = 0; n < popupKeys.length; n++) {
final PopupKeySpec popupKeySpec = popupKeys[n]; final PopupKeySpec popupKeySpec = popupKeys[n];
final int row = n / params.mNumColumns; final int row = n / params.mNumColumns;
final int x = params.getX(n, row); final int x = params.getX(n, row);
final int y = params.getY(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.markAsEdgeKey(key, row);
params.onAddKey(key); params.onAddKey(key);

View file

@ -68,11 +68,9 @@ public final class PopupKeySpec {
} }
@NonNull @NonNull
public Key buildKey(final int x, final int y, final int labelFlags, public Key buildKey(final int x, final int y, final int labelFlags, final int background, @NonNull final KeyboardParams params) {
@NonNull final KeyboardParams params) { return new Key(mLabel, mIconName, mCode, mOutputText, null, labelFlags, background, x, y,
return new Key(mLabel, mIconName, mCode, mOutputText, null /* hintLabel */, labelFlags, params.mDefaultAbsoluteKeyWidth, params.mDefaultAbsoluteRowHeight, params.mHorizontalGap, params.mVerticalGap);
Key.BACKGROUND_TYPE_NORMAL, x, y, params.mDefaultAbsoluteKeyWidth, params.mDefaultAbsoluteRowHeight,
params.mHorizontalGap, params.mVerticalGap);
} }
@Override @Override