From bbaf2452b06142f5068c212954e6c0aa10f97ee1 Mon Sep 17 00:00:00 2001 From: tschaumburg Date: Sun, 3 Jan 2016 17:03:04 +0100 Subject: [PATCH] Updated camera state handling to be more robust when rapid start()+stop() sequences occur - whivh happens a lot in the FastBarcodeScannerPlugin project --- build.gradle | 8 +- fast-barcode-scanner-demo/build.gradle | 2 +- .../fastbarcodescannerdemo/MainActivity.java | 19 +++ .../src/main/res/layout/content_main.xml | 12 +- fast-barcode-scanner/build.gradle | 5 +- .../FastBarcodeScanner.java | 31 +++- settings.gradle | 3 + still-sequence-camera/build.gradle | 1 + .../IStillSequenceCamera.java | 4 - .../camera2/FocusManager.java | 6 +- .../camera2/StillSequenceCamera2.java | 135 ++++++++++++------ 11 files changed, 165 insertions(+), 61 deletions(-) diff --git a/build.gradle b/build.gradle index 886383c..eb1871d 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/fast-barcode-scanner-demo/build.gradle b/fast-barcode-scanner-demo/build.gradle index a05fe39..88276ab 100644 --- a/fast-barcode-scanner-demo/build.gradle +++ b/fast-barcode-scanner-demo/build.gradle @@ -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') } diff --git a/fast-barcode-scanner-demo/src/main/java/dk/schaumburgit/fastbarcodescannerdemo/MainActivity.java b/fast-barcode-scanner-demo/src/main/java/dk/schaumburgit/fastbarcodescannerdemo/MainActivity.java index 6987be1..82a341c 100644 --- a/fast-barcode-scanner-demo/src/main/java/dk/schaumburgit/fastbarcodescannerdemo/MainActivity.java +++ b/fast-barcode-scanner-demo/src/main/java/dk/schaumburgit/fastbarcodescannerdemo/MainActivity.java @@ -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); @@ -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(); @@ -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); } diff --git a/fast-barcode-scanner-demo/src/main/res/layout/content_main.xml b/fast-barcode-scanner-demo/src/main/res/layout/content_main.xml index e2ab35c..2d1fa02 100644 --- a/fast-barcode-scanner-demo/src/main/res/layout/content_main.xml +++ b/fast-barcode-scanner-demo/src/main/res/layout/content_main.xml @@ -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" /> +