add screen capture and color searching

This commit is contained in:
hyb1996
2017-05-22 15:41:11 +08:00
parent b3fad201f7
commit 302879333a
45 changed files with 1547 additions and 92 deletions

View File

@@ -12,6 +12,7 @@ public class ScreenMetrics {
private static int deviceScreenHeight;
private static int deviceScreenWidth;
private static boolean initialized = false;
private static int deviceScreenDensity;
public static void initIfNeeded(Activity activity) {
if (!initialized) {
@@ -19,6 +20,7 @@ public class ScreenMetrics {
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
deviceScreenHeight = metrics.heightPixels;
deviceScreenWidth = metrics.widthPixels;
deviceScreenDensity = metrics.densityDpi;
initialized = true;
}
}
@@ -31,10 +33,26 @@ public class ScreenMetrics {
return deviceScreenWidth;
}
public static int getDeviceScreenDensity() {
return deviceScreenDensity;
}
public static int scaleX(int x, int width) {
if (width == 0 || !initialized)
return x;
return x * deviceScreenWidth / width;
}
public static int scaleY(int y, int height) {
if (height == 0 || !initialized)
return y;
return y * deviceScreenHeight / height;
}
private int mScreenWidth;
private int mScreenHeight;
public void setScreenWidth(int screenWidth) {
mScreenWidth = screenWidth;
}
@@ -44,17 +62,14 @@ public class ScreenMetrics {
}
public int scaleX(int x) {
if (mScreenWidth == 0 || !initialized)
return x;
return x * deviceScreenWidth / mScreenWidth;
return scaleX(x, mScreenWidth);
}
public int scaleY(int y) {
if (mScreenHeight == 0 || !initialized)
return y;
return y * deviceScreenHeight / mScreenHeight;
return scaleY(y, mScreenHeight);
}
public void setScreenMetrics(int width, int height) {
mScreenWidth = width;
mScreenHeight = height;