public void testMain() {
UiObject ptnView = mDevice.findObject(new UiSelector().resourceId("com.android.settings:id/lockPattern"));
Rect curPoint;
//
curPoint = ptnView.getVisibleBounds();
// 0: 1080: 540: 994: 1080: 1080: 454
mDevice.takeScreenshot(new File("/path/Test.png"));
Bitmap bitmap = BitmapFactory.decodeFile("/path/Test.png");
int width = curPoint.right;
int height = curPoint.bottom;
int index = 1;
for (int y = curPoint.top; y < height; y++) {
int i = 0;
for (int x = curPoint.left + 1; x < width; x++) {
int[] colorA = getColorArray(bitmap.getPixel(x - 1, y));
int[] colorB = getColorArray(bitmap.getPixel(x, y));
//
double distan = getDistance(colorA, colorB);
if (distan > 200) {
x += 50;
i++;
if (i > 2) {
y += 60;
break;
}
}
}
}
} catch (Exception e) {
}
}
private double getDistance(int[] colorA, int[] colorB) {
double x = colorA[0] - colorB[0];
double y = colorA[1] - colorB[1];
double z = colorA[2] - colorB[2];
return Math.sqrt(x * x + y * y + z * z);
}
public int[] getColorArray(int color) {
int[] colorArray = new int[3];
colorArray[0] = color & 0x0ff0000 >> 16;
colorArray[1] = color & 0x0ff00 >> 8;
colorArray[2] = color & 0x0ff;
return colorArray;
}