背景描述:
在设置中, 物理键的键盘布局是系统有提供几种选择, 当选择其中如:法语, 则,输出字符会变为对应的法语.
?
设置中,键盘布局列表获取:
packages/Settings/src/com/android/settings/inputmethod/KeyboardLayoutDialogFragment.java @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mInputDeviceDescriptor = getActivity().getIntent().getStringExtra( EXTRA_INPUT_DEVICE_DESCRIPTOR); if (mInputDeviceDescriptor == null) { getActivity().finish(); } mIm = (InputManager)getSystemService(Context.INPUT_SERVICE); mKeyboardLayouts = mIm.getKeyboardLayouts();//获取所有布局 Arrays.sort(mKeyboardLayouts); setPreferenceScreen(createPreferenceHierarchy()); }
2. 输入服务中的实现:
frameworks/base/services/java/com/android/server/input/InputManagerService.java private void visitAllKeyboardLayouts(KeyboardLayoutVisitor visitor) { final PackageManager pm = mContext.getPackageManager(); Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS);//关键 for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA)) { visitKeyboardLayoutsInPackage(pm, resolveInfo.activityInfo, null, visitor); } } @Override // Binder call public KeyboardLayout[] getKeyboardLayouts() { final ArrayList<KeyboardLayout> list = new ArrayList<KeyboardLayout>(); visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { @Override public void visitKeyboardLayout(Resources resources, String descriptor, String label, String collection, int keyboardLayoutResId) { list.add(new KeyboardLayout(descriptor, label, collection)); } });//主要干活的地方. return list.toArray(new KeyboardLayout[list.size()]); }
??
跟着去哪?
终于知道InputDevices是干嘛用的了....
frameworks/base/packages/InputDevices/AndroidManifest.xml<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.inputdevices" coreApp="true" android:sharedUserId="android.uid.system"> <application android:allowClearUserData="false" android:label="@string/app_label" android:process="system"> <receiver android:name=".InputDeviceReceiver" android:label="@string/keyboard_layouts_label"> <intent-filter> <action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" /><!--关键部分--> </intent-filter> <meta-data android:name="android.hardware.input.metadata.KEYBOARD_LAYOUTS" android:resource="@xml/keyboard_layouts" /><!--有必要看看这个XML--> </receiver> </application></manifest>
?
<?xml version="1.0" encoding="utf-8"?><keyboard-layouts xmlns:android="http://schemas.android.com/apk/res/android"> <keyboard-layout android:name="keyboard_layout_english_us" android:label="@string/keyboard_layout_english_us_label" android:keyboardLayout="@raw/keyboard_layout_english_us" /><!--这是啥?--> <keyboard-layout android:name="keyboard_layout_english_us_dvorak" android:label="@string/keyboard_layout_english_us_dvorak_label" android:keyboardLayout="@raw/keyboard_layout_english_us_dvorak" /> <keyboard-layout android:name="keyboard_layout_german" android:label="@string/keyboard_layout_german_label" android:keyboardLayout="@raw/keyboard_layout_german" /> <keyboard-layout android:name="keyboard_layout_french" android:label="@string/keyboard_layout_french_label" android:keyboardLayout="@raw/keyboard_layout_french" /> <keyboard-layout android:name="keyboard_layout_french_ca" android:label="@string/keyboard_layout_french_ca_label" android:keyboardLayout="@raw/keyboard_layout_french_ca" /> <keyboard-layout android:name="keyboard_layout_russian" android:label="@string/keyboard_layout_russian_label" android:keyboardLayout="@raw/keyboard_layout_russian" /> <keyboard-layout android:name="keyboard_layout_russian_mac" android:label="@string/keyboard_layout_russian_mac_label" android:keyboardLayout="@raw/keyboard_layout_russian_mac" /> <keyboard-layout android:name="keyboard_layout_spanish" android:label="@string/keyboard_layout_spanish_label" android:keyboardLayout="@raw/keyboard_layout_spanish" /> <keyboard-layout android:name="keyboard_layout_swiss_french" android:label="@string/keyboard_layout_swiss_french_label" android:keyboardLayout="@raw/keyboard_layout_swiss_french" /> <keyboard-layout android:name="keyboard_layout_swiss_german" android:label="@string/keyboard_layout_swiss_german_label" android:keyboardLayout="@raw/keyboard_layout_swiss_german" /> <keyboard-layout android:name="keyboard_layout_belgian" android:label="@string/keyboard_layout_belgian" android:keyboardLayout="@raw/keyboard_layout_belgian" /> <keyboard-layout android:name="keyboard_layout_bulgarian" android:label="@string/keyboard_layout_bulgarian" android:keyboardLayout="@raw/keyboard_layout_bulgarian" /> <keyboard-layout android:name="keyboard_layout_italian" android:label="@string/keyboard_layout_italian" android:keyboardLayout="@raw/keyboard_layout_italian" /> <keyboard-layout android:name="keyboard_layout_danish" android:label="@string/keyboard_layout_danish" android:keyboardLayout="@raw/keyboard_layout_danish" /> <keyboard-layout android:name="keyboard_layout_norwegian" android:label="@string/keyboard_layout_norwegian" android:keyboardLayout="@raw/keyboard_layout_norwegian" /> <keyboard-layout android:name="keyboard_layout_swedish" android:label="@string/keyboard_layout_swedish" android:keyboardLayout="@raw/keyboard_layout_swedish" /> <keyboard-layout android:name="keyboard_layout_finnish" android:label="@string/keyboard_layout_finnish" android:keyboardLayout="@raw/keyboard_layout_finnish" /> <keyboard-layout android:name="keyboard_layout_croatian" android:label="@string/keyboard_layout_croatian" android:keyboardLayout="@raw/keyboard_layout_croatian_and_slovenian" /> <keyboard-layout android:name="keyboard_layout_czech" android:label="@string/keyboard_layout_czech" android:keyboardLayout="@raw/keyboard_layout_czech" /> <keyboard-layout android:name="keyboard_layout_estonian" android:label="@string/keyboard_layout_estonian" android:keyboardLayout="@raw/keyboard_layout_estonian" /> <keyboard-layout android:name="keyboard_layout_hungarian" android:label="@string/keyboard_layout_hungarian" android:keyboardLayout="@raw/keyboard_layout_hungarian" /> <keyboard-layout android:name="keyboard_layout_icelandic" android:label="@string/keyboard_layout_icelandic" android:keyboardLayout="@raw/keyboard_layout_icelandic" /> <keyboard-layout android:name="keyboard_layout_portuguese" android:label="@string/keyboard_layout_portuguese" android:keyboardLayout="@raw/keyboard_layout_portuguese" /> <keyboard-layout android:name="keyboard_layout_slovak" android:label="@string/keyboard_layout_slovak" android:keyboardLayout="@raw/keyboard_layout_slovak" /> <keyboard-layout android:name="keyboard_layout_slovenian" android:label="@string/keyboard_layout_slovenian" android:keyboardLayout="@raw/keyboard_layout_croatian_and_slovenian" /> <keyboard-layout android:name="keyboard_layout_turkish" android:label="@string/keyboard_layout_turkish" android:keyboardLayout="@raw/keyboard_layout_turkish" /> <keyboard-layout android:name="keyboard_layout_ukrainian" android:label="@string/keyboard_layout_ukrainian" android:keyboardLayout="@raw/keyboard_layout_ukrainian" /></keyboard-layouts>
?
下面是一个KCM文件:
# Copyright (C) 2012 The Android Open Source Project## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.## English (US) keyboard layout.# Unlike the default (generic) keyboard layout, English (US) does not contain any# special ALT characters.#type OVERLAY### ROW 1key GRAVE { label: '`' base: '`' shift: '~'}key 1 { label: '1' base: '1' shift: '!'}key 2 { label: '2' base: '2' shift: '@'}key 3 { label: '3' base: '3' shift: '#'}key 4 { label: '4' base: '4' shift: '$'}key 5 { label: '5' base: '5' shift: '%'}key 6 { label: '6' base: '6' shift: '^'}key 7 { label: '7' base: '7' shift: '&'}key 8 { label: '8' base: '8' shift: '*'}key 9 { label: '9' base: '9' shift: '('}key 0 { label: '0' base: '0' shift: ')'}key MINUS { label: '-' base: '-' shift: '_'}key EQUALS { label: '=' base: '=' shift: '+'}### ROW 2key Q { label: 'Q' base: 'q' shift, capslock: 'Q'}key W { label: 'W' base: 'w' shift, capslock: 'W'}key E { label: 'E' base: 'e' shift, capslock: 'E'}key R { label: 'R' base: 'r' shift, capslock: 'R'}key T { label: 'T' base: 't' shift, capslock: 'T'}key Y { label: 'Y' base: 'y' shift, capslock: 'Y'}key U { label: 'U' base: 'u' shift, capslock: 'U'}key I { label: 'I' base: 'i' shift, capslock: 'I'}key O { label: 'O' base: 'o' shift, capslock: 'O'}key P { label: 'P' base: 'p' shift, capslock: 'P'}key LEFT_BRACKET { label: '[' base: '[' shift: '{'}key RIGHT_BRACKET { label: ']' base: ']' shift: '}'}key BACKSLASH { label: '\\' base: '\\' shift: '|'}### ROW 3key A { label: 'A' base: 'a' shift, capslock: 'A'}key S { label: 'S' base: 's' shift, capslock: 'S'}key D { label: 'D' base: 'd' shift, capslock: 'D'}key F { label: 'F' base: 'f' shift, capslock: 'F'}key G { label: 'G' base: 'g' shift, capslock: 'G'}key H { label: 'H' base: 'h' shift, capslock: 'H'}key J { label: 'J' base: 'j' shift, capslock: 'J'}key K { label: 'K' base: 'k' shift, capslock: 'K'}key L { label: 'L' base: 'l' shift, capslock: 'L'}key SEMICOLON { label: ';' base: ';' shift: ':'}key APOSTROPHE { label: '\'' base: '\'' shift: '"'}### ROW 4key Z { label: 'Z' base: 'z' shift, capslock: 'Z'}key X { label: 'X' base: 'x' shift, capslock: 'X'}key C { label: 'C' base: 'c' shift, capslock: 'C'}key V { label: 'V' base: 'v' shift, capslock: 'V'}key B { label: 'B' base: 'b' shift, capslock: 'B'}key N { label: 'N' base: 'n' shift, capslock: 'N'}key M { label: 'M' base: 'm' shift, capslock: 'M'}key COMMA { label: ',' base: ',' shift: '<'}key PERIOD { label: '.' base: '.' shift: '>'}key SLASH { label: '/' base: '/' shift: '?'}
?
?
?
?