Improved the Android M3 viewfinder display, by making the framing box larger and zooming in. Also fixed a bug when restarting the activity where the camera params were stale. Fixed handling of geo and tel URIs.

git-svn-id: https://zxing.googlecode.com/svn/trunk@342 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-04-03 21:13:50 +00:00
parent 87da7e9226
commit 6f4417346c
2 changed files with 28 additions and 16 deletions

View file

@ -41,6 +41,7 @@ final class CameraManager {
private final Context context;
private Point cameraResolution;
private Point stillResolution;
private Point previewResolution;
private int stillMultiplier;
private Point screenResolution;
private Rect framingRect;
@ -51,8 +52,9 @@ final class CameraManager {
CameraManager(Context context) {
this.context = context;
calculateStillResolution();
getScreenResolution();
calculateStillResolution();
calculatePreviewResolution();
bitmap = Bitmap.createBitmap(stillResolution.x, stillResolution.y, false);
camera = CameraDevice.open();
params = new CameraDevice.CaptureParams();
@ -63,6 +65,9 @@ final class CameraManager {
public void openDriver() {
if (camera == null) {
camera = CameraDevice.open();
// If we're reopening the camera, we need to reset the capture params.
previewMode = false;
setPreviewMode(true);
}
}
@ -95,7 +100,7 @@ final class CameraManager {
*/
public Rect getFramingRect() {
if (framingRect == null) {
int size = stillResolution.x * screenResolution.x / cameraResolution.x;
int size = stillResolution.x * screenResolution.x / previewResolution.x;
int leftOffset = (screenResolution.x - size) / 2;
int topOffset = (screenResolution.y - size) / 2;
framingRect = new Rect(leftOffset, topOffset, leftOffset + size, topOffset + size);
@ -134,18 +139,10 @@ final class CameraManager {
if (on != previewMode) {
if (on) {
params.type = 1; // preview
if (cameraResolution.x / (float) cameraResolution.y <
screenResolution.x / (float) screenResolution.y) {
params.srcWidth = cameraResolution.x;
params.srcHeight = cameraResolution.x * screenResolution.y / screenResolution.x;
params.leftPixel = 0;
params.topPixel = (cameraResolution.y - params.srcHeight) / 2;
} else {
params.srcWidth = cameraResolution.y * screenResolution.x / screenResolution.y;
params.srcHeight = cameraResolution.y;
params.leftPixel = (cameraResolution.x - params.srcWidth) / 2;
params.topPixel = 0;
}
params.srcWidth = previewResolution.x;
params.srcHeight = previewResolution.y;
params.leftPixel = (cameraResolution.x - params.srcWidth) / 2;
params.topPixel = (cameraResolution.y - params.srcHeight) / 2;
params.outputWidth = screenResolution.x;
params.outputHeight = screenResolution.y;
params.dataFormat = 2; // RGB565
@ -217,6 +214,16 @@ final class CameraManager {
" nativeResolution " + nativeResolution + " stillMultiplier " + stillMultiplier);
}
private void calculatePreviewResolution() {
int previewHeight = (int) (stillResolution.x * stillMultiplier * 1.4f);
int previewWidth = previewHeight * screenResolution.x / screenResolution.y;
previewWidth = ((previewWidth + 7) >> 3) << 3;
if (previewWidth > cameraResolution.x) previewWidth = cameraResolution.x;
previewHeight = previewWidth * screenResolution.y / screenResolution.x;
previewResolution = new Point(previewWidth, previewHeight);
Log.v(TAG, "previewWidth " + previewWidth + " previewHeight " + previewHeight);
}
// FIXME(dswitkin): These three methods have temporary constants until the new Camera API can
// provide the real values for the current device.
// Temporary: the camera's maximum resolution in pixels.

View file

@ -21,6 +21,7 @@ import android.net.ContentURI;
import android.os.Handler;
import android.os.Message;
import android.provider.Contacts;
import android.util.Log;
import com.google.zxing.client.result.AddressBookAUParsedResult;
import com.google.zxing.client.result.AddressBookDoCoMoParsedResult;
import com.google.zxing.client.result.BookmarkDoCoMoParsedResult;
@ -45,6 +46,8 @@ import java.net.URISyntaxException;
*/
final class ResultHandler extends Handler {
private static final String TAG = "ResultHandler";
private final Intent intent;
private final BarcodeReaderCaptureActivity captureActivity;
@ -94,7 +97,7 @@ final class ResultHandler extends Handler {
} else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
try {
intent = new Intent(Intent.SENDTO_ACTION, new ContentURI(emailResult.getEmailAddress()));
intent = new Intent(Intent.SENDTO_ACTION, new ContentURI("mailto:" + emailResult.getEmailAddress()));
} catch (URISyntaxException e) {
}
} else if (type.equals(ParsedReaderResultType.TEL)) {
@ -106,7 +109,9 @@ final class ResultHandler extends Handler {
} else if (type.equals(ParsedReaderResultType.GEO)) {
GeoParsedResult geoResult = (GeoParsedResult) result;
try {
intent = new Intent(Intent.VIEW_ACTION, new ContentURI(geoResult.getGeoURI()));
ContentURI geoURI = new ContentURI("geo:" + geoResult.getGeoURI());
Log.v(TAG, "Created geo URI: " + geoURI.toString());
intent = new Intent(Intent.VIEW_ACTION, geoURI);
} catch (URISyntaxException e) {
}
} else if (type.equals(ParsedReaderResultType.UPC)) {