Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  [+] added the optional calls to builder in sample app
  [*] updated readme to specify optional tag
  [*] updated Readme and constant reference
  [*] bumped up version of mobile-vision lib to v9.0.0 and of the lib to v.1.0.5
  [+] added builder pattern to eliminate multiple confusing constructors. [*] fixed a setProcessor issue [-] QREader is no more a singleton, the dev needs to implement that as per their use-case
  • Loading branch information
nisrulz committed May 23, 2016
2 parents 354b58d + b555943 commit b1188ab
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 157 deletions.
146 changes: 89 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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.4'
compile 'com.github.nisrulz:qreader:1.0.5'
```

#Usage
Expand All @@ -24,76 +24,108 @@ compile 'com.github.nisrulz:qreader:1.0.4'
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.camera_view);
```

+ Next setup the config with `QRDataListener` as the last argument in any of the `setConfig()` calls
+ The default config uses autofocus, back camera and preview size set at 800x800 and is referenced as below
+ Next create an object of `QREader` using the `Builder` in your `onCreate()`
```java
QREader.getInstance().setUpConfig(new QRDataListener() {
@Override
public void onDetected(final String data) {
Log.d("QREader", "Value : " + data);

// Post data on UI Thread
textView_qrcode_info.post(new Runnable() {
@Override
public void run() {
textView_qrcode_info.setText(data);
}
});
}
});
QREader qrEader;
.
..
...
@Override protected void onCreate(Bundle savedInstanceState) {
..

surfaceView = (SurfaceView) findViewById(R.id.camera_view);

qrEader = new QREader.Builder(this, surfaceView, new QRDataListener() {
@Override public void onDetected(final String data) {
// Do something with the string data

Log.d("QREader", "Value : " + data);
}
}).build();
}
```

+ There are other config methods to give you more granular configurations
*where*
+ `Builder` takes in arguments as `Builder(context, surfaceview, qrdatalistner)`
+ **[Optional]** To modify further you can call below functions on the `Builder` before calling the `build()`
+ `enableAutofocus(boolean autofocus_enabled)` // Default is `true`
+ `width(int width)` // Default is `800`
+ `height(int height)` // Default is `800`
+ `facing(int facing)` // Default is `QREader.BACK_CAM`
+ where argument can be one of `QREader.BACK_CAM` , `QREader.FRONT_CAM`

+ Next Call ` qrEader.init()`, right after you `build()` your object using the `Builder`.
```java
// Disable/Enable autofocus
// Choose between Front facing or Back facing camera | Possible arguments : CameraSource.CAMERA_FACING_BACK / CameraSource.CAMERA_FACING_FRONT
public void setUpConfig(boolean autofocus_enabled, int facing, QRDataListener qrDataListener) {
// Change all the config values
public void setUpConfig(boolean autofocus_enabled, int width, int height, int facing, QRDataListener qrDataListener) {
```

+ Call `QREader.getInstance().init()` with required arguments in your Activity code, to start reading QR code.
```java
QREader.getInstance().init(this, surfaceView);
```

*where*

|argument|type|
|---|---|
|this|`Context`|
|surfaceView|`SurfaceView`|

@Override protected void onCreate(Bundle savedInstanceState) {
..

qrEader = new QREader.Builder(this, surfaceView, new QRDataListener() {
@Override public void onDetected(final String data) {
..
}
}).build();

// Call Init
qrEader.init();
}
```

+ To start QR code detection
+ To start QR code detection, call `start()` on the `qreader` object
```java
QREader.getInstance().start();
qrEader.start();
```
+ To stop QR code detection
+ To stop QR code detection, call `stop()` on the `qreader` object
```java
QREader.getInstance().stop();
qrEader.stop();
```
+ To `releaseAndCleanup` by QREader
+ To release and cleanup , call `releaseAndCleanup()` on the `qreader` object
```java
QREader.getInstance().releaseAndCleanup();
qrEader.releaseAndCleanup();
```

A typical use case would be , which works well with locking your device and when the app goes into background and then comes back in foreground
```java
@Override protected void onStart() {
super.onStart();

// Call in onStart
QREader.getInstance().start();
}

@Override protected void onDestroy() {
super.onDestroy();

// Call in onDestroy
QREader.getInstance().stop();
QREader.getInstance().releaseAndCleanup();
}
private SurfaceView surfaceView;
private TextView textView_qrcode_info;
QREader qrEader;

@Override protected void onCreate(Bundle savedInstanceState) {
...
...

surfaceView = (SurfaceView) findViewById(R.id.camera_view);
textView_qrcode_info = (TextView) findViewById(R.id.code_info);

qrEader = new QREader.Builder(this, surfaceView, new QRDataListener() {
@Override public void onDetected(final String data) {
Log.d("QREader", "Value : " + data);
textView_qrcode_info.post(new Runnable() {
@Override public void run() {
textView_qrcode_info.setText(data);
}
});
}
}).build();

qrEader.init();
}

@Override protected void onStart() {
super.onStart();
...

// Call in onStart
qrEader.start();
}

@Override protected void onDestroy() {
super.onDestroy();
..

// Call in onDestroy
qrEader.stop();
qrEader.releaseAndCleanup();
}
```


Expand Down
17 changes: 11 additions & 6 deletions app/src/main/java/github/nisrulz/projectqreader/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MainActivity extends AppCompatActivity {

private SurfaceView surfaceView;
private TextView textView_qrcode_info;
QREader qrEader;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -36,7 +37,7 @@ public class MainActivity extends AppCompatActivity {
surfaceView = (SurfaceView) findViewById(R.id.camera_view);
textView_qrcode_info = (TextView) findViewById(R.id.code_info);

QREader.getInstance().setUpConfig(new QRDataListener() {
qrEader = new QREader.Builder(this, surfaceView, new QRDataListener() {
@Override public void onDetected(final String data) {
Log.d("QREader", "Value : " + data);
textView_qrcode_info.post(new Runnable() {
Expand All @@ -45,23 +46,27 @@ public class MainActivity extends AppCompatActivity {
}
});
}
});
}).facing(QREader.BACK_CAM)
.enableAutofocus(true)
.height(800)
.width(800)
.build();

QREader.getInstance().init(this, surfaceView);
qrEader.init();
}

@Override protected void onStart() {
super.onStart();

// Call in onStart
QREader.getInstance().start();
qrEader.start();
}

@Override protected void onDestroy() {
super.onDestroy();

// Call in onDestroy
QREader.getInstance().stop();
QREader.getInstance().releaseAndCleanup();
qrEader.stop();
qrEader.releaseAndCleanup();
}
}
6 changes: 3 additions & 3 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 5
versionName "1.0.4"
versionCode 6
versionName "1.0.5"
consumerProguardFiles 'consumer-proguard-rules.pro'
}
buildTypes {
Expand All @@ -40,7 +40,7 @@ android {
dependencies {
testCompile 'junit:junit:4.12'
// Add Vision API
compile "com.google.android.gms:play-services-vision:8.4.0"
compile "com.google.android.gms:play-services-vision:9.0.0"
}

// Place this in the 'build.gradle' of the library module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

public interface QRDataListener {

void onDetected(String data);
void onDetected(final String data);
}
Loading

0 comments on commit b1188ab

Please sign in to comment.