summaryrefslogtreecommitdiff
path: root/sample/src/main/java/example/zxing/CustomCaptureActivity.java
diff options
context:
space:
mode:
authorRalf Kistner <ralf@embarkmobile.com>2015-04-04 18:17:16 +0300
committerRalf Kistner <ralf@embarkmobile.com>2015-04-04 18:32:24 +0300
commitefdb192aa68a5a1a027a75cb73b80dd2c64a9bec (patch)
treedfa396f39afa2fb7d46361da5f2f6d12d43716ec /sample/src/main/java/example/zxing/CustomCaptureActivity.java
parent3e74da3f7abb118616d5251f6d32a4f55a18b99b (diff)
downloadzxing-android-embedded-efdb192aa68a5a1a027a75cb73b80dd2c64a9bec.tar.xz
New CaptureActivity.
Diffstat (limited to 'sample/src/main/java/example/zxing/CustomCaptureActivity.java')
-rw-r--r--sample/src/main/java/example/zxing/CustomCaptureActivity.java113
1 files changed, 113 insertions, 0 deletions
diff --git a/sample/src/main/java/example/zxing/CustomCaptureActivity.java b/sample/src/main/java/example/zxing/CustomCaptureActivity.java
new file mode 100644
index 00000000..dd2abedd
--- /dev/null
+++ b/sample/src/main/java/example/zxing/CustomCaptureActivity.java
@@ -0,0 +1,113 @@
+package example.zxing;
+
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+
+import com.google.zxing.Result;
+import com.google.zxing.ResultPoint;
+import com.journeyapps.barcodescanner.BarcodeCallback;
+import com.journeyapps.barcodescanner.BarcodeView;
+import com.journeyapps.barcodescanner.ViewfinderView;
+
+import java.util.List;
+
+/**
+ *
+ */
+public class CustomCaptureActivity extends Activity {
+ private static final String TAG = CustomCaptureActivity.class.getSimpleName();
+ private BarcodeView barcodeView;
+ private ViewfinderView viewFinder;
+
+ private BarcodeCallback callback = new BarcodeCallback() {
+ @Override
+ public void barcodeResult(Result result) {
+// TextView text = (TextView)findViewById(R.id.zxing_barcode_status);
+// if(result.getText() != null) {
+// text.setText(result.getText());
+// }
+ }
+
+ @Override
+ public void possibleResultPoints(List<ResultPoint> resultPoints) {
+ for (ResultPoint point : resultPoints) {
+ viewFinder.addPossibleResultPoint(point);
+ }
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.new_custom_layout);
+
+ barcodeView = (BarcodeView) findViewById(R.id.zxing_barcode_surface);
+ barcodeView.decodeContinuous(callback);
+
+ viewFinder = (ViewfinderView)findViewById(R.id.zxing_viewfinder_view);
+ viewFinder.setCameraPreview(barcodeView);
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+ Log.d(TAG, "Configuration changed");
+
+ }
+
+ private void orientationChanged() {
+ barcodeView.pause();
+ barcodeView.resume();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ barcodeView.resume();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+
+ barcodeView.pause();
+ }
+
+ public void pause(View view) {
+ barcodeView.pause();
+ }
+
+ public void resume(View view) {
+ barcodeView.resume();
+ }
+
+ public void triggerScan(View view) {
+ barcodeView.decodeSingle(callback);
+ }
+
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_FOCUS:
+ case KeyEvent.KEYCODE_CAMERA:
+ // Handle these events so they don't launch the Camera app
+ return true;
+ // Use volume up/down to turn on light
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ barcodeView.setTorch(false);
+ return true;
+ case KeyEvent.KEYCODE_VOLUME_UP:
+ barcodeView.setTorch(true);
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+}