add: simple code generation

This commit is contained in:
hyb1996
2017-11-06 23:45:36 +08:00
parent 0b884f5747
commit 7c1decdc04
18 changed files with 822 additions and 40 deletions

View File

@@ -403,12 +403,16 @@ public class UiGlobalSelector {
}
public UiObjectCollection findOf(UiObject node) {
return UiObjectCollection.of(findAndReturnList(node));
}
public List<UiObject> findAndReturnList(UiObject node) {
List<UiObject> list = new ArrayList<>();
list.add(node);
for (ListFilter filter : mFilters) {
list = filter.filter(list);
}
return UiObjectCollection.of(list);
return list;
}
@Nullable

View File

@@ -139,7 +139,8 @@ public class UiObject extends AccessibilityNodeInfoCompat {
}
public String desc() {
return getContentDescription().toString();
CharSequence d = getContentDescription();
return d == null ? null : d.toString();
}
public String className() {
@@ -411,7 +412,7 @@ public class UiObject extends AccessibilityNodeInfoCompat {
}
public List<UiObject> findByText(String text) {
return compatListToUiObjectList(findAccessibilityNodeInfosByText(text), mAllocator);
return new UiGlobalSelector().textContains(text).findAndReturnList(this);
}
@Override
@@ -422,7 +423,7 @@ public class UiObject extends AccessibilityNodeInfoCompat {
}
public List<UiObject> findByViewId(String viewId) {
return compatListToUiObjectList(findAccessibilityNodeInfosByViewId(viewId), mAllocator);
return new UiGlobalSelector().id(viewId).findAndReturnList(this);
}
public static List<UiObject> compatListToUiObjectList(List<AccessibilityNodeInfoCompat> compats, AccessibilityNodeInfoAllocator allocator) {

View File

@@ -18,8 +18,8 @@ public class IdFilter extends ListFilter.Default {
}
};
public static IdFilter equals(String id) {
return new IdFilter(id);
public static StringEqualsFilter equals(String id) {
return new StringEqualsFilter(id, ID_GETTER);
}
public static StringStartsWithFilter startsWith(String prefix) {

View File

@@ -23,7 +23,7 @@ public class TextFilter extends ListFilter.Default {
}
public static ListFilter contains(String str) {
return new TextFilter(str);
return new StringContainsFilter(str, TEXT_GETTER);
}
public static ListFilter startsWith(String prefix) {

View File

@@ -18,13 +18,14 @@ import java.util.List;
public class NodeInfo {
private List<NodeInfo> children = new ArrayList<>();
private Rect mBoundsInScreen;
private Rect mBoundsInScreen = new Rect();
private Rect mBoundsInParent = new Rect();
public String id;
public CharSequence desc;
public CharSequence className;
public CharSequence packageName;
public CharSequence text;
public String desc;
public String className;
public String packageName;
public String text;
public int depth;
public int drawingOrder;
public boolean accessibilityFocused;
@@ -45,14 +46,17 @@ public class NodeInfo {
public boolean selected;
public boolean scrollable;
public String bounds;
public boolean checkable;
public boolean focused;
public boolean visibleToUser;
public NodeInfo(UiObject node) {
id = simplifyId(node.getViewIdResourceName());
desc = node.getContentDescription();
className = node.getClassName();
packageName = node.getPackageName();
text = node.getText();
desc = node.desc();
className = node.className();
packageName = node.packageName();
text = node.text();
depth = node.depth();
drawingOrder = node.getDrawingOrder();
@@ -66,18 +70,22 @@ public class NodeInfo {
accessibilityFocused = node.isAccessibilityFocused();
checked = node.isChecked();
checkable = node.isCheckable();
clickable = node.isClickable();
contextClickable = node.isContextClickable();
dismissable = node.isDismissable();
enabled = node.isEnabled();
editable = node.isEditable();
focusable = node.isFocusable();
focused = node.focused();
longClickable = node.isLongClickable();
selected = node.isSelected();
scrollable = node.isScrollable();
mBoundsInScreen = new Rect();
visibleToUser = node.visibleToUser();
node.getBoundsInScreen(mBoundsInScreen);
node.getBoundsInParent(mBoundsInParent);
bounds = boundsToString(mBoundsInScreen);
}
private String simplifyId(String idResourceName) {
@@ -91,6 +99,11 @@ public class NodeInfo {
return mBoundsInScreen;
}
public Rect getBoundsInParent() {
return mBoundsInParent;
}
public static String boundsToString(Rect rect) {
return rect.toString().replace('-', ',').replace(" ", "").substring(4);
}