| <html devsite><head> |
| <title>触控笔</title> |
| <meta name="project_path" value="/_project.yaml"/> |
| <meta name="book_path" value="/_book.yaml"/> |
| </head> |
| <body> |
| <!-- |
| Copyright 2017 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. |
| --> |
| |
| <p>Android 6.0 及更高版本支持蓝牙 (BT)、蓝牙低功耗 (BTLE) 或 USB 协议的蓝牙触控笔连接适用的标准数据格式。平台会分析触摸输入和触控笔数据之间的时间关系并进行关联,然后提供触控笔数据,以便在前台应用中呈现 MotionEvent。下面几节提供的指南适用于原始设备制造商 (OEM) 设备实现者、触控笔配件制造者和触控笔应用开发者。</p> |
| |
| <h2 id="guide-partners">面向 OEM 设备实现者的指南</h2> |
| <p>要启用蓝牙触控笔支持,OEM 设备实现者必须支持蓝牙(并且应支持 BTLE 以实现更广泛的兼容性)。平台会针对支持的触控笔事件处理数据收集、时间关联操作,以及应用呈现。</p> |
| |
| <p>目前,Android CTS <strong>不</strong>包括相关测试来确保现有触摸事件 API 支持默认行为。要解决此问题,我们建议您构建触控笔配件或可模拟触控笔事件的模拟器。</p> |
| |
| <h2 id="guide-creators">面向触控笔配件制造者的指南</h2> |
| <p>要在触控笔设备上实现支持,设备实现者必须使用下方所示的触控笔人机接口设备 (HID) 描述符,来描述触控笔数据(压力感应、橡皮擦、侧边按钮、设备 ID 等)的表示方式。触控笔设备会将 HID 信息发送到 Android 移动设备,使平台能够将 HID 数据与触摸屏的触摸数据相关联,以通过 MotionEvent 产生触控笔事件。数据可通过蓝牙 (BT)、蓝牙低功耗 (BTLE) 或 USB 发送。</p> |
| |
| <h3 id="hid-descriptor">HID 描述符</h3> |
| |
| <pre class="devsite-click-to-copy"> |
| UsagePage(Digitizer) |
| Usage(Pen) |
| Collection(Application) |
| Usage(Stylus) |
| Collection(Logical) |
| Usage(Tip Pressure) |
| Logical Minimum(0) |
| Logical Maximum(1023) |
| Report Count(1) |
| Report Size(10) |
| Input(Data, Variable, Absolute, No Null) |
| |
| Usage(Barrel Switch) |
| Usage(Secondary Barrel Switch) |
| Usage(Tip Switch) |
| Usage(Invert) |
| Logical Maximum(1) |
| Report Count(4) |
| Report Size(1) |
| Input(Data, Variable, Absolute, No Null) |
| |
| Usage(Transducer Serial Number) |
| Report Count(1) |
| Report Size(128) |
| Feature(Constant, Variable) |
| EndCollection |
| EndCollection |
| |
| unsigned char HID_DESC[] = { |
| 0x05, 0x0D, // UsagePage(Digitizer) |
| 0x09, 0x02, // Usage(Pen) |
| 0xA1, 0x01, // Collection(Application) |
| 0x09, 0x20, // Usage(Stylus) |
| 0xA1, 0x02, // Collection(Logical) |
| 0x09, 0x30, // Usage(Tip Pressure) |
| 0x15, 0x00, // Logical Minimum(0) |
| 0x26, 0xFF, 0x03, // Logical Maximum(1023) |
| 0x95, 0x01, // Report Count(1) |
| 0x75, 0x0A, // Report Size(10) |
| 0x81, 0x02, // Input(Data, Variable, Absolute, No Null) |
| |
| 0x09, 0x44, // Usage(Barrel Switch) |
| 0x09, 0x5A, // Usage(Secondary Barrel Switch) |
| 0x09, 0x42, // Usage(Tip Switch) |
| 0x09, 0x3C, // Usage(Invert) |
| 0x25, 0x01, // Logical Maximum(1) |
| 0x95, 0x04, // Report Count(4) |
| 0x75, 0x01, // Report Size(1) |
| 0x81, 0x02, // Input(Data, Variable, Absolute, No Null) |
| |
| 0x09, 0x5B, // Usage(Transducer Serial Number) |
| 0x95, 0x01, // Report Count(1) |
| 0x75, 0x80, // Report Size(128) |
| 0xB1, 0x03, // Feature(Constant, Variable) |
| 0xC0, // End Collection |
| 0xC0, // End Collection |
| } |
| </pre> |
| |
| <h2 id="guidelines-devs">面向触控笔应用开发者的指南</h2> |
| <p>Android 6.0 平台会自动处理配对和事件关联操作,因此 Android 6.0 上运行的现有应用和新应用均默认支持蓝牙触控笔。要详细了解蓝牙触控笔 API,请参阅 <a href="http://developer.android.com/about/versions/marshmallow/android-6.0.html#bluetooth-stylus">developer.android.com</a>。 |
| |
| </p></body></html> |