Skip to content

Commit

Permalink
supporting multiple barcode format and adding failure callback for ba…
Browse files Browse the repository at this point in the history
…rcodeRetriever
  • Loading branch information
KingsMentor committed Oct 11, 2016
1 parent f567772 commit 45de971
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// use a compound button so either checkbox or switch widgets work.


private static final int RC_BARCODE_CAPTURE = 9001;
private static final String TAG = "BarcodeMain";

@Override
Expand All @@ -49,7 +48,6 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);



BarcodeCapture barcodeCapture = (BarcodeCapture) getSupportFragmentManager().findFragmentById(R.id.barcode);
barcodeCapture.setRetrieval(this);

Expand All @@ -67,12 +65,19 @@ public void onClick(View v) {


@Override
public void onRetrieved(Barcode barcode) {
public void onRetrieved(final Barcode barcode) {
Log.d(TAG, "Barcode read: " + barcode.displayValue);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle("code retrieved")
.setMessage(barcode.displayValue);
builder.show();
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
.setTitle("code retrieved")
.setMessage(barcode.displayValue);
builder.show();
}
});


}

@Override
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<fragment
android:id="@+id/barcode"
class="com.google.android.gms.samples.vision.barcodereader.BarcodeCapture"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:gvb_auto_focus="true"
app:gvb_flash="false" />
Expand Down Expand Up @@ -42,7 +42,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_weight="1"
android:text="flash" />
android:text="draw rect" />


</LinearLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public void draw(Canvas canvas) {
rect.top = translateY(rect.top);
rect.right = translateX(rect.right);
rect.bottom = translateY(rect.bottom);
canvas.drawRect(rect, mRectPaint);
if (graphicOverlay.isDrawRect())
canvas.drawRect(rect, mRectPaint);

// Draws a label at the bottom of the barcode indicate the barcode value that was detected.
if (graphicOverlay.isShowText())
Expand Down

0 comments on commit 45de971

Please sign in to comment.