summaryrefslogtreecommitdiff
path: root/sample/src
diff options
context:
space:
mode:
authorRalf Kistner <ralf@embarkmobile.com>2015-05-03 20:26:52 +0300
committerRalf Kistner <ralf@embarkmobile.com>2015-05-03 20:26:52 +0300
commitd281cb0a1a701dc5eea2db1c807c8419cd73d326 (patch)
tree8952eb7317e32eaf4d7ef468596d5032aa03f380 /sample/src
parentcfddf30f0df822fa4f982fe650bb3aa385c9ac36 (diff)
parent4dd4d582957e6b04691658b3675f959ba900867e (diff)
downloadzxing-android-embedded-d281cb0a1a701dc5eea2db1c807c8419cd73d326.tar.xz
Merge branch '3.x' of github.com:journeyapps/zxing-android-embedded into 3.x
Diffstat (limited to 'sample/src')
-rw-r--r--sample/src/main/AndroidManifest.xml13
-rw-r--r--sample/src/main/java/example/zxing/AnyOrientationCaptureActivity.java11
-rw-r--r--sample/src/main/java/example/zxing/CaptureActivityAnyOrientation.java10
-rw-r--r--sample/src/main/java/example/zxing/ContinuousCaptureActivity.java83
-rw-r--r--sample/src/main/java/example/zxing/CustomCaptureActivity.java119
-rw-r--r--sample/src/main/java/example/zxing/MainActivity.java15
-rw-r--r--sample/src/main/java/example/zxing/ToolbarCaptureActivity.java69
-rw-r--r--sample/src/main/res/layout/activity_main.xml73
-rw-r--r--sample/src/main/res/layout/capture_appcompat.xml37
-rw-r--r--sample/src/main/res/layout/continuous_scan.xml (renamed from sample/src/main/res/layout/new_custom_layout.xml)24
-rw-r--r--sample/src/main/res/values-v21/styles.xml7
-rw-r--r--sample/src/main/res/values/strings.xml5
-rw-r--r--sample/src/main/res/values/styles.xml8
13 files changed, 286 insertions, 188 deletions
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 774ce8b7..1c87c9be 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -17,17 +17,26 @@
</intent-filter>
</activity>
- <activity android:name=".CustomCaptureActivity">
+ <activity android:name=".ContinuousCaptureActivity">
</activity>
- <activity android:name=".CaptureActivityAnyOrientation"
+ <activity android:name=".AnyOrientationCaptureActivity"
android:screenOrientation="fullSensor"
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>
+
+
+ <activity android:name=".ToolbarCaptureActivity"
+ android:clearTaskOnLaunch="true"
+ android:screenOrientation="sensorLandscape"
+ android:stateNotNeeded="true"
+ android:theme="@style/AppCompatCaptureTheme"
+ android:windowSoftInputMode="stateAlwaysHidden">
+ </activity>
</application>
</manifest>
diff --git a/sample/src/main/java/example/zxing/AnyOrientationCaptureActivity.java b/sample/src/main/java/example/zxing/AnyOrientationCaptureActivity.java
new file mode 100644
index 00000000..34393c51
--- /dev/null
+++ b/sample/src/main/java/example/zxing/AnyOrientationCaptureActivity.java
@@ -0,0 +1,11 @@
+package example.zxing;
+
+import com.journeyapps.barcodescanner.CaptureActivity;
+
+/**
+ * This Activity is exactly the same as CaptureActivity, but has a different orientation
+ * setting in AndroidManifest.xml.
+ */
+public class AnyOrientationCaptureActivity extends CaptureActivity {
+
+}
diff --git a/sample/src/main/java/example/zxing/CaptureActivityAnyOrientation.java b/sample/src/main/java/example/zxing/CaptureActivityAnyOrientation.java
deleted file mode 100644
index 6be3a3e9..00000000
--- a/sample/src/main/java/example/zxing/CaptureActivityAnyOrientation.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package example.zxing;
-
-import com.journeyapps.barcodescanner.CaptureActivity;
-
-/**
- *
- */
-public class CaptureActivityAnyOrientation extends CaptureActivity {
-
-}
diff --git a/sample/src/main/java/example/zxing/ContinuousCaptureActivity.java b/sample/src/main/java/example/zxing/ContinuousCaptureActivity.java
new file mode 100644
index 00000000..783eb892
--- /dev/null
+++ b/sample/src/main/java/example/zxing/ContinuousCaptureActivity.java
@@ -0,0 +1,83 @@
+package example.zxing;
+
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.widget.ImageView;
+
+import com.google.zxing.ResultPoint;
+import com.journeyapps.barcodescanner.BarcodeCallback;
+import com.journeyapps.barcodescanner.BarcodeResult;
+import com.journeyapps.barcodescanner.CompoundBarcodeView;
+
+import java.util.List;
+
+/**
+ * This sample performs continuous scanning, displaying the barcode and source image whenever
+ * a barcode is scanned.
+ */
+public class ContinuousCaptureActivity extends Activity {
+ private static final String TAG = ContinuousCaptureActivity.class.getSimpleName();
+ private CompoundBarcodeView barcodeView;
+
+ private BarcodeCallback callback = new BarcodeCallback() {
+ @Override
+ public void barcodeResult(BarcodeResult result) {
+ if (result.getText() != null) {
+ barcodeView.setStatusText(result.getText());
+ }
+ //Added preview of scanned barcode
+ ImageView imageView = (ImageView) findViewById(R.id.barcodePreview);
+ imageView.setImageBitmap(result.getBitmapWithResultPoints(Color.YELLOW));
+ }
+
+ @Override
+ public void possibleResultPoints(List<ResultPoint> resultPoints) {
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.continuous_scan);
+
+ barcodeView = (CompoundBarcodeView) findViewById(R.id.barcode_scanner);
+ barcodeView.decodeContinuous(callback);
+ }
+
+ @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) {
+ return barcodeView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
+ }
+}
diff --git a/sample/src/main/java/example/zxing/CustomCaptureActivity.java b/sample/src/main/java/example/zxing/CustomCaptureActivity.java
deleted file mode 100644
index 37b69fed..00000000
--- a/sample/src/main/java/example/zxing/CustomCaptureActivity.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package example.zxing;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.graphics.Color;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.View;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import com.google.zxing.ResultPoint;
-import com.journeyapps.barcodescanner.BarcodeCallback;
-import com.journeyapps.barcodescanner.BarcodeResult;
-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(BarcodeResult result) {
- TextView text = (TextView) findViewById(R.id.zxing_barcode_status);
- if (result.getText() != null) {
- text.setText(result.getText());
- }
- //Added preview of scanned barcode
- ImageView imageView = (ImageView) findViewById(R.id.barcodePreview);
- imageView.setImageBitmap(result.getBitmapWithResultPoints(Color.YELLOW));
- }
-
- @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);
- }
-}
diff --git a/sample/src/main/java/example/zxing/MainActivity.java b/sample/src/main/java/example/zxing/MainActivity.java
index 6c33ede9..f8c9622c 100644
--- a/sample/src/main/java/example/zxing/MainActivity.java
+++ b/sample/src/main/java/example/zxing/MainActivity.java
@@ -1,11 +1,11 @@
package example.zxing;
import android.content.Intent;
-import android.content.pm.ActivityInfo;
import android.hardware.Camera;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -30,7 +30,7 @@ public class MainActivity extends ActionBarActivity {
public void scanBarcodeCustomLayout(View view) {
IntentIntegrator integrator = new IntentIntegrator(this);
- integrator.setCaptureActivity(CaptureActivityAnyOrientation.class);
+ integrator.setCaptureActivity(AnyOrientationCaptureActivity.class);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan something");
integrator.setOrientationLocked(false);
@@ -43,21 +43,28 @@ public class MainActivity extends ActionBarActivity {
integrator.initiateScan();
}
- public void scan2(View view) {
- Intent intent = new Intent(this, CustomCaptureActivity.class);
+ public void scanContinuous(View view) {
+ Intent intent = new Intent(this, ContinuousCaptureActivity.class);
startActivity(intent);
}
+ public void scanToolbar(View view) {
+ new IntentIntegrator(this).setCaptureActivity(ToolbarCaptureActivity.class).initiateScan();
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
+ Log.d("MainActivity", "Cancelled scan");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
+ Log.d("MainActivity", "Scanned");
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
+ Log.d("MainActivity", "Weird");
// This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data);
}
diff --git a/sample/src/main/java/example/zxing/ToolbarCaptureActivity.java b/sample/src/main/java/example/zxing/ToolbarCaptureActivity.java
new file mode 100644
index 00000000..f497d117
--- /dev/null
+++ b/sample/src/main/java/example/zxing/ToolbarCaptureActivity.java
@@ -0,0 +1,69 @@
+package example.zxing;
+
+import android.os.Bundle;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.KeyEvent;
+
+import com.journeyapps.barcodescanner.CaptureManager;
+import com.journeyapps.barcodescanner.CompoundBarcodeView;
+
+/**
+ * Sample Activity extending from ActionBarActivity to display a Toolbar.
+ */
+public class ToolbarCaptureActivity extends ActionBarActivity {
+ private CaptureManager capture;
+ private CompoundBarcodeView barcodeScannerView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.capture_appcompat);
+ Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
+ toolbar.setTitle("Scan Barcode");
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ barcodeScannerView = (CompoundBarcodeView)findViewById(R.id.zxing_barcode_scanner);
+
+ capture = new CaptureManager(this, barcodeScannerView);
+ capture.initializeFromIntent(getIntent(), savedInstanceState);
+ capture.decode();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ capture.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ capture.onPause();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ capture.onDestroy();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ capture.onSaveInstanceState(outState);
+ }
+
+ @Override
+ public boolean onSupportNavigateUp() {
+ onBackPressed();
+ return true;
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return barcodeScannerView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
+ }
+}
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml
index 95b7ee17..8f2d4c48 100644
--- a/sample/src/main/res/layout/activity_main.xml
+++ b/sample/src/main/res/layout/activity_main.xml
@@ -1,44 +1,57 @@
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:orientation="vertical"
tools:context="example.zxing.MainActivity">
- <Button
- android:layout_width="wrap_content"
+ <LinearLayout
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="@string/scan_barcode"
- android:onClick="scanBarcode"/>
+ android:orientation="vertical"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ android:paddingBottom="@dimen/activity_vertical_margin">
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/any_orientation"
- android:onClick="scanBarcodeCustomLayout"/>
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/scan_barcode"
+ android:onClick="scanBarcode"/>
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/front_camera"
- android:onClick="scanBarcodeFrontCamera"/>
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/any_orientation"
+ android:onClick="scanBarcodeCustomLayout"/>
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/front_camera"
+ android:onClick="scanBarcodeFrontCamera"/>
- <fragment
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:name="example.zxing.MainActivity$ScanFragment" tools:layout="@layout/fragment_scan" />
+ <fragment
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:name="example.zxing.MainActivity$ScanFragment" tools:layout="@layout/fragment_scan" />
+
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/custom_activity"
+ android:onClick="scanContinuous"/>
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/toolbar_activity"
+ android:onClick="scanToolbar"/>
+
+ </LinearLayout>
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/custom_activity"
- android:onClick="scan2"/>
-</LinearLayout>
+</ScrollView>
diff --git a/sample/src/main/res/layout/capture_appcompat.xml b/sample/src/main/res/layout/capture_appcompat.xml
new file mode 100644
index 00000000..b1ffaffa
--- /dev/null
+++ b/sample/src/main/res/layout/capture_appcompat.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (C) 2008 ZXing authors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/my_awesome_toolbar"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:minHeight="?attr/actionBarSize"
+ android:background="?attr/colorPrimary"
+ app:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
+
+ <com.journeyapps.barcodescanner.CompoundBarcodeView
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:id="@+id/zxing_barcode_scanner"/>
+</LinearLayout> \ No newline at end of file
diff --git a/sample/src/main/res/layout/new_custom_layout.xml b/sample/src/main/res/layout/continuous_scan.xml
index 528498b6..e1b9356d 100644
--- a/sample/src/main/res/layout/new_custom_layout.xml
+++ b/sample/src/main/res/layout/continuous_scan.xml
@@ -3,25 +3,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <FrameLayout
+ <com.journeyapps.barcodescanner.CompoundBarcodeView
+ android:id="@+id/barcode_scanner"
android:layout_width="match_parent"
android:layout_height="0dp"
- android:layout_weight="2"
- android:layout_margin="0dp"
android:layout_above="@+id/buttonsLayout"
android:layout_alignParentTop="true">
- <com.journeyapps.barcodescanner.BarcodeView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/zxing_barcode_surface" />
-
- <com.journeyapps.barcodescanner.ViewfinderView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/zxing_viewfinder_view" />
- </FrameLayout>
-
+ </com.journeyapps.barcodescanner.CompoundBarcodeView>
<LinearLayout
android:orientation="vertical"
@@ -31,13 +20,6 @@
android:id="@+id/buttonsLayout"
android:layout_toLeftOf="@+id/centerHorizont">
- <TextView
- android:id="@+id/zxing_barcode_status"
- android:layout_width="match_parent"
- android:layout_height="30dip"
- android:layout_weight="0"
- android:text="Scanning..." />
-
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/sample/src/main/res/values-v21/styles.xml b/sample/src/main/res/values-v21/styles.xml
new file mode 100644
index 00000000..86092ffd
--- /dev/null
+++ b/sample/src/main/res/values-v21/styles.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="AppCompatCaptureTheme" parent="Theme.AppCompat.Light.NoActionBar">
+ <item name="android:windowDrawsSystemBarBackgrounds">true</item>
+ <item name="android:statusBarColor">#ffb341</item>
+ </style>
+</resources>
diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml
index 10decfcf..7e9475b8 100644
--- a/sample/src/main/res/values/strings.xml
+++ b/sample/src/main/res/values/strings.xml
@@ -3,9 +3,10 @@
<string name="app_name">ZXing Sample</string>
<string name="scan_barcode">Scan Barcode</string>
- <string name="any_orientation">Any Orientation</string>
+ <string name="any_orientation">1D Any Orientation</string>
<string name="scan_from_fragment">Scan from fragment</string>
<string name="front_camera">Front Camera</string>
- <string name="custom_activity">Custom Activity</string>
+ <string name="custom_activity">Continuous Scan</string>
+ <string name="toolbar_activity">Activity with Toolbar</string>
</resources>
diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml
index 54315dca..993da3a1 100644
--- a/sample/src/main/res/values/styles.xml
+++ b/sample/src/main/res/values/styles.xml
@@ -4,4 +4,12 @@
<style name="AppTheme" parent="Theme.AppCompat">
</style>
+
+ <style name="AppCompatCaptureTheme" parent="Theme.AppCompat.Light.NoActionBar">
+ <item name="android:windowFullscreen">true</item>
+ <item name="android:windowContentOverlay">@null</item>
+ <item name="colorPrimary">#ffb341</item>
+ <item name="colorPrimaryDark">#ffb341</item>
+ <item name="colorAccent">#ffb341</item>
+ </style>
</resources>