/documentation/android_access/developers.html
HTML | 192 lines | 176 code | 4 blank | 12 comment | 0 complexity | e73fda3eb424c0f3473aaa7c148e77ef MD5 | raw file
1 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 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 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. --> 14 15<html> 16<head> 17<title>Designing for Accessibility</title> 18<link rel="stylesheet" type="text/css" href="style.css"> 19<style> 20.code { 21 font-style: italic; 22} 23</style> 24 25</head> 26<body> 27 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> 34<p></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> 39<p></p> 40<p>Your application should follow these guidelines to assure that it will 41provide a good experience for these users.</p> 42<h2>Introduction</h2> 43<p>Following these two basic rules will solve the majority of access related 44problems:</p> 45<ol> 46 <li>Make all of your controls accessible via the trackball or directional 47 controller.</li> 48 <li><span class="code"><a 49 href="http://developer.android.com/reference/android/widget/ImageButton.html">ImageButton</a></span><a 50 href="http://developer.android.com/reference/android/widget/ImageButton.html">s</a>, 51 <span class="code"><a 52 href="http://developer.android.com/reference/android/widget/EditText.html">EditTexts</a></span> 53 and other input elements using the <span class="code"><a 54 href="http://developer.android.com/reference/android/view/View.html#attr_android:contentDescription">contentDescription</a></span> 55 attribute.</li> 56</ol> 57<h2>Allow Navigation with a Directional Controller</h2> 58<p>Many Android devices come with some sort of directional controller, such 59as:</p> 60<ol> 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’s equivalent to clicking a 64 trackball or d-pad.</li> 65</ol> 66<p></p> 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> 71<p></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> 77<p></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="http://developer.android.com/reference/android/view/View.html#isFocusable()">isFocusable()</a></span> 81method. To change whether a view can take focus, call <span class="code"><a 82 href="http://developer.android.com/reference/android/view/View.html#setFocusable(boolean)">setFocusable(boolean)</a></span> 83or set the <span class="code"><a 84 href="http://developer.android.com/reference/android/view/View.html#attr_android:focusable">android:focusable</a></span> 85attribute in an XML layout file.</p> 86<p></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="http://developer.android.com/reference/android/view/KeyEvent.html">KeyEvent</a></span> 99with <span class="code"><a 100 href="http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_DPAD_CENTER">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> 103appropriately.</p> 104<p></p> 105<p><span class="code">KeyEvent</span> <span class="code"><a 106 href="http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_ENTER">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="http://developer.android.com/reference/android/widget/ImageButton.html">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="http://developer.android.com/reference/android/widget/EditText.html">EditText</a></span> 116may have a label near it that indicates its purpose. When a visually impaired 117user accesses your application using Android’s accessibility services, 118these visual cues are often lost.</p> 119<p></p> 120<p>The <span class="code"><a 121 href="http://developer.android.com/reference/android/view/View.html#attr_android:contentDescription">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’s 131interface.</p> 132<p></p> 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 136Elements</h2> 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="http://developer.android.com/reference/android/view/accessibility/AccessibilityEventSource.html">AccessibilityEventSource</a></span> 140interface and sending <span class="code"><a 141 href="http://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html">AccessibilityEvent</a></span>s 142at the proper times.</p> 143<p></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> 147<p></p> 148<p>There are five types of accessibility events that should be sent as the 149user interacts with your view.</p> 150<p></p> 151<p class="code">TYPE_VIEW_CLICKED</p> 152<p> This should be sent when the user clicks on the view.</p> 153<p class="code">TYPE_VIEW_LONG_CLICKED</p> 154<p> This should be sent when the user long clicks on the view.</p> 155<p class="code">TYPE_VIEW_SELECTED</p> 156<p> This should be sent when the selects and item, usually in 157the context of an <a 158 href="http://developer.android.com/reference/android/widget/AdapterView.html">AdapterView</a>.</p> 159<p class="code">TYPE_VIEW_FOCUSED</p> 160<p> This should be sent when the user focuses on the view.</p> 161<p class="code">TYPE_VIEW_TEXT_CHANGED</p> 162<p> This should be sent when the text of the view changes.</p> 163<p></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’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="http://market.android.com/details?id=com.google.android.marvin.talkback">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> 174<p></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> 180<p></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> 185<p></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> 190</div> 191</body> 192</html>