android 物理键盘布局

简介: android 物理键盘布局

背景描述:


在设置中, 物理键的键盘布局是系统有提供几种选择, 当选择其中如:法语, 则,输出字符会变为对应的法语.



设置中,键盘布局列表获取:


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 1
key 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 2
key 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 3
key 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 4
key 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:                              '?'
}


相关文章
|
15天前
|
ARouter Android开发
Android不同module布局文件重名被覆盖
Android不同module布局文件重名被覆盖
|
3月前
|
移动开发 监控 前端开发
构建高效Android应用:从优化布局到提升性能
【7月更文挑战第60天】在移动开发领域,一个流畅且响应迅速的应用程序是用户留存的关键。针对Android平台,开发者面临的挑战包括多样化的设备兼容性和性能优化。本文将深入探讨如何通过改进布局设计、内存管理和多线程处理来构建高效的Android应用。我们将剖析布局优化的细节,并讨论最新的Android性能提升策略,以帮助开发者创建更快速、更流畅的用户体验。
62 10
|
24天前
|
ARouter Android开发
Android不同module布局文件重名被覆盖
Android不同module布局文件重名被覆盖
71 0
|
3月前
|
编解码 Android开发
【Android Studio】使用UI工具绘制,ConstraintLayout 限制性布局,快速上手
本文介绍了Android Studio中使用ConstraintLayout布局的方法,通过创建布局文件、设置控件约束等步骤,快速上手UI设计,并提供了一个TV Launcher界面布局的绘制示例。
49 1
|
4月前
|
Android开发 Kotlin
kotlin开发安卓app,如何让布局自适应系统传统导航和全面屏导航
使用`navigationBarsPadding()`修饰符实现界面自适应,自动处理底部导航栏的内边距,再加上`.padding(bottom = 10.dp)`设定内容与屏幕底部的距离,以完成全面的布局适配。示例代码采用Kotlin。
123 15
|
3月前
|
XML 数据可视化 API
Android经典实战之约束布局ConstraintLayout的实用技巧和经验
ConstraintLayout是Android中一款强大的布局管理器,它通过视图间的约束轻松创建复杂灵活的界面。相较于传统布局,它提供更高灵活性与性能。基本用法涉及XML定义约束,如视图与父布局对齐。此外,它支持百分比尺寸、偏移量控制等高级功能,并配有ConstraintSet和编辑器辅助设计。合理运用可显著提高布局效率及性能。
200 0
|
3月前
|
Android开发
AutoX——当Android中clickable属性显示为false,实际可点击的布局如何处理
AutoX——当Android中clickable属性显示为false,实际可点击的布局如何处理
46 0
|
4月前
|
XML Android开发 数据安全/隐私保护
使用RelativeLayout布局Android界面
使用RelativeLayout布局Android界面
|
4月前
Android-自定义流布局标签
Android-自定义流布局标签
41 0
|
4月前
|
Android开发 索引
Android流布局实现筛选界面
Android流布局实现筛选界面
52 0