• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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 package com.android.uiautomator.core;
17 
18 import android.graphics.Rect;
19 import android.view.accessibility.AccessibilityNodeInfo;
20 
21 /**
22  * This class contains static helper methods to work with
23  * {@link AccessibilityNodeInfo}
24  */
25 class AccessibilityNodeInfoHelper {
26 
27     /**
28      * Returns the node's bounds clipped to the size of the display
29      *
30      * @param node
31      * @param width pixel width of the display
32      * @param height pixel height of the display
33      * @return null if node is null, else a Rect containing visible bounds
34      */
getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height)35     static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
36         if (node == null) {
37             return null;
38         }
39         // targeted node's bounds
40         Rect nodeRect = new Rect();
41         node.getBoundsInScreen(nodeRect);
42 
43         Rect displayRect = new Rect();
44         displayRect.top = 0;
45         displayRect.left = 0;
46         displayRect.right = width;
47         displayRect.bottom = height;
48 
49         if (nodeRect.intersect(displayRect)) {
50             return nodeRect;
51         } else {
52             return new Rect();
53         }
54     }
55 }
56