Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android-test and android-integration #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Iterator;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
Expand All @@ -31,6 +33,8 @@
import android.net.Uri;
import android.util.Log;



/**
* <p>A utility class which helps ease integration with Barcode Scanner via {@link Intent}s. This is a simple
* way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the
Expand Down Expand Up @@ -245,6 +249,39 @@ public AlertDialog initiateScan(Collection<String> desiredBarcodeFormats) {
startActivityForResult(intentScan, REQUEST_CODE);
return null;
}
public AlertDialog initiateScan(Collection<String> desiredBarcodeFormats, Bundle extras) {
Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");
intentScan.addCategory(Intent.CATEGORY_DEFAULT);

// check which types of codes to scan for
if (desiredBarcodeFormats != null) {
// set the desired barcode types
StringBuilder joinedByComma = new StringBuilder();
for (String format : desiredBarcodeFormats) {
if (joinedByComma.length() > 0) {
joinedByComma.append(',');
}
joinedByComma.append(format);
}
intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
}
/*String key;
for (Iterator i = extras.keySet.Iterator(); i.hasNext();) {
key = extras.keySet(i) ;
intentScan.putExtra(key,extras.get(key));
}
*/
intentScan.putExtras(extras);
String targetAppPackage = findTargetAppPackage(intentScan);
if (targetAppPackage == null) {
return showDownloadDialog();
}
intentScan.setPackage(targetAppPackage);
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivityForResult(intentScan, REQUEST_CODE);
return null;
}

/**
* Start an activity.<br>
Expand Down Expand Up @@ -341,6 +378,38 @@ public void shareText(CharSequence text) {
intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
intent.putExtra("ENCODE_DATA", text);
String targetAppPackage = findTargetAppPackage(intent);
if (targetAppPackage == null) {
showDownloadDialog();
} else {
intent.setPackage(targetAppPackage);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
activity.startActivity(intent);
}
}
public void shareText(String type, String data) {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setAction(BS_PACKAGE + ".ENCODE");
intent.putExtra("ENCODE_TYPE", type);
intent.putExtra("ENCODE_DATA", data);
String targetAppPackage = findTargetAppPackage(intent);
if (targetAppPackage == null) {
showDownloadDialog();
} else {
intent.setPackage(targetAppPackage);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
activity.startActivity(intent);
}
}
public void shareText(String type,Bundle data) {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setAction(BS_PACKAGE + ".ENCODE");
intent.putExtra("ENCODE_TYPE", type);
intent.putExtra("ENCODE_DATA", data);
String targetAppPackage = findTargetAppPackage(intent);
if (targetAppPackage == null) {
showDownloadDialog();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.ArrayList;

public final class ZXingTestActivity extends Activity {

Expand Down Expand Up @@ -138,13 +139,16 @@ public void onClick(View v) {
private final Button.OnClickListener scanProduct = new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
intent.putExtra("SCAN_WIDTH", 800);
intent.putExtra("SCAN_HEIGHT", 200);
intent.putExtra("RESULT_DISPLAY_DURATION_MS", 3000L);
intent.putExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
startActivityForResult(intent, IntentIntegrator.REQUEST_CODE);
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
ArrayList<String> scanModes = new ArrayList<String>();
scanModes.add("PRODUCT");

Bundle extras = new Bundle();
extras.putInt("SCAN_WIDTH",800);
extras.putInt("SCAN_HEIGHT",200);
extras.putLong("RESULT_DISPLAY_DURATION_ms",3000L);
extras.putString("PROMPT_MESSAGE","Custom prompt to scan a product");
integrator.initiateScan(scanModes,extras);
}
};

Expand Down Expand Up @@ -258,17 +262,13 @@ private void showDialog(int title, CharSequence message) {
}

private void encodeBarcode(String type, String data) {
Intent intent = new Intent("com.google.zxing.client.android.ENCODE");
intent.putExtra("ENCODE_TYPE", type);
intent.putExtra("ENCODE_DATA", data);
startActivity(intent);
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
integrator.shareText(type,data);
}

private void encodeBarcode(String type, Bundle data) {
Intent intent = new Intent("com.google.zxing.client.android.ENCODE");
intent.putExtra("ENCODE_TYPE", type);
intent.putExtra("ENCODE_DATA", data);
startActivity(intent);
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
integrator.shareText(type,data);
}

private static String getFlattenedParams() {
Expand Down