1 /**
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. 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 distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11  * express or implied. See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 package android.accessibilityservice.cts.activities;
16 
17 import android.os.Bundle;
18 import android.view.View;
19 
20 import android.view.accessibility.AccessibilityNodeInfo;
21 import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
22 import android.accessibilityservice.cts.R;
23 
24 /**
25  * Activity for testing the accessibility APIs for querying of
26  * the screen content. These APIs allow exploring the screen and
27  * requesting an action to be performed on a given view from an
28  * AccessibilityService.
29  */
30 public class AccessibilityWindowQueryActivity extends AccessibilityTestActivity {
31 
32     @Override
onCreate(Bundle savedInstanceState)33     public void onCreate(Bundle savedInstanceState) {
34         super.onCreate(savedInstanceState);
35         setContentView(R.layout.query_window_test);
36 
37         findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() {
38             public void onClick(View v) {
39                 /* do nothing */
40             }
41         });
42         findViewById(R.id.button5).setOnLongClickListener(new View.OnLongClickListener() {
43             public boolean onLongClick(View v) {
44                 return true;
45             }
46         });
47 
48         findViewById(R.id.button5).setAccessibilityDelegate(new View.AccessibilityDelegate() {
49             @Override
50             public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
51                 super.onInitializeAccessibilityNodeInfo(host, info);
52                 info.addAction(new AccessibilityAction(R.id.foo_custom_action, "Foo"));
53             }
54 
55             @Override
56             public boolean performAccessibilityAction(View host, int action, Bundle args) {
57                 if (action == R.id.foo_custom_action) {
58                     return true;
59                 }
60                 return super.performAccessibilityAction(host, action, args);
61             }
62         });
63     }
64 }
65