Move KeyDetector.printableCode to Keyboard

Change-Id: I9cde21fbb45c1e5f1a568bb97b1b1a76524f4bf2
This commit is contained in:
Tadashi G. Takaoka 2011-12-12 13:08:41 +09:00
parent 646a06ce25
commit 7dfd5a3e83
3 changed files with 23 additions and 10 deletions

View file

@ -222,13 +222,7 @@ public class KeyDetector {
} }
public static String printableCode(Key key) { public static String printableCode(Key key) {
return key != null ? printableCode(key.mCode) : "none"; return key != null ? Keyboard.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) { public static String printableCodes(int[] codes) {

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeyboardParams; import com.android.inputmethod.keyboard.internal.KeyboardParams;
@ -48,6 +49,8 @@ import java.util.Set;
* </pre> * </pre>
*/ */
public class Keyboard { public class Keyboard {
private static final String TAG = Keyboard.class.getSimpleName();
/** Some common keys code. These should be aligned with values/keycodes.xml */ /** Some common keys code. These should be aligned with values/keycodes.xml */
public static final int CODE_ENTER = '\n'; public static final int CODE_ENTER = '\n';
public static final int CODE_TAB = '\t'; public static final int CODE_TAB = '\t';
@ -242,4 +245,20 @@ public class Keyboard {
default: return null; default: return null;
} }
} }
public static String printableCode(int code) {
switch (code) {
case CODE_SHIFT: return "shift";
case CODE_SWITCH_ALPHA_SYMBOL: return "symbol";
case CODE_CAPSLOCK: return "capslock";
case CODE_DELETE: return "delete";
case CODE_SHORTCUT: return "shortcut";
case CODE_DUMMY: return "dummy";
case CODE_UNSPECIFIED: return "unspec";
default:
if (code < 0) Log.w(TAG, "Unknow negative key code=" + code);
if (code < 0x100) return String.format("\\u%02x", code);
return String.format("\\u04x", code);
}
}
} }

View file

@ -239,7 +239,7 @@ public class PointerTracker {
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 : " + KeyDetector.printableCode(key.mCode) Log.d(TAG, "onPress : " + KeyDetector.printableCode(key)
+ " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey + " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey
+ " enabled=" + key.isEnabled()); + " enabled=" + key.isEnabled());
} }
@ -264,7 +264,7 @@ 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: " + KeyDetector.printableCode(code) + " text=" + text Log.d(TAG, "onCodeInput: " + Keyboard.printableCode(code) + " text=" + text
+ " codes="+ KeyDetector.printableCodes(keyCodes) + " x=" + x + " y=" + y + " codes="+ KeyDetector.printableCodes(keyCodes) + " x=" + x + " y=" + y
+ " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode + " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode
+ " enabled=" + key.isEnabled()); + " enabled=" + key.isEnabled());
@ -289,7 +289,7 @@ public class PointerTracker {
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 : " + KeyDetector.printableCode(primaryCode) Log.d(TAG, "onRelease : " + Keyboard.printableCode(primaryCode)
+ " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey + " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey
+ " enabled="+ key.isEnabled()); + " enabled="+ key.isEnabled());
} }