More concise Key.toString()

Change-Id: I0ef983f54e828193e9c7e4a10c888f72702d499c
This commit is contained in:
Tadashi G. Takaoka 2014-06-03 13:30:38 +09:00
parent d427d3b0fa
commit a32803cefe
2 changed files with 23 additions and 12 deletions

View file

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

View file

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