PageRenderTime 29ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

HTML | 192 lines | 176 code | 4 blank | 12 comment | 0 complexity | e73fda3eb424c0f3473aaa7c148e77ef MD5 | raw file
  2<!-- Copyright 2010 Google Inc.
  3     Licensed under the Apache License, Version 2.0 (the "License");
  4     you may not use this file except in compliance with the License.
  5     You may obtain a copy of the License at
  9     Unless required by applicable law or agreed to in writing, software
 10     distributed under the License is distributed on an "AS IS" BASIS,
 11     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12     See the License for the specific language governing permissions and
 13     limitations under the License. -->
 17<title>Designing for Accessibility</title>
 18<link rel="stylesheet" type="text/css" href="style.css">
 20.code {
 21  font-style: italic;
 28<div id="main_body">
 29<h1>Designing for Accessibility</h1>
 30<p>Many Android users have disabilities that cause them to interact with
 31their Android devices in different ways. These include users who have visual,
 32physical or aging-related disabilities that prevent them from fully using or
 33seeing a touch screen.</p>
 35<p>Android provides an accessibility layer that helps these users navigate
 36their Android devices more easily. These services provide things like
 37text-to-speech, haptic feedback and trackball/D-pad navigation that augment the
 38user experience.</p>
 40<p>Your application should follow these guidelines to assure that it will
 41provide a good experience for these users.</p>
 43<p>Following these two basic rules will solve the majority of access related
 46  <li>Make all of your controls accessible via the trackball or directional
 47  controller.</li>
 48  <li><span class="code"><a
 49    href="">ImageButton</a></span><a
 50    href="">s</a>,
 51  <span class="code"><a
 52    href="">EditTexts</a></span>
 53  and other input elements using the <span class="code"><a
 54    href="">contentDescription</a></span>
 55  attribute.</li>
 57<h2>Allow Navigation with a Directional Controller</h2>
 58<p>Many Android devices come with some sort of directional controller, such
 61  <li>A clickable trackball that can be moved in arbitrary directions.</li>
 62  <li>A clickable D-pad that provides movement in four directions.</li>
 63  <li>Arrow keys plus a center button that&rsquo;s equivalent to clicking a
 64  trackball or d-pad.</li>
 67<p>All of these types of directional controllers allow users to navigate the
 68screen without using the touch screen. On some devices, a user can also navigate
 69to the top or bottom of a list by holding down the alt key while pressing a
 70discrete key for up or down.</p>
 72<p>A directional controller is the primary means of navigation for users
 73with visual and some physical impairments and for devices without a touch
 74screen. Verify that all important controls are reachable without using the touch
 75screen and that clicking with the center button has the same effect as clicking
 76on the element on the touch screen.</p>
 78<p>The ability to navigate to a particular view with a directional
 79controller it is determined via the <span class="code"><a
 80  href="">isFocusable()</a></span>
 81method. To change whether a view can take focus, call <span class="code"><a
 82  href="">setFocusable(boolean)</a></span>
 83or set the <span class="code"><a
 84  href="">android:focusable</a></span>
 85attribute in an XML layout file.</p>
 87<p>The ordering of the focus movement is based on an algorithm which finds
 88the nearest neighbor in a given direction. In rare cases, the default algorithm
 89may not match the intended behavior of the developer. In these situations, you
 90can provide explicit overrides by using these XML attributes in the layout file:</p>
 91<p class="code">nextFocusDown</p>
 92<p class="code">nextFocusLeft</p>
 93<p class="code">nextFocusRight</p>
 94<p class="code">nextFocusUp</p>
 95<h3>Clicking with the a directional controller</h3>
 96<p>On most devices, clicking with a directional controller sends a <span
 97  class="code"><a
 98  href="">KeyEvent</a></span>
 99with <span class="code"><a
100  href="">KEYCODE_DPAD_CENTER</a></span>.
101Make sure that this event has the same effect as clicking on the element. All
102standard Android views already handle <span class="code">KEYCODE_DPAD_CENTER</span>
105<p><span class="code">KeyEvent</span> <span class="code"><a
106  href="">KEYCODE_ENTER</a></span>
107as equivalent to <span class="code">KEYCODE_DPAD_CENTER</span>. That makes
108things easier for devices with a full qwerty keyboard.</p>
109<h2>Label Your Input Elements</h2>
110<p>Many input elements rely on visual cues to inform the user of their
111meaning. For example, an application may use an <span class="code"><a
112  href="">ImageButton</a></span>
113with a picture of a plus sign to indicate that the user can add an entry to a
114table. Or, an <span class="code"><a
115  href="">EditText</a></span>
116may have a label near it that indicates its purpose. When a visually impaired
117user accesses your application using Android&rsquo;s accessibility services,
118these visual cues are often lost.</p>
120<p>The <span class="code"><a
121  href="">contentDescription</a></span>
122attribute that should be used to provide a textual representation of this
123information. Set this attribute on every <span class="code">ImageButton</span>
124and <span class="code">EditText</span> and on any other input widget that might
125benefit from this extra information.</p>
126<h2>Follow Android UI Best Practices</h2>
127<p>Developing a user interface that complies with the Android UI guidelines
128will make it easier for users to learn to use your application. This consistency
129is especially important for many disabled users, as they may have less
130contextual information available to try to understand your application&rsquo;s
133<p>Use the view elements provided by the Android SDK whenever possible, as
134these elements have accessibility support built in.</p>
135<h2>Send <span class="code">AccessibilityEvents</span> from Custom View
137<p>If your application requires that you create a custom view element, you
138can make your view accessible by implementing the <span class="code"><a
139  href="">AccessibilityEventSource</a></span>
140interface and sending <span class="code"><a
141  href="">AccessibilityEvent</a></span>s
142at the proper times.</p>
144<p>View classes already implement the <span class="code">AccessibiltyEventSource</span>
145interface. This interface provides the mechanism for sending events to the
146registered AccessibilityServices.</p>
148<p>There are five types of accessibility events that should be sent as the
149user interacts with your view.</p>
151<p class="code">TYPE_VIEW_CLICKED</p>
152<p>&nbsp; &nbsp;This should be sent when the user clicks on the view.</p>
153<p class="code">TYPE_VIEW_LONG_CLICKED</p>
154<p>&nbsp; &nbsp;This should be sent when the user long clicks on the view.</p>
155<p class="code">TYPE_VIEW_SELECTED</p>
156<p>&nbsp; &nbsp;This should be sent when the selects and item, usually in
157the context of an <a
158  href="">AdapterView</a>.</p>
159<p class="code">TYPE_VIEW_FOCUSED</p>
160<p>&nbsp; &nbsp;This should be sent when the user focuses on the view.</p>
161<p class="code">TYPE_VIEW_TEXT_CHANGED</p>
162<p>&nbsp; &nbsp;This should be sent when the text of the view changes.</p>
164<p>Each event type requires that particular properties be set, so that the
165accessibility service can properly respond to the event. Those specifics are
166detailed in the <span class="code">AccessibilityEvent</span> documentation.</p>
167<h2>Test Your Application&rsquo;s Accessibility</h2>
168<p>You can simulate the experience for many users by enabling an
169accessibility service that will speak as you move about the screen. One such
170service is <a
171  href="">TalkBack</a>,
172by the Eyes-Free Project. It comes preinstalled on many Android devices, but is
173also available for free download in the Android Market.</p>
175<p>This service requires that you have a text-to-speech engine installed on
176your phone. You can verify if you have one installed in the <span class="code">Text-to-speech</span>
177settings menu by selecting <span class="code">Listen to an example</span>. If
178you do not hear anything spoken, install the required voice data using the <span
179  class="code">Install voice data</span> option.</p>
181<p>Once text-to-speech is functioning correctly, you can enable TalkBack in
182the <span class="code">Accessibility settings</span> menu. Enable both
183Accessibility and TalkBack. As you navigate about the device, you should now
184hear spoken feedback.</p>
186<p>You can now attempt to use your application as a blind user would. As you
187move around using only the directional controller, make sure that the spoken
188feedback hear makes sense and is sufficient to navigate the application without
189any visual cues.</p>