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.accessibilityservice.cts.R;
18 import android.os.Bundle;
19 import android.view.View;
20 import android.view.accessibility.AccessibilityNodeInfo;
21 import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
22 
23 /**
24  * Activity for testing the accessibility APIs for querying of
25  * the screen content. These APIs allow exploring the screen and
26  * requesting an action to be performed on a given view from an
27  * AccessibilityService.
28  */
29 public class AccessibilityWindowQueryActivity extends AccessibilityTestActivity {
30 
31     @Override
onCreate(Bundle savedInstanceState)32     public void onCreate(Bundle savedInstanceState) {
33         super.onCreate(savedInstanceState);
34         setContentView(R.layout.query_window_test);
35 
36         findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() {
37             public void onClick(View v) {
38                 /* do nothing */
39             }
40         });
41         findViewById(R.id.button5).setOnLongClickListener(new View.OnLongClickListener() {
42             public boolean onLongClick(View v) {
43                 return true;
44             }
45         });
46 
47         findViewById(R.id.button5).setAccessibilityDelegate(new View.AccessibilityDelegate() {
48             @Override
49             public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
50                 super.onInitializeAccessibilityNodeInfo(host, info);
51                 info.addAction(new AccessibilityAction(R.id.foo_custom_action, "Foo"));
52             }
53 
54             @Override
55             public boolean performAccessibilityAction(View host, int action, Bundle args) {
56                 if (action == R.id.foo_custom_action) {
57                     return true;
58                 }
59                 return super.performAccessibilityAction(host, action, args);
60             }
61         });
62     }
63 }
64