More rational sizing of reticle (max size 50% of screen dimension) but also allow larger reticles to accomodate very high res new devices like the S4

git-svn-id: https://zxing.googlecode.com/svn/trunk@2709 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen@gmail.com 2013-05-03 20:59:17 +00:00
parent 8fbcb53126
commit 4cbc515401

View file

@ -41,8 +41,8 @@ public final class CameraManager {
private static final int MIN_FRAME_WIDTH = 240; private static final int MIN_FRAME_WIDTH = 240;
private static final int MIN_FRAME_HEIGHT = 240; private static final int MIN_FRAME_HEIGHT = 240;
private static final int MAX_FRAME_WIDTH = 600; private static final int MAX_FRAME_WIDTH = 960; // = 1920/2
private static final int MAX_FRAME_HEIGHT = 400; private static final int MAX_FRAME_HEIGHT = 540; // = 1080/2
private final Context context; private final Context context;
private final CameraConfigurationManager configManager; private final CameraConfigurationManager configManager;
@ -212,18 +212,10 @@ public final class CameraManager {
// Called early, before init even finished // Called early, before init even finished
return null; return null;
} }
int width = screenResolution.x * 3 / 4;
if (width < MIN_FRAME_WIDTH) { int width = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
width = MIN_FRAME_WIDTH; int height = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
} else if (width > MAX_FRAME_WIDTH) {
width = MAX_FRAME_WIDTH;
}
int height = screenResolution.y * 3 / 4;
if (height < MIN_FRAME_HEIGHT) {
height = MIN_FRAME_HEIGHT;
} else if (height > MAX_FRAME_HEIGHT) {
height = MAX_FRAME_HEIGHT;
}
int leftOffset = (screenResolution.x - width) / 2; int leftOffset = (screenResolution.x - width) / 2;
int topOffset = (screenResolution.y - height) / 2; int topOffset = (screenResolution.y - height) / 2;
framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height); framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
@ -231,6 +223,17 @@ public final class CameraManager {
} }
return framingRect; return framingRect;
} }
private static int findDesiredDimensionInRange(int resolution, int hardMin, int hardMax) {
int dim = resolution / 2; // Target 50% of each dimension
if (dim < hardMin) {
return hardMin;
}
if (dim > hardMax) {
return hardMax;
}
return dim;
}
/** /**
* Like {@link #getFramingRect} but coordinates are in terms of the preview frame, * Like {@link #getFramingRect} but coordinates are in terms of the preview frame,