Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Attempt to temporarily fix #249, #287 and #293. Bump to 1.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushyanth Maguluru committed Jul 15, 2017
1 parent e7570a6 commit 5a3ed7c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [1.9.4] - July 15, 2017
* Add ability to customize aspect ratio tolerance that is used in figuring out the optimal camera preview size. This is just a temporary fix for #249,#287,#293

## [1.9.3] - May 27, 2017
* Add ability to customize view finder with custom attributes. See #285 for more info. Thanks to @albinpoignot for the pull request

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Installation

Add the following dependency to your build.gradle file.

`compile 'me.dm7.barcodescanner:zxing:1.9.3'`
`compile 'me.dm7.barcodescanner:zxing:1.9.4'`

Simple Usage
------------
Expand Down Expand Up @@ -126,7 +126,7 @@ Installation

Add the following dependency to your build.gradle file.

`compile 'me.dm7.barcodescanner:zbar:1.9.3'`
`compile 'me.dm7.barcodescanner:zbar:1.9.4'`

Simple Usage
------------
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}

allprojects {
group = 'me.dm7.barcodescanner'
version = '1.9.3'
version = '1.9.4'

repositories {
mavenCentral()
Expand Down Expand Up @@ -44,8 +44,8 @@ subprojects {
defaultConfig {
minSdkVersion versions.min_sdk
targetSdkVersion versions.target_sdk
versionCode 193
versionName "1.9.3"
versionCode 194
versionName "1.9.4"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public abstract class BarcodeScannerView extends FrameLayout implements Camera.P
private boolean mSquaredFinder = false;
private float mBorderAlpha = 1.0f;
private int mViewFinderOffset = 0;
private float mAspectTolerance = 0.1f;

public BarcodeScannerView(Context context) {
super(context);
Expand Down Expand Up @@ -77,6 +78,7 @@ public final void setupLayout(CameraWrapper cameraWrapper) {
removeAllViews();

mPreview = new CameraPreview(getContext(), cameraWrapper, this);
mPreview.setAspectTolerance(mAspectTolerance);
mPreview.setShouldScaleToFill(mShouldScaleToFill);
if (!mShouldScaleToFill) {
RelativeLayout relativeLayout = new RelativeLayout(getContext());
Expand Down Expand Up @@ -298,5 +300,9 @@ public void setAutoFocus(boolean state) {
public void setShouldScaleToFill(boolean shouldScaleToFill) {
mShouldScaleToFill = shouldScaleToFill;
}

public void setAspectTolerance(float aspectTolerance) {
mAspectTolerance = aspectTolerance;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
private boolean mSurfaceCreated = false;
private boolean mShouldScaleToFill = true;
private Camera.PreviewCallback mPreviewCallback;
private float mAspectTolerance = 0.1f;

public CameraPreview(Context context, CameraWrapper cameraWrapper, Camera.PreviewCallback previewCallback) {
super(context);
Expand Down Expand Up @@ -54,6 +55,10 @@ public void setShouldScaleToFill(boolean scaleToFill) {
mShouldScaleToFill = scaleToFill;
}

public void setAspectTolerance(float aspectTolerance) {
mAspectTolerance = aspectTolerance;
}

@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
mSurfaceCreated = true;
Expand Down Expand Up @@ -235,7 +240,6 @@ private Camera.Size getOptimalPreviewSize() {
w = portraitWidth;
}

final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) w / h;
if (sizes == null) return null;

Expand All @@ -247,7 +251,7 @@ private Camera.Size getOptimalPreviewSize() {
// Try to find an size match aspect ratio and size
for (Camera.Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(ratio - targetRatio) > mAspectTolerance) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
Expand Down
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext.versions = [
build_tools : "25.0.2",
support_lib : "25.3.1",
zxing : "3.3.0",
barcodescanner: "1.9.3"
barcodescanner: "1.9.4"
]

ext.libraries = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public void onCreate(Bundle state) {
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this);
// You can optionally set aspect ratio tolerance level
// that is used in calculating the optimal Camera preview size
mScannerView.setAspectTolerance(0.2f);
mScannerView.startCamera();
mScannerView.setFlash(mFlash);
}
Expand Down

0 comments on commit 5a3ed7c

Please sign in to comment.