am 41a51bb2: Merge "Fix debug messages neatly"

* commit '41a51bb2b4e0cc52c84a98e7bd0e2586061eb1f4':
  Fix debug messages neatly
main
Tadashi G. Takaoka 2011-12-01 01:02:32 -08:00 committed by Android Git Automerger
commit 6fb6deb13f
2 changed files with 37 additions and 20 deletions

View File

@ -213,12 +213,31 @@ public class KeyDetector {
getNearbyKeyCodes(allCodes);
if (DEBUG) {
Log.d(TAG, "x=" + x + " y=" + y
+ " primary="
+ (primaryKey == null ? "none" : primaryKey.mCode)
+ " codes=" + Arrays.toString(allCodes));
+ " primary=" + printableCode(primaryKey)
+ " codes=" + printableCodes(allCodes));
}
}
return primaryKey;
}
public static String printableCode(Key key) {
return key != null ? printableCode(key.mCode) : "none";
}
public static String printableCode(int primaryCode) {
if (primaryCode < 0) return String.format("%4d", primaryCode);
if (primaryCode < 0x100) return String.format("\\u%02x", primaryCode);
return String.format("\\u04x", primaryCode);
}
public static String printableCodes(int[] codes) {
final StringBuilder sb = new StringBuilder();
for (final int code : codes) {
if (code == NOT_A_CODE) break;
if (sb.length() > 0) sb.append(", ");
sb.append(code);
}
return "[" + sb + "]";
}
}

View File

@ -28,7 +28,6 @@ import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PointerTracker {
@ -239,9 +238,11 @@ public class PointerTracker {
// Returns true if keyboard has been changed by this callback.
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) {
final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier();
if (DEBUG_LISTENER)
Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding
+ " ignoreModifier=" + ignoreModifierKey);
if (DEBUG_LISTENER) {
Log.d(TAG, "onPress : " + KeyDetector.printableCode(key.mCode)
+ " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey
+ " enabled=" + key.isEnabled());
}
if (ignoreModifierKey) {
return false;
}
@ -263,9 +264,10 @@ public class PointerTracker {
// If code is CODE_DUMMY here, this key will be ignored or generate text.
final CharSequence text = (code != Keyboard.CODE_DUMMY) ? null : key.mOutputText;
if (DEBUG_LISTENER) {
Log.d(TAG, "onCodeInput: " + keyCodePrintable(code) + " text=" + text
+ " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y
+ " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode);
Log.d(TAG, "onCodeInput: " + KeyDetector.printableCode(code) + " text=" + text
+ " codes="+ KeyDetector.printableCodes(keyCodes) + " x=" + x + " y=" + y
+ " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode
+ " enabled=" + key.isEnabled());
}
if (ignoreModifierKey) {
return;
@ -286,9 +288,11 @@ public class PointerTracker {
// primaryCode is different from {@link Key#mCode}.
private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) {
final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier();
if (DEBUG_LISTENER)
Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding="
+ withSliding + " ignoreModifier=" + ignoreModifierKey);
if (DEBUG_LISTENER) {
Log.d(TAG, "onRelease : " + KeyDetector.printableCode(primaryCode)
+ " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey
+ " enabled="+ key.isEnabled());
}
if (ignoreModifierKey) {
return;
}
@ -763,16 +767,10 @@ public class PointerTracker {
private void printTouchEvent(String title, int x, int y, long eventTime) {
final Key key = mKeyDetector.getKeyAndNearbyCodes(x, y, null);
final String code = (key == null) ? "----" : keyCodePrintable(key.mCode);
final String code = KeyDetector.printableCode(key);
final long delta = eventTime - mPreviousEventTime;
Log.d(TAG, String.format("%s%s[%d] %4d %4d %5d %s", title,
(mKeyAlreadyProcessed ? "-" : " "), mPointerId, x, y, delta, code));
mPreviousEventTime = eventTime;
}
private static String keyCodePrintable(int primaryCode) {
if (primaryCode < 0) return String.format("%4d", primaryCode);
if (primaryCode < 0x100) return String.format("\\u%02x", primaryCode);
return String.format("\\u04x", primaryCode);
}
}