Merge "Fix debug messages neatly"

main
Tadashi G. Takaoka 2011-12-01 01:01:09 -08:00 committed by Android (Google) Code Review
commit 41a51bb2b4
2 changed files with 37 additions and 20 deletions

View File

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