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

@@ -0,0 +1,54 @@
package com.stardust.app;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.util.SparseArray;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Stardust on 2017/3/5.
*/
public interface OnActivityResultDelegate {
void onActivityResult(int requestCode, int resultCode, Intent data);
interface DelegateHost {
@NonNull
Mediator getOnActivityResultDelegateMediator();
}
class Mediator implements OnActivityResultDelegate {
private SparseArray<OnActivityResultDelegate> mSpecialDelegate = new SparseArray<>();
private List<OnActivityResultDelegate> mDelegates = new ArrayList<>();
public void onActivityResult(int requestCode, int resultCode, Intent data) {
OnActivityResultDelegate delegate = mSpecialDelegate.get(requestCode);
if (delegate != null) {
delegate.onActivityResult(requestCode, resultCode, data);
}
for (OnActivityResultDelegate d : mDelegates) {
d.onActivityResult(requestCode, resultCode, data);
}
}
public void addDelegate(OnActivityResultDelegate delegate) {
mDelegates.add(delegate);
}
public void addDelegate(int requestCode, OnActivityResultDelegate delegate) {
mSpecialDelegate.put(requestCode, delegate);
}
public void removeDelegate(OnActivityResultDelegate delegate) {
if (mDelegates.remove(delegate)) {
// TODO: 2017/3/16 优化
mSpecialDelegate.removeAt(mSpecialDelegate.indexOfValue(delegate));
}
}
}
}

View File

@@ -1,6 +1,8 @@
package com.stardust.concurrent;
import java.lang.reflect.Constructor;
/**
* Created by Stardust on 2017/5/8.
*/
@@ -25,6 +27,14 @@ public class VolatileBox<T> {
mValue = value;
}
public boolean isNull() {
return mValue == null;
}
public boolean notNull() {
return mValue != null;
}
public void setAndNotify(T value) {
mValue = value;
synchronized (this) {
@@ -43,4 +53,18 @@ public class VolatileBox<T> {
return mValue;
}
public T blockedGetOrThrow(Class<? extends RuntimeException> exception) {
synchronized (this) {
try {
this.wait();
} catch (InterruptedException e) {
try {
throw exception.newInstance();
} catch (InstantiationException | IllegalAccessException e1) {
throw new RuntimeException(e1);
}
}
}
return mValue;
}
}

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;