原因是
mDigits.setKeyListener(DialerKeyListener.getInstance()); mDigits.setInputType(InputType.TYPE_CLASS_PHONE);
把这两行去掉并加上一句mDigits.setInputType(InputType.TYPE_NULL);就行了!
Phone那个拨号界面对应的是Contacts下的TwelveKeyDialer.java
本身采用的是
playTone(ToneGenerator.TONE_DTMF_1);//生音是否显示 keyPressed(KeyEvent.KEYCODE_1);//输入的数字
mHaptic.vibrate();//震动 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); mDigits.onKeyDown(keyCode, event);//keycode对应的就是KeyEvent.KEYCODE_1
keyCode对应的去取对应的值!这个值对应的在MultiTapKeyListener.java中有定义!
static { sRecs.put(KeyEvent.KEYCODE_1, ".,1!@#$%^&*:/?'=()"); sRecs.put(KeyEvent.KEYCODE_2, "abc2ABC"); sRecs.put(KeyEvent.KEYCODE_3, "def3DEF"); sRecs.put(KeyEvent.KEYCODE_4, "ghi4GHI"); sRecs.put(KeyEvent.KEYCODE_5, "jkl5JKL"); sRecs.put(KeyEvent.KEYCODE_6, "mno6MNO"); sRecs.put(KeyEvent.KEYCODE_7, "pqrs7PQRS"); sRecs.put(KeyEvent.KEYCODE_8, "tuv8TUV"); sRecs.put(KeyEvent.KEYCODE_9, "wxyz9WXYZ"); sRecs.put(KeyEvent.KEYCODE_0, "0+"); sRecs.put(KeyEvent.KEYCODE_POUND, " "); };
根据这个MultiTapKeyListener.java的注释
/** * This is the standard key listener for alphabetic input on 12-key * keyboards. You should generally not need to instantiate this yourself; * TextKeyListener will do it for you. */
说明实际是由TextKeyListener.java来控制的!
@Override public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) { KeyListener im = getKeyListener(event); return im.onKeyDown(view, content, keyCode, event); }
KeyListener 接口对应的返回实例在这里类型有两种!
private KeyListener getKeyListener(KeyEvent event) { KeyCharacterMap kmap = KeyCharacterMap.load(event.getKeyboardDevice()); int kind = kmap.getKeyboardType(); if (kind == KeyCharacterMap.ALPHA) { return QwertyKeyListener.getInstance(mAutoText, mAutoCap); } else if (kind == KeyCharacterMap.NUMERIC) { return MultiTapKeyListener.getInstance(mAutoText, mAutoCap); } return NullKeyListener.getInstance(); }
/** * Returns {@link #NUMERIC}, {@link #PREDICTIVE} or {@link #ALPHA}. */ public int getKeyboardType() { return getKeyboardType_native(mPointer); }
private static native int getKeyboardType_native(int ptr);返回NUMERIC数值类型或ALPHA希腊字母类型或PREDICTIVE这个返回的实际就是空的类型.
最后这个值是怎么取出来的列!已返回QwertyKeyListener.getInstance(mAutoText, mAutoCap);为例。
在QwertyKeyListener的onKeyDown方法中的
int i = event.getUnicodeChar(getMetaState(content));
public int getUnicodeChar(int meta) { return KeyCharacterMap.load(mDeviceId).get(mKeyCode, meta); }
private static native char get_native(int ptr, int keycode, int meta);
键布局映射文件通常放在/system/usr/keylayout和/data/usr/keylayout
对于每一个键盘设备xxx,设置系统属性android.keylayout.xxx,如果没有为自己的硬件设备创建一个特定的设备,Android将去读/system/usr/keylayout/qwerty.kl这个配置文件。
key 399 GRAVE key 2 1 key 3 2 key 4 3 key 5 4 key 6 5 key 7 6 key 8 7 key 9 8 key 10 9 key 11 0 key 158 BACK WAKE_DROPPED key 230 SOFT_RIGHT WAKE key 60 SOFT_RIGHT WAKE key 107 ENDCALL WAKE_DROPPED key 62 ENDCALL WAKE_DROPPED key 229 MENU WAKE_DROPPED key 139 MENU WAKE_DROPPED key 59 MENU WAKE_DROPPED key 127 SEARCH WAKE_DROPPED key 217 SEARCH WAKE_DROPPED key 228 POUND key 227 STAR key 231 CALL WAKE_DROPPED key 61 CALL WAKE_DROPPED key 232 DPAD_CENTER WAKE_DROPPED key 108 DPAD_DOWN WAKE_DROPPED key 103 DPAD_UP WAKE_DROPPED key 102 HOME WAKE key 105 DPAD_LEFT WAKE_DROPPED key 106 DPAD_RIGHT WAKE_DROPPED key 115 VOLUME_UP key 114 VOLUME_DOWN key 116 POWER WAKE key 212 CAMERA key 16 Q key 17 W key 18 E key 19 R key 20 T key 21 Y key 22 U key 23 I key 24 O key 25 P key 26 LEFT_BRACKET key 27 RIGHT_BRACKET key 43 BACKSLASH key 30 A key 31 S key 32 D key 33 F key 34 G key 35 H key 36 J key 37 K key 38 L key 39 SEMICOLON key 40 APOSTROPHE key 14 DEL key 44 Z key 45 X key 46 C key 47 V key 48 B key 49 N key 50 M key 51 COMMA key 52 PERIOD key 53 SLASH key 28 ENTER key 56 ALT_LEFT key 100 ALT_RIGHT key 42 SHIFT_LEFT key 54 SHIFT_RIGHT key 15 TAB key 57 SPACE key 150 EXPLORER key 155 ENVELOPE key 12 MINUS key 13 EQUALS key 215 AT