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 */ 16package com.android.uiautomator.core; 17 18import android.graphics.Point; 19import android.graphics.Rect; 20import android.hardware.display.DisplayManagerGlobal; 21import android.view.Display; 22import android.view.accessibility.AccessibilityNodeInfo; 23 24/** 25 * This class contains static helper methods to work with 26 * {@link AccessibilityNodeInfo} 27 */ 28class AccessibilityNodeInfoHelper { 29 30 /** 31 * Returns the node's bounds clipped to the size of the display 32 * 33 * @param node 34 * @return null if node is null, else a Rect containing visible bounds 35 */ 36 static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node) { 37 if (node == null) { 38 return null; 39 } 40 // targeted node's bounds 41 Rect nodeRect = new Rect(); 42 node.getBoundsInScreen(nodeRect); 43 44 Rect displayRect = new Rect(); 45 Display display = DisplayManagerGlobal.getInstance() 46 .getRealDisplay(Display.DEFAULT_DISPLAY); 47 Point outSize = new Point(); 48 display.getSize(outSize); 49 displayRect.top = 0; 50 displayRect.left = 0; 51 displayRect.right = outSize.x; 52 displayRect.bottom = outSize.y; 53 54 nodeRect.intersect(displayRect); 55 return nodeRect; 56 } 57} 58