am a32803ce: More concise Key.toString()

* commit 'a32803cefec6b7b161b1abd88c95c2834c46be23':
  More concise Key.toString()
main
Tadashi G. Takaoka 2014-06-03 05:34:09 +00:00 committed by Android Git Automerger
commit 1982726cc5
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);
}
}