• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package foo.bar.testback;
18 
19 import android.view.accessibility.AccessibilityNodeInfo;
20 
21 import java.util.function.Predicate;
22 
23 /**
24  * Utility class for working with AccessibilityNodeInfo
25  */
26 public class AccessibilityNodeInfoUtils {
findParent( AccessibilityNodeInfo start, Predicate<AccessibilityNodeInfo> condition)27     public static AccessibilityNodeInfo findParent(
28             AccessibilityNodeInfo start, Predicate<AccessibilityNodeInfo> condition) {
29         AccessibilityNodeInfo parent = start.getParent();
30         if ((parent == null) || (condition.test(parent))) {
31             return parent;
32         }
33 
34         return findParent(parent, condition);
35     }
36 
findChildDfs( AccessibilityNodeInfo start, Predicate<AccessibilityNodeInfo> condition)37     public static AccessibilityNodeInfo findChildDfs(
38             AccessibilityNodeInfo start, Predicate<AccessibilityNodeInfo> condition) {
39         int numChildren = start.getChildCount();
40         for (int i = 0; i < numChildren; i++) {
41             AccessibilityNodeInfo child = start.getChild(i);
42             if (child != null) {
43                 if (condition.test(child)) {
44                     return child;
45                 }
46                 AccessibilityNodeInfo childResult = findChildDfs(child, condition);
47                 if (childResult != null) {
48                     return childResult;
49                 }
50             }
51         }
52         return null;
53     }
54 }
55