mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
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:
parent
87da7e9226
commit
6f4417346c
|
@ -41,6 +41,7 @@ final class CameraManager {
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private Point cameraResolution;
|
private Point cameraResolution;
|
||||||
private Point stillResolution;
|
private Point stillResolution;
|
||||||
|
private Point previewResolution;
|
||||||
private int stillMultiplier;
|
private int stillMultiplier;
|
||||||
private Point screenResolution;
|
private Point screenResolution;
|
||||||
private Rect framingRect;
|
private Rect framingRect;
|
||||||
|
@ -51,8 +52,9 @@ final class CameraManager {
|
||||||
|
|
||||||
CameraManager(Context context) {
|
CameraManager(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
calculateStillResolution();
|
|
||||||
getScreenResolution();
|
getScreenResolution();
|
||||||
|
calculateStillResolution();
|
||||||
|
calculatePreviewResolution();
|
||||||
bitmap = Bitmap.createBitmap(stillResolution.x, stillResolution.y, false);
|
bitmap = Bitmap.createBitmap(stillResolution.x, stillResolution.y, false);
|
||||||
camera = CameraDevice.open();
|
camera = CameraDevice.open();
|
||||||
params = new CameraDevice.CaptureParams();
|
params = new CameraDevice.CaptureParams();
|
||||||
|
@ -63,6 +65,9 @@ final class CameraManager {
|
||||||
public void openDriver() {
|
public void openDriver() {
|
||||||
if (camera == null) {
|
if (camera == null) {
|
||||||
camera = CameraDevice.open();
|
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() {
|
public Rect getFramingRect() {
|
||||||
if (framingRect == null) {
|
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 leftOffset = (screenResolution.x - size) / 2;
|
||||||
int topOffset = (screenResolution.y - size) / 2;
|
int topOffset = (screenResolution.y - size) / 2;
|
||||||
framingRect = new Rect(leftOffset, topOffset, leftOffset + size, topOffset + size);
|
framingRect = new Rect(leftOffset, topOffset, leftOffset + size, topOffset + size);
|
||||||
|
@ -134,18 +139,10 @@ final class CameraManager {
|
||||||
if (on != previewMode) {
|
if (on != previewMode) {
|
||||||
if (on) {
|
if (on) {
|
||||||
params.type = 1; // preview
|
params.type = 1; // preview
|
||||||
if (cameraResolution.x / (float) cameraResolution.y <
|
params.srcWidth = previewResolution.x;
|
||||||
screenResolution.x / (float) screenResolution.y) {
|
params.srcHeight = previewResolution.y;
|
||||||
params.srcWidth = cameraResolution.x;
|
params.leftPixel = (cameraResolution.x - params.srcWidth) / 2;
|
||||||
params.srcHeight = cameraResolution.x * screenResolution.y / screenResolution.x;
|
params.topPixel = (cameraResolution.y - params.srcHeight) / 2;
|
||||||
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.outputWidth = screenResolution.x;
|
params.outputWidth = screenResolution.x;
|
||||||
params.outputHeight = screenResolution.y;
|
params.outputHeight = screenResolution.y;
|
||||||
params.dataFormat = 2; // RGB565
|
params.dataFormat = 2; // RGB565
|
||||||
|
@ -217,6 +214,16 @@ final class CameraManager {
|
||||||
" nativeResolution " + nativeResolution + " stillMultiplier " + stillMultiplier);
|
" 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
|
// FIXME(dswitkin): These three methods have temporary constants until the new Camera API can
|
||||||
// provide the real values for the current device.
|
// provide the real values for the current device.
|
||||||
// Temporary: the camera's maximum resolution in pixels.
|
// Temporary: the camera's maximum resolution in pixels.
|
||||||
|
|
|
@ -21,6 +21,7 @@ import android.net.ContentURI;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.provider.Contacts;
|
import android.provider.Contacts;
|
||||||
|
import android.util.Log;
|
||||||
import com.google.zxing.client.result.AddressBookAUParsedResult;
|
import com.google.zxing.client.result.AddressBookAUParsedResult;
|
||||||
import com.google.zxing.client.result.AddressBookDoCoMoParsedResult;
|
import com.google.zxing.client.result.AddressBookDoCoMoParsedResult;
|
||||||
import com.google.zxing.client.result.BookmarkDoCoMoParsedResult;
|
import com.google.zxing.client.result.BookmarkDoCoMoParsedResult;
|
||||||
|
@ -45,6 +46,8 @@ import java.net.URISyntaxException;
|
||||||
*/
|
*/
|
||||||
final class ResultHandler extends Handler {
|
final class ResultHandler extends Handler {
|
||||||
|
|
||||||
|
private static final String TAG = "ResultHandler";
|
||||||
|
|
||||||
private final Intent intent;
|
private final Intent intent;
|
||||||
private final BarcodeReaderCaptureActivity captureActivity;
|
private final BarcodeReaderCaptureActivity captureActivity;
|
||||||
|
|
||||||
|
@ -94,7 +97,7 @@ final class ResultHandler extends Handler {
|
||||||
} else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
|
} else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
|
||||||
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
|
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
|
||||||
try {
|
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) {
|
} catch (URISyntaxException e) {
|
||||||
}
|
}
|
||||||
} else if (type.equals(ParsedReaderResultType.TEL)) {
|
} else if (type.equals(ParsedReaderResultType.TEL)) {
|
||||||
|
@ -106,7 +109,9 @@ final class ResultHandler extends Handler {
|
||||||
} else if (type.equals(ParsedReaderResultType.GEO)) {
|
} else if (type.equals(ParsedReaderResultType.GEO)) {
|
||||||
GeoParsedResult geoResult = (GeoParsedResult) result;
|
GeoParsedResult geoResult = (GeoParsedResult) result;
|
||||||
try {
|
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) {
|
} catch (URISyntaxException e) {
|
||||||
}
|
}
|
||||||
} else if (type.equals(ParsedReaderResultType.UPC)) {
|
} else if (type.equals(ParsedReaderResultType.UPC)) {
|
||||||
|
|
Loading…
Reference in a new issue