118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu/* 218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * Copyright (C) 2012 The Android Open Source Project 318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * 418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * Licensed under the Apache License, Version 2.0 (the "License"); 518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * you may not use this file except in compliance with the License. 618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * You may obtain a copy of the License at 718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * 818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * http://www.apache.org/licenses/LICENSE-2.0 918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * 1018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * Unless required by applicable law or agreed to in writing, software 1118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * distributed under the License is distributed on an "AS IS" BASIS, 1218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * See the License for the specific language governing permissions and 1418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * limitations under the License. 1518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu */ 1618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhupackage com.android.uiautomator.core; 1718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu 1818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuimport android.graphics.Rect; 1918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuimport android.view.accessibility.AccessibilityNodeInfo; 2018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu 2118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu/** 2218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * This class contains static helper methods to work with 2318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * {@link AccessibilityNodeInfo} 2418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu */ 2518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhuclass AccessibilityNodeInfoHelper { 2618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu 2718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu /** 2818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * Returns the node's bounds clipped to the size of the display 2918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * 3018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * @param node 3118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * @param width pixel width of the display 3218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * @param height pixel height of the display 3318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * @return null if node is null, else a Rect containing visible bounds 3418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu */ 3518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) { 3618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu if (node == null) { 3718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu return null; 3818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu } 3918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu // targeted node's bounds 4018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu Rect nodeRect = new Rect(); 4118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu node.getBoundsInScreen(nodeRect); 4218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu 4318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu Rect displayRect = new Rect(); 4418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu displayRect.top = 0; 4518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu displayRect.left = 0; 4618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu displayRect.right = width; 4718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu displayRect.bottom = height; 4818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu 4918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu nodeRect.intersect(displayRect); 5018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu return nodeRect; 5118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu } 5218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu} 53