Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a32803ce authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

More concise Key.toString()

Change-Id: I0ef983f54e828193e9c7e4a10c888f72702d499c
parent d427d3b0
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -467,15 +467,24 @@ public class Key implements Comparable<Key> {

    @Override
    public String toString() {
        final String label;
        if (StringUtils.codePointCount(mLabel) == 1 && mLabel.codePointAt(0) == mCode) {
            label = "";
        } else {
            label = "/" + mLabel;
        return toShortString() + " " + getX() + "," + getY() + " " + getWidth() + "x" + getHeight();
    }

    public String toShortString() {
        final int code = getCode();
        if (code == Constants.CODE_OUTPUT_TEXT) {
            return getOutputText();
        }
        return String.format(Locale.ROOT, "%s%s %d,%d %dx%d %s/%s/%s",
                Constants.printableCode(mCode), label, mX, mY, mWidth, mHeight, mHintLabel,
                KeyboardIconsSet.getIconName(mIconId), backgroundName(mBackgroundType));
        return Constants.printableCode(code);
    }

    public String toLongString() {
        final int iconId = getIconId();
        final String topVisual = (iconId == KeyboardIconsSet.ICON_UNDEFINED)
                ? KeyboardIconsSet.PREFIX_ICON + KeyboardIconsSet.getIconName(iconId) : getLabel();
        final String hintLabel = getHintLabel();
        final String visual = (hintLabel == null) ? topVisual : topVisual + "^" + hintLabel;
        return toString() + " " + visual + "/" + backgroundName(mBackgroundType);
    }

    private static String backgroundName(final int backgroundType) {
+6 −4
Original line number Diff line number Diff line
@@ -254,14 +254,16 @@ public final class Constants {
        case CODE_LANGUAGE_SWITCH: return "languageSwitch";
        case CODE_EMOJI: return "emoji";
        case CODE_SHIFT_ENTER: return "shiftEnter";
        case CODE_ALPHA_FROM_EMOJI: return "alpha";
        case CODE_UNSPECIFIED: return "unspec";
        case CODE_TAB: return "tab";
        case CODE_ENTER: return "enter";
        case CODE_ALPHA_FROM_EMOJI: return "alpha";
        case CODE_SPACE: return "space";
        default:
            if (code < CODE_SPACE) return String.format("'\\u%02x'", code);
            if (code < 0x100) return String.format("'%c'", code);
            return String.format("'\\u%04x'", code);
            if (code < CODE_SPACE) return String.format("\\u%02x", code);
            if (code < 0x100) return String.format("%c", code);
            if (code < 0x10000) return String.format("\\u04x", code);
            return String.format("\\U%05x", code);
        }
    }