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.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<Key> {
@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<Key> {
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() {

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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