• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /** Static utility methods for {@link UiObject2}s. */
23 public class UiObject2Utils {
24 
hasSiblingInDirection(UiObject2 theUiObject, Direction direction)25     public static boolean hasSiblingInDirection(UiObject2 theUiObject, Direction direction) {
26         Point myCenter = theUiObject.getVisibleCenter();
27         for (UiObject2 sibling : theUiObject.getParent().getChildren()) {
28             Point siblingCenter = sibling.getVisibleCenter();
29             switch (direction) {
30                 case UP:
31                     if (myCenter.y > siblingCenter.y) {
32                         return true;
33                     }
34                     break;
35                 case DOWN:
36                     if (myCenter.y < siblingCenter.y) {
37                         return true;
38                     }
39                     break;
40                 case LEFT:
41                     if (myCenter.x > siblingCenter.x) {
42                         return true;
43                     }
44                     break;
45                 case RIGHT:
46                     if (myCenter.x < siblingCenter.x) {
47                         return true;
48                     }
49                     break;
50                 default:
51                     throw new IllegalArgumentException(direction.toString());
52             }
53         }
54         return false;
55     }
56 
UiObject2Utils()57     private UiObject2Utils() {}
58 }
59