Skip to content

Commit

Permalink
Updated camera state handling to be more robust when rapid start()+st…
Browse files Browse the repository at this point in the history
…op() sequences occur - whivh happens a lot in the FastBarcodeScannerPlugin project
  • Loading branch information
tschaumburg committed Jan 3, 2016
1 parent 4896931 commit bbaf245
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 61 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

// To release, run
// gradlew clean build bintrayUpload -PbintrayUser=tschaumburg -PbintrayKey=xxxxxxxxxxxxxxxxxx -PdryRun=false
// where xxxxxxxxxxx is retrieved from
// https://bintray.com/profile/edit
// under "API Key"
ext {
VERSION_NAME = '1.0.5'
VERSION_NAME = '1.0.7'
}

buildscript {
Expand Down
2 changes: 1 addition & 1 deletion fast-barcode-scanner-demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:support-v13:23.1.0'
//compile 'dk.schaumburgit.fast-barcode-scanner:fast-barcode-scanner:1.0.4'
//compile 'dk.schaumburgit.fast-barcode-scanner:fast-barcode-scanner:1.0.7'
compile project(':fast-barcode-scanner')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public void onClick(View view) {
}
});

Button pauseResumeButton = (Button)findViewById(R.id.pauseresume);
pauseResumeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pauseResume();
}
});

//mSurfaceView = (SurfaceView)findViewById(R.id.preview);
//mTextureView = (TextureView)findViewById(R.id.preview2);
mImageView = (ImageView)findViewById(R.id.imageview);
Expand Down Expand Up @@ -96,6 +104,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

private void pauseResume() {
// like pause:
mScanner.StopScan();
// like resume:
mScanner.StartScan(false, this, null);
}

FastBarcodeScanner mScanner = null;
private void startScan() {
requestCameraPermission();
Expand All @@ -109,19 +124,23 @@ private void startScan() {

Button startButton = (Button)findViewById(R.id.start);
Button stopButton = (Button)findViewById(R.id.button3);
Button pauseResumeButton = (Button)findViewById(R.id.pauseresume);

startButton.setEnabled(false);
mScanner.setLockFocus(true);
//mScanner.setIncludeImagesInCallback(true);
mScanner.StartMultiScan(true, this, null);
stopButton.setEnabled(true);
pauseResumeButton.setEnabled(true);
}

private void stopScan() {
Button startButton = (Button)findViewById(R.id.start);
Button stopButton = (Button)findViewById(R.id.button3);
Button pauseResumeButton = (Button)findViewById(R.id.pauseresume);

stopButton.setEnabled(false);
pauseResumeButton.setEnabled(false);
mScanner.StopScan();
startButton.setEnabled(true);
}
Expand Down
12 changes: 11 additions & 1 deletion fast-barcode-scanner-demo/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,21 @@
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:text="Stop scan"
android:layout_above="@+id/start"
android:layout_above="@+id/pauseresume"
android:layout_alignParentStart="true"
android:background="@android:color/darker_gray"
android:enabled="false"
android:id="@+id/button3" />
<Button
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:text="Pause+resume"
android:layout_above="@+id/start"
android:layout_alignParentStart="true"
android:background="@android:color/darker_gray"
android:enabled="false"
android:id="@+id/pauseresume" />
<Button
android:layout_width="fill_parent"
android:layout_height="50dp"
Expand Down
5 changes: 3 additions & 2 deletions fast-barcode-scanner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.zxing:core:3.2.1'
testCompile 'junit:junit:4.12'
//compile 'dk.schaumburgit.fast-barcode-scanner:still-sequence-camera:1.0.4'
//compile 'dk.schaumburgit.fast-barcode-scanner:tracking-barcode-scanner:1.0.4'
//compile 'dk.schaumburgit.fast-barcode-scanner:still-sequence-camera:1.0.7'
//Scompile 'dk.schaumburgit.fast-barcode-scanner:tracking-barcode-scanner:1.0.7'
compile project(':still-sequence-camera')
compile project(':tracking-barcode-scanner')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,21 @@ public void StartScan(final boolean includeImagesInCallback, final BarcodeDetect

@Override
public void onImageAvailable(Image image) {
processSingleImage(image, includeImagesInCallback, listener, finalHandler);
if (mPaused)
image.close();
else
processSingleImage(image, includeImagesInCallback, listener, finalHandler);
}

@Override
public void onJpegImageAvailable(byte[] jpegData, int width, int height) {
processSingleJpeg(jpegData, width, height, includeImagesInCallback, listener, finalHandler);
if (!mPaused)
processSingleJpeg(jpegData, width, height, includeImagesInCallback, listener, finalHandler);
}

@Override
public void onError(Exception error) {
if (!mPaused)
FastBarcodeScanner.this.onError(error, listener, finalHandler);
}

Expand Down Expand Up @@ -278,24 +283,40 @@ public void StartMultiScan(final boolean includeImagesInCallback, final Multiple

@Override
public void onImageAvailable(Image source) {
processMultiImage(source, includeImagesInCallback, listener, finalHandler);
if (mPaused)
source.close();
else
processMultiImage(source, includeImagesInCallback, listener, finalHandler);
}

@Override
public void onJpegImageAvailable(byte[] jpegData, int width, int height) {
processMultiJpeg(jpegData, width, height, includeImagesInCallback, listener, finalHandler);
if (!mPaused)
processMultiJpeg(jpegData, width, height, includeImagesInCallback, listener, finalHandler);
}

@Override
public void onError(Exception error) {
FastBarcodeScanner.this.onError(error, listener, finalHandler);
if (!mPaused)
FastBarcodeScanner.this.onError(error, listener, finalHandler);
}

},
mProcessingHandler
);
}

private boolean mPaused = false;
public void Pause()
{
mPaused = true;
}

public void Resume()
{
mPaused = false;
}

/**
* Stops the scanning process started by StartScan() or StartMultiScan() and frees any shared system resources
* (e.g. the camera). StartScan() or StartMultiScan() can always be called to restart.
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
include ':tracking-barcode-scanner', ':still-sequence-camera', ':fast-barcode-scanner', ':fast-barcode-scanner-demo'
//include ':tracking-barcode-scanner', ':still-sequence-camera'
//include ':fast-barcode-scanner'
//include ':fast-barcode-scanner-demo'
1 change: 1 addition & 0 deletions still-sequence-camera/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'org.jdeferred:jdeferred-core:1.2.4'
testCompile 'junit:junit:4.12'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package dk.schaumburgit.stillsequencecamera;

import android.app.Activity;
import android.media.Image;
import android.os.Handler;
import android.view.TextureView;

import java.io.IOException;
import java.util.Map;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ public void run() {
}
} catch (CameraAccessException e)
{
throw new UnsupportedOperationException("Camera access required");
e.printStackTrace();
throw new UnsupportedOperationException("Camera access required 3");
}
}

Expand All @@ -610,7 +611,8 @@ public void run() {
}
} catch (CameraAccessException e)
{
throw new UnsupportedOperationException("Camera access required");
e.printStackTrace();
throw new UnsupportedOperationException("Camera access required 4");
}
}
}
Expand Down
Loading

0 comments on commit bbaf245

Please sign in to comment.