Skip to content

Commit

Permalink
[*] updated code to fix issue #8 , bumped up the version.
Browse files Browse the repository at this point in the history
  • Loading branch information
nisrulz committed May 17, 2016
1 parent 3172e74 commit a55eea8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
22 changes: 10 additions & 12 deletions app/src/main/java/github/nisrulz/projectqreader/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 19 additions & 16 deletions library/src/main/java/github/nisrulz/qreader/QREader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Barcode>() {
@Override public void release() {

}

@Override public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> 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)
Expand All @@ -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<Barcode>() {
@Override public void release() {

}

@Override public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> barcodes = detections.getDetectedItems();
if (barcodes.size() != 0 && qrDataListener != null) {
qrDataListener.onDetected(barcodes.valueAt(0).displayValue);
}
}
});
}
}

@Override public void surfaceDestroyed(SurfaceHolder surfaceHolder) {

stop();
}
};

Expand Down Expand Up @@ -202,7 +205,7 @@ public void stop() {
}

/**
* Release and cleanup qr eader.
* Release and cleanup qreader.
*/
public void releaseAndCleanup() {
stop();
Expand Down

0 comments on commit a55eea8

Please sign in to comment.