1 /* 2 * Copyright (C) 2015 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.tv.testing.uihelper; 17 18 import android.graphics.Point; 19 import android.support.test.uiautomator.Direction; 20 import android.support.test.uiautomator.UiObject2; 21 22 /** 23 * Static utility methods for {@link UiObject2}s. 24 */ 25 public class UiObject2Utils { 26 27 public static boolean hasSiblingInDirection(UiObject2 theUiObject, Direction direction) { 28 Point myCenter = theUiObject.getVisibleCenter(); 29 for (UiObject2 sibling : theUiObject.getParent().getChildren()) { 30 Point siblingCenter = sibling.getVisibleCenter(); 31 switch (direction) { 32 case UP: 33 if (myCenter.y > siblingCenter.y) { 34 return true; 35 } 36 break; 37 case DOWN: 38 if (myCenter.y < siblingCenter.y) { 39 return true; 40 } 41 break; 42 case LEFT: 43 if (myCenter.x > siblingCenter.x) { 44 return true; 45 } 46 break; 47 case RIGHT: 48 if (myCenter.x < siblingCenter.x) { 49 return true; 50 } 51 break; 52 default: 53 throw new IllegalArgumentException(direction.toString()); 54 } 55 } 56 return false; 57 } 58 59 private UiObject2Utils() { 60 } 61 } 62