diff --git a/README.md b/README.md index 8adf8df..de38f60 100755 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Android library using google's mobile vision api to read QR Code #Integration - QREader is available in the MavenCentral, so getting it as simple as adding it as a dependency ```gradle -compile 'com.github.nisrulz:qreader:1.0.3' +compile 'com.github.nisrulz:qreader:1.0.4' ``` #Usage diff --git a/app/build.gradle b/app/build.gradle index f07e9cc..418a43a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,6 +38,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.3.0' + compile 'com.android.support:appcompat-v7:23.4.0' compile project(':library') } diff --git a/app/src/main/java/github/nisrulz/projectqreader/MainActivity.java b/app/src/main/java/github/nisrulz/projectqreader/MainActivity.java index 4e2b23d..62eda69 100644 --- a/app/src/main/java/github/nisrulz/projectqreader/MainActivity.java +++ b/app/src/main/java/github/nisrulz/projectqreader/MainActivity.java @@ -17,10 +17,10 @@ package github.nisrulz.projectqreader; import android.os.Bundle; +import android.os.PersistableBundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.SurfaceView; -import android.widget.Button; import android.widget.TextView; import github.nisrulz.qreader.QRDataListener; import github.nisrulz.qreader.QREader; @@ -29,8 +29,6 @@ public class MainActivity extends AppCompatActivity { private SurfaceView surfaceView; private TextView textView_qrcode_info; - private Button btn_toggle; - private boolean isRunning = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -53,24 +51,24 @@ public class MainActivity extends AppCompatActivity { QREader.getInstance().init(this, surfaceView); } - @Override protected void onResume() { - super.onResume(); + @Override public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { + super.onSaveInstanceState(outState, outPersistentState); + } - QREader.getInstance().start(); - isRunning = true; + @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); } - @Override protected void onPause() { - super.onPause(); + @Override protected void onStart() { + super.onStart(); - QREader.getInstance().stop(); - isRunning = false; + QREader.getInstance().start(); } @Override protected void onDestroy() { super.onDestroy(); + QREader.getInstance().stop(); QREader.getInstance().releaseAndCleanup(); - isRunning = false; } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cdbac48..ed96b98 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -19,4 +19,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip diff --git a/library/build.gradle b/library/build.gradle index 79d4ff8..2f2300a 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -25,8 +25,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 23 - versionCode 4 - versionName "1.0.3" + versionCode 5 + versionName "1.0.4" consumerProguardFiles 'consumer-proguard-rules.pro' } buildTypes { diff --git a/library/src/main/java/github/nisrulz/qreader/QREader.java b/library/src/main/java/github/nisrulz/qreader/QREader.java index dfc184a..e9b0a94 100644 --- a/library/src/main/java/github/nisrulz/qreader/QREader.java +++ b/library/src/main/java/github/nisrulz/qreader/QREader.java @@ -115,11 +115,28 @@ public void init(final Context context, final SurfaceView surfaceView) { this.context = context; this.surfaceView = surfaceView; + // Setup Barcodedetector if (barcodeDetector == null) { barcodeDetector = new BarcodeDetector.Builder(context).setBarcodeFormats(Barcode.QR_CODE).build(); + + if (barcodeDetector.isOperational()) { + barcodeDetector.setProcessor(new Detector.Processor() { + @Override public void release() { + + } + + @Override public void receiveDetections(Detector.Detections detections) { + final SparseArray barcodes = detections.getDetectedItems(); + if (barcodes.size() != 0 && qrDataListener != null) { + qrDataListener.onDetected(barcodes.valueAt(0).displayValue); + } + } + }); + } } + // Setup Camera if (cameraSource == null) { cameraSource = new CameraSource.Builder(context, barcodeDetector).setAutoFocusEnabled(autofocus_enabled) @@ -144,24 +161,10 @@ public void start() { } @Override public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) { - if (barcodeDetector.isOperational()) { - barcodeDetector.setProcessor(new Detector.Processor() { - @Override public void release() { - - } - - @Override public void receiveDetections(Detector.Detections detections) { - final SparseArray barcodes = detections.getDetectedItems(); - if (barcodes.size() != 0 && qrDataListener != null) { - qrDataListener.onDetected(barcodes.valueAt(0).displayValue); - } - } - }); - } } @Override public void surfaceDestroyed(SurfaceHolder surfaceHolder) { - + stop(); } }; @@ -202,7 +205,7 @@ public void stop() { } /** - * Release and cleanup qr eader. + * Release and cleanup qreader. */ public void releaseAndCleanup() { stop();