• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Stylus
2@jd:body
3
4<!--
5    Copyright 2015 The Android Open Source Project
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18-->
19
20<div id="qv-wrapper">
21  <div id="qv">
22    <h2>In this document</h2>
23    <ol id="auto-toc">
24    </ol>
25  </div>
26</div>
27
28<p>Android 6.0 and higher supports a standard data format for Bluetooth stylus
29connections over Bluetooth (BT), Bluetooth Low Energy (BTLE), or USB. The
30platform correlates timing between touch input and stylus data then provides
31stylus data to render MotionEvents to the active application. The following
32sections provide guidelines for OEM partners, stylus accessory creators, and
33stylus application developers.</p>
34
35<h2 id="guide-partners">Guidelines for OEM partners</h2>
36<p>To enable Bluetooth stylus support, OEM partners must support Bluetooth
37(and should support BTLE for wider compatibility). The platform handles data
38collection, timing correlation, and rendering to the application for supported
39stylus events.</p>
40
41<p>At this time, the Android CTS <strong>does not</strong> include tests to
42ensure existing APIs for touch events support default behavior. As a
43workaround, we recommend creating a stylus accessory or emulator that can
44simulate stylus events.</p>
45
46<h2 id="guide-creators">Guidelines for stylus accessory creators</h2>
47<p>To implement support on a stylus device, partners must use the Stylus
48Human Interface Device (HID) Descriptor shown below to describe how stylus data
49(pressure sensitivity, eraser, side buttons, device ID, etc.) is represented.
50The stylus device sends the HID information to the Android mobile device,
51enabling the platform to correlate HID data with touch data from the touchscreen
52to produce stylus events via MotionEvent. Data can be sent over Bluetooth (BT),
53Bluetooth Low Energy (BTLE), or USB.</p>
54
55<h3 id="hid-descriptor">HID descriptor</h3>
56
57<p><pre>
58UsagePage(Digitizer)
59Usage(Pen)
60Collection(Application)
61    Usage(Stylus)
62    Collection(Logical)
63        Usage(Tip Pressure)
64        Logical Minimum(0)
65        Logical Maximum(1023)
66        Report Count(1)
67        Report Size(10)
68        Input(Data, Variable, Absolute, No Null)
69
70        Usage(Barrel Switch)
71        Usage(Secondary Barrel Switch)
72        Usage(Tip Switch)
73        Usage(Invert)
74        Logical Maximum(1)
75        Report Count(4)
76        Report Size(1)
77        Input(Data, Variable, Absolute, No Null)
78
79        Usage(Transducer Serial Number)
80        Report Count(1)
81        Report Size(128)
82        Feature(Constant, Variable)
83    EndCollection
84EndCollection
85
86unsigned char HID_DESC[] = {
87    0x05, 0x0D, // UsagePage(Digitizer)
88    0x09, 0x02, // Usage(Pen)
89    0xA1, 0x01, // Collection(Application)
90    0x09, 0x20, // Usage(Stylus)
91    0xA1, 0x02, // Collection(Logical)
92    0x09, 0x30, // Usage(Tip Pressure)
93    0x15, 0x00, // Logical Minimum(0)
94    0x26, 0xFF, 0x03, // Logical Maximum(1023)
95    0x95, 0x01, // Report Count(1)
96    0x75, 0x0A, // Report Size(10)
97    0x81, 0x02, // Input(Data, Variable, Absolute, No Null)
98
99    0x09, 0x44, // Usage(Barrel Switch)
100    0x09, 0x5A, // Usage(Secondary Barrel Switch)
101    0x09, 0x42, // Usage(Tip Switch)
102    0x09, 0x3C, // Usage(Invert)
103    0x25, 0x01, // Logical Maximum(1)
104    0x95, 0x04, // Report Count(4)
105    0x75, 0x01, // Report Size(1)
106    0x81, 0x02, // Input(Data, Variable, Absolute, No Null)
107
108    0x09, 0x5B, // Usage(Transducer Serial Number)
109    0x95, 0x01, // Report Count(1)
110    0x75, 0x80, // Report Size(128)
111    0xB1, 0x03, // Feature(Constant, Variable)
112    0xC0, // End Collection
113    0xC0, // End Collection
114}
115</pre></p>
116
117<h2 id="guidelines-devs">Guidelines for stylus application developers</h2>
118<p>The Android 6.0 platform automatically handles pairing and event correlation,
119so both existing and new applications running on Android 6.0 support Bluetooth
120stylus by default. For details on Bluetooth stylus APIs, refer to
121<a href="http://developer.android.com/about/versions/marshmallow/android-6.0.html#bluetooth-stylus">developer.android.com</a>.