From 7dfd5a3e833e14d5bf90d728d5a50b40c8a927d2 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 12 Dec 2011 13:08:41 +0900 Subject: [PATCH] Move KeyDetector.printableCode to Keyboard Change-Id: I9cde21fbb45c1e5f1a568bb97b1b1a76524f4bf2 --- .../inputmethod/keyboard/KeyDetector.java | 8 +------- .../inputmethod/keyboard/Keyboard.java | 19 +++++++++++++++++++ .../inputmethod/keyboard/PointerTracker.java | 6 +++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index 2a6e0a2de..8e325b65c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -222,13 +222,7 @@ public class KeyDetector { } 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); + return key != null ? Keyboard.printableCode(key.mCode) : "none"; } public static String printableCodes(int[] codes) { diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 2bc140ed5..7cbf66543 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard; import android.graphics.drawable.Drawable; import android.text.TextUtils; +import android.util.Log; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardParams; @@ -48,6 +49,8 @@ import java.util.Set; * */ public class Keyboard { + private static final String TAG = Keyboard.class.getSimpleName(); + /** Some common keys code. These should be aligned with values/keycodes.xml */ public static final int CODE_ENTER = '\n'; public static final int CODE_TAB = '\t'; @@ -242,4 +245,20 @@ public class Keyboard { 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); + } + } } diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 9e0c5ce02..3a07cdf4d 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -239,7 +239,7 @@ public class PointerTracker { private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) { final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier(); if (DEBUG_LISTENER) { - Log.d(TAG, "onPress : " + KeyDetector.printableCode(key.mCode) + Log.d(TAG, "onPress : " + KeyDetector.printableCode(key) + " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey + " enabled=" + key.isEnabled()); } @@ -264,7 +264,7 @@ 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: " + KeyDetector.printableCode(code) + " text=" + text + Log.d(TAG, "onCodeInput: " + Keyboard.printableCode(code) + " text=" + text + " codes="+ KeyDetector.printableCodes(keyCodes) + " x=" + x + " y=" + y + " ignoreModifier=" + ignoreModifierKey + " alterCode=" + alterCode + " enabled=" + key.isEnabled()); @@ -289,7 +289,7 @@ public class PointerTracker { private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) { final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier(); if (DEBUG_LISTENER) { - Log.d(TAG, "onRelease : " + KeyDetector.printableCode(primaryCode) + Log.d(TAG, "onRelease : " + Keyboard.printableCode(primaryCode) + " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey + " enabled="+ key.isEnabled()); }