From a32803cefec6b7b161b1abd88c95c2834c46be23 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 3 Jun 2014 13:30:38 +0900 Subject: [PATCH] More concise Key.toString() Change-Id: I0ef983f54e828193e9c7e4a10c888f72702d499c --- .../com/android/inputmethod/keyboard/Key.java | 25 +++++++++++++------ .../android/inputmethod/latin/Constants.java | 10 +++++--- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index cf68c565d..89a60cc1d 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -467,15 +467,24 @@ public class Key implements Comparable { @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) { diff --git a/java/src/com/android/inputmethod/latin/Constants.java b/java/src/com/android/inputmethod/latin/Constants.java index 05d34767c..35012a452 100644 --- a/java/src/com/android/inputmethod/latin/Constants.java +++ b/java/src/com/android/inputmethod/latin/Constants.java @@ -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); } }