1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 Copyright 2013 The Android Open Source Project 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16--> 17 18<sample> 19 <name>CheckableLayout</name> 20 <group>Accessibility</group> 21 <package>com.example.android.checkablelayout</package> 22 <minSdk>16</minSdk> 23 <strings> 24 <intro> 25 <![CDATA[ 26 Sample showing how to make an accessible custom view that extends 27 a layout. 28 ]]> 29 </intro> 30 </strings> 31 32 <template src="base-build" /> 33 34 <metadata> 35 <status>PUBLISHED</status> 36 <categories>Accessibility</categories> 37 <technologies>Android</technologies> 38 <languages>Java</languages> 39 <solutions>Mobile</solutions> 40 <level>BEGINNER</level> 41 <icon>screenshots/icon-web.png</icon> 42 <screenshots> 43 <img>screenshots/discover.png</img> 44 <img>screenshots/checked.png</img> 45 </screenshots> 46 <api_refs> 47 <android>android.view.accessibility.AccessibilityNodeInfo</android> 48 <android>android.view.accessibility.AccessibilityEvent</android> 49 </api_refs> 50 <description> 51 Sample demonstrating how to make a simple custom view accessible. 52 Creates a simple `CheckableFrameLayout` that has the accessibility 53 profile of builtin that implements the `Checkable` interface (e.g. 54 `Checkbox`). 55 </description> 56 <intro> 57 This sample implements a single custom view, a 58 `CheckableFrameLayout`, which implements the `Checkable` interface 59 and maintains a checked state. 60 61 This sample uses the custom view as a container for two overlayed 62 `<![CDATA[<ImageView>]]>`s. The first `<![CDATA[<ImageView>]]>` is 63 always displayed, while the second `<![CDATA[<ImageView>]]>`'s 64 display status toggles with the checked state of it's parent (the 65 `CheckableLayout`). This second `<![CDATA[<ImageView>]]>` uses 66 `android:duplicateParentState` (see `activity_main.xml`) and a 67 drawable that is tied to `android:state_checked` (see 68 `drawable/ic_checkable_item.xml`). This drawable is displayed only 69 when the parent is in a checked state. 70 71 This sample provides a basic introduction to Android accessibility 72 by showing how to make a custom view behave similar to a builtin 73 widget like a `Checkbox`. 74 Developers should focus on two methods that are overridden from the 75 parent class: 76 `onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)` and 77 `onInitializeAccessibilityEvent(AccessibilityEvent event)`. 78 79 The `onInitializeAccessibilityNodeInfo()` method provides 80 accessibility services with information about the state of this 81 view. We override this method to tell an accessibility service that 82 this view is checkable, and we set the intitial checked state of the 83 view. 84 85 The `onInitializeAccessibilityEvent()` method is use by the 86 system to obtain additional information about the state of the view 87 as its state changes. 88 89 With this information, an accessibility service has what it needs to 90 allow a user to meaningfully discover the view and know its state. 91 </intro> 92 </metadata> 93</sample> 94