From 75fb3ce1be3c879bb614097a2534f791c833dd7c Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 30 Jul 2012 15:51:41 +0900 Subject: [PATCH] More readable Key.toString() and MoreKeySpec.toString() Change-Id: Iee3c33dedd0c00ba259aa55e8b0c1c57b84eccdd --- java/src/com/android/inputmethod/keyboard/Key.java | 10 ++++++++-- .../inputmethod/keyboard/internal/KeySpecParser.java | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index e1e1ca9cf..178c9ff05 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -414,8 +414,14 @@ public class Key { @Override public String toString() { - return String.format("%s/%s %d,%d %dx%d %s/%s/%s", - Keyboard.printableCode(mCode), mLabel, mX, mY, mWidth, mHeight, mHintLabel, + final String label; + if (StringUtils.codePointCount(mLabel) == 1 && mLabel.codePointAt(0) == mCode) { + label = ""; + } else { + label = "/" + mLabel; + } + return String.format("%s%s %d,%d %dx%d %s/%s/%s", + Keyboard.printableCode(mCode), label, mX, mY, mWidth, mHeight, mHintLabel, KeyboardIconsSet.getIconName(mIconId), backgroundName(mBackgroundType)); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index 099e56182..94a7b826f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -90,8 +90,12 @@ public class KeySpecParser { final String label = (mIconId == KeyboardIconsSet.ICON_UNDEFINED ? mLabel : PREFIX_ICON + KeyboardIconsSet.getIconName(mIconId)); final String output = (mCode == Keyboard.CODE_OUTPUT_TEXT ? mOutputText - : String.format("0x%04x", mCode)); - return label + "/" + output; + : Keyboard.printableCode(mCode)); + if (StringUtils.codePointCount(label) == 1 && label.codePointAt(0) == mCode) { + return output; + } else { + return label + "|" + output; + } } }