feat(autojs): UiSelector.indexInParent

This commit is contained in:
hyb1996
2018-05-28 13:14:59 +08:00
parent 9911c9146d
commit ac0e9952c8
3 changed files with 25 additions and 1 deletions

View File

@@ -79,7 +79,7 @@ public class ImageWrapper {
} }
public Mat getMat() { public Mat getMat() {
if (mMat == null) { if (mMat == null && mBitmap != null) {
mMat = new Mat(); mMat = new Mat();
Utils.bitmapToMat(mBitmap, mMat); Utils.bitmapToMat(mBitmap, mMat);
} }
@@ -87,6 +87,7 @@ public class ImageWrapper {
} }
public void saveTo(String path) { public void saveTo(String path) {
ensureNotRecycled();
if (mBitmap != null) { if (mBitmap != null) {
try { try {
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(path)); mBitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(path));
@@ -99,6 +100,7 @@ public class ImageWrapper {
} }
public int pixel(int x, int y) { public int pixel(int x, int y) {
ensureNotRecycled();
if (mBitmap != null) { if (mBitmap != null) {
return mBitmap.getPixel(x, y); return mBitmap.getPixel(x, y);
} }
@@ -121,4 +123,9 @@ public class ImageWrapper {
} }
} }
private void ensureNotRecycled() {
if (mBitmap == null && mMat == null)
throw new IllegalStateException("image has been recycled");
}
} }

View File

@@ -396,6 +396,11 @@ public class UiGlobalSelector {
return this; return this;
} }
public UiGlobalSelector indexInParent(int index) {
mFilters.add(new IntFilter(IntFilter.INDEX_IN_PARENT, index));
return this;
}
public UiGlobalSelector filter(final BooleanFilter.BooleanSupplier filter) { public UiGlobalSelector filter(final BooleanFilter.BooleanSupplier filter) {
mFilters.add(new DfsFilter() { mFilters.add(new DfsFilter() {

View File

@@ -96,6 +96,18 @@ public class IntFilter extends DfsFilter {
} }
}; };
public static final IntProperty INDEX_IN_PARENT = new IntProperty() {
@Override
public int get(UiObject object) {
return object.indexInParent();
}
@Override
public String toString() {
return "indexInParent";
}
};
private IntProperty mIntProperty; private IntProperty mIntProperty;
private int mValue; private int mValue;