mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Remove glass, androidtest apps
This commit is contained in:
parent
7fdc869d02
commit
6ae3a36107
4
CHANGES
4
CHANGES
|
@ -363,3 +363,7 @@
|
||||||
- BS 4.7.6 release with Android API 23 support
|
- BS 4.7.6 release with Android API 23 support
|
||||||
- TIFF support in online decoder
|
- TIFF support in online decoder
|
||||||
- Many small bug fixes, typo fixes and project build improvements
|
- Many small bug fixes, typo fixes and project build improvements
|
||||||
|
|
||||||
|
3.4.0 (?)
|
||||||
|
|
||||||
|
- Removed Google Glass, ZXing Test apps
|
|
@ -27,10 +27,8 @@ library implemented in Java, with ports to other languages.
|
||||||
| core | The core image decoding library, and test code
|
| core | The core image decoding library, and test code
|
||||||
| javase | JavaSE-specific client code
|
| javase | JavaSE-specific client code
|
||||||
| android | Android client Barcode Scanner [](https://play.google.com/store/apps/details?id=com.google.zxing.client.android)
|
| android | Android client Barcode Scanner [](https://play.google.com/store/apps/details?id=com.google.zxing.client.android)
|
||||||
| androidtest | Android test app, ZXing Test
|
|
||||||
| android-integration | Supports integration with Barcode Scanner via `Intent`
|
| android-integration | Supports integration with Barcode Scanner via `Intent`
|
||||||
| android-core | Android-related code shared among `android`, `androidtest`, `glass`
|
| android-core | Android-related code shared among `android`, `androidtest`, `glass`
|
||||||
| glass | Simple Google Glass application
|
|
||||||
| zxingorg | The source behind `zxing.org`
|
| zxingorg | The source behind `zxing.org`
|
||||||
| zxing.appspot.com | The source behind web-based barcode generator at `zxing.appspot.com`
|
| zxing.appspot.com | The source behind web-based barcode generator at `zxing.appspot.com`
|
||||||
|
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
<?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.
|
|
||||||
-->
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.google.zxing.client.androidtest"
|
|
||||||
android:versionName="1.4.2"
|
|
||||||
android:versionCode="11"
|
|
||||||
android:installLocation="auto">
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.CAMERA"/>
|
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22"/>
|
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.camera.any"/>
|
|
||||||
|
|
||||||
<application android:label="@string/app_name"
|
|
||||||
android:icon="@drawable/icon"
|
|
||||||
android:allowBackup="true">
|
|
||||||
<activity android:name="ZXingTestActivity"
|
|
||||||
android:label="@string/app_name">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity android:name="BenchmarkActivity"
|
|
||||||
android:label="@string/benchmark_name"/>
|
|
||||||
</application>
|
|
||||||
|
|
||||||
</manifest>
|
|
|
@ -1,76 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2013 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.
|
|
||||||
-->
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>androidtest</artifactId>
|
|
||||||
<version>1.4.2</version>
|
|
||||||
<packaging>apk</packaging>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.zxing</groupId>
|
|
||||||
<artifactId>core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.zxing</groupId>
|
|
||||||
<artifactId>android-integration</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.zxing</groupId>
|
|
||||||
<artifactId>android-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.android</groupId>
|
|
||||||
<artifactId>android</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.google.zxing</groupId>
|
|
||||||
<artifactId>zxing-parent</artifactId>
|
|
||||||
<version>3.3.1-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<sourceDirectory>src</sourceDirectory>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.simpligility.maven.plugins</groupId>
|
|
||||||
<artifactId>android-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<name>Android ZXing Test app</name>
|
|
||||||
<description>Provides the Android app "ZXing Test" for developers</description>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1 +0,0 @@
|
||||||
../android/proguard.cfg
|
|
Binary file not shown.
Before Width: | Height: | Size: 8.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 13 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.6 KiB |
|
@ -1,31 +0,0 @@
|
||||||
<?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"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
<Button android:id="@+id/benchmark_run"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/benchmark_run"/>
|
|
||||||
<TextView android:id="@+id/benchmark_help"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:singleLine="false"
|
|
||||||
android:text="@string/benchmark_help"
|
|
||||||
android:padding="5dip"/>
|
|
||||||
</LinearLayout>
|
|
|
@ -1,85 +0,0 @@
|
||||||
<?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.
|
|
||||||
-->
|
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
<LinearLayout android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="@android:color/background_dark"
|
|
||||||
android:orientation="vertical">
|
|
||||||
<Button android:id="@+id/run_benchmark"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/benchmark_run"/>
|
|
||||||
<Button android:id="@+id/get_camera_parameters"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/get_camera_parameters"/>
|
|
||||||
<Button android:id="@+id/scan_product"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/scan_product"/>
|
|
||||||
<Button android:id="@+id/scan_qr_code"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/scan_qr_code"/>
|
|
||||||
<Button android:id="@+id/scan_anything"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/scan_anything"/>
|
|
||||||
<Button android:id="@+id/search_book_contents"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/search_book_contents"/>
|
|
||||||
<Button android:id="@+id/encode_url"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/encode_url"/>
|
|
||||||
<Button android:id="@+id/encode_email"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/encode_email"/>
|
|
||||||
<Button android:id="@+id/encode_phone"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/encode_phone"/>
|
|
||||||
<Button android:id="@+id/encode_sms"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/encode_sms"/>
|
|
||||||
<Button android:id="@+id/encode_contact"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/encode_contact"/>
|
|
||||||
<Button android:id="@+id/encode_location"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/encode_location"/>
|
|
||||||
<Button android:id="@+id/encode_hidden_data"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/encode_hidden_data"/>
|
|
||||||
<Button android:id="@+id/encode_bad_data"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/encode_bad_data"/>
|
|
||||||
<Button android:id="@+id/share_via_barcode"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/share_via_barcode"/>
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
|
@ -1,22 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2013 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.
|
|
||||||
-->
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item android:id="@+id/menu_about"
|
|
||||||
android:title="@string/about_menu"
|
|
||||||
android:icon="@android:drawable/ic_menu_help"
|
|
||||||
android:showAsAction="withText|ifRoom"/>
|
|
||||||
</menu>
|
|
|
@ -1,24 +0,0 @@
|
||||||
<?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.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<item type="id" name="auto_focus"/>
|
|
||||||
<item type="id" name="benchmark_done"/>
|
|
||||||
<item type="id" name="quit"/>
|
|
||||||
<item type="id" name="save"/>
|
|
||||||
<item type="id" name="save_succeeded"/>
|
|
||||||
<item type="id" name="save_failed"/>
|
|
||||||
</resources>
|
|
|
@ -1,43 +0,0 @@
|
||||||
<?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.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<string name="about_menu">About</string>
|
|
||||||
<string name="about_message">A utility written by the ZXing Team to help with the development of Barcode Scanner</string>
|
|
||||||
<string name="app_name">ZXing Test</string>
|
|
||||||
<string name="benchmark_name">ZXing Benchmark</string>
|
|
||||||
<string name="benchmark_help">Place images in /sdcard/zxingbenchmark, then check \"adb logcat\" for results. Turn on Airplane Mode first for more reliable results.</string>
|
|
||||||
<string name="benchmark_run">Run benchmark</string>
|
|
||||||
<string name="benchmark_running">Benchmark running\u2026</string>
|
|
||||||
<string name="encode_bad_data">Encode bad data</string>
|
|
||||||
<string name="encode_contact">Encode contact</string>
|
|
||||||
<string name="encode_email">Encode email</string>
|
|
||||||
<string name="encode_hidden_data">Encode hidden data</string>
|
|
||||||
<string name="encode_location">Encode location</string>
|
|
||||||
<string name="encode_phone">Encode phone</string>
|
|
||||||
<string name="encode_sms">Encode SMS</string>
|
|
||||||
<string name="encode_url">Encode URL</string>
|
|
||||||
<string name="get_camera_parameters">Get camera parameters</string>
|
|
||||||
<string name="ok_button">OK</string>
|
|
||||||
<string name="result_failed">No barcode found</string>
|
|
||||||
<string name="result_failed_why">"The user gave up and pressed Back"</string>
|
|
||||||
<string name="result_succeeded">Found barcode</string>
|
|
||||||
<string name="scan_anything">Scan anything</string>
|
|
||||||
<string name="scan_product">Scan product</string>
|
|
||||||
<string name="scan_qr_code">Scan QR Code</string>
|
|
||||||
<string name="search_book_contents">Search Book Contents</string>
|
|
||||||
<string name="share_via_barcode">Share via barcode</string>
|
|
||||||
</resources>
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.androidtest;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Activity that runs barcode scanning benchmarks.
|
|
||||||
*/
|
|
||||||
public final class BenchmarkActivity extends Activity {
|
|
||||||
|
|
||||||
private View runBenchmarkButton;
|
|
||||||
private TextView textView;
|
|
||||||
private AsyncTask<Object,Object,String> benchmarkTask;
|
|
||||||
|
|
||||||
private final View.OnClickListener runBenchmark = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (benchmarkTask == null) {
|
|
||||||
String path = Environment.getExternalStorageDirectory().getPath() + "/zxingbenchmark";
|
|
||||||
File dir = new File(path, "zxingbenchmark");
|
|
||||||
benchmarkTask = new BenchmarkAsyncTask(BenchmarkActivity.this, dir);
|
|
||||||
runBenchmarkButton.setEnabled(false);
|
|
||||||
textView.setText(R.string.benchmark_running);
|
|
||||||
benchmarkTask.execute(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
setContentView(R.layout.benchmark);
|
|
||||||
runBenchmarkButton = findViewById(R.id.benchmark_run);
|
|
||||||
runBenchmarkButton.setOnClickListener(runBenchmark);
|
|
||||||
textView = (TextView) findViewById(R.id.benchmark_help);
|
|
||||||
benchmarkTask = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onBenchmarkDone(String message) {
|
|
||||||
textView.setText(message + "\n\n" + getString(R.string.benchmark_help));
|
|
||||||
runBenchmarkButton.setEnabled(true);
|
|
||||||
benchmarkTask = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,139 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2013 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.androidtest;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Debug;
|
|
||||||
import android.util.Log;
|
|
||||||
import com.google.zxing.BinaryBitmap;
|
|
||||||
import com.google.zxing.MultiFormatReader;
|
|
||||||
import com.google.zxing.RGBLuminanceSource;
|
|
||||||
import com.google.zxing.ReaderException;
|
|
||||||
import com.google.zxing.Result;
|
|
||||||
import com.google.zxing.common.HybridBinarizer;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asynchronous task which actually runs benchmarks and collects timing.z
|
|
||||||
*/
|
|
||||||
public final class BenchmarkAsyncTask extends AsyncTask<Object,Object,String> {
|
|
||||||
|
|
||||||
private static final String TAG = BenchmarkAsyncTask.class.getSimpleName();
|
|
||||||
private static final int RUNS = 10;
|
|
||||||
|
|
||||||
private final BenchmarkActivity benchmarkActivity;
|
|
||||||
private final File file;
|
|
||||||
|
|
||||||
BenchmarkAsyncTask(BenchmarkActivity benchmarkActivity, File file) {
|
|
||||||
this.benchmarkActivity = benchmarkActivity;
|
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String doInBackground(Object... params) {
|
|
||||||
MultiFormatReader reader = new MultiFormatReader();
|
|
||||||
reader.setHints(null);
|
|
||||||
// Try to get in a known state before starting the benchmark
|
|
||||||
System.gc();
|
|
||||||
|
|
||||||
List<BenchmarkItem> items = new ArrayList<>();
|
|
||||||
walkTree(reader, file, items);
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
int time = 0;
|
|
||||||
for (BenchmarkItem item : items) {
|
|
||||||
if (item != null) {
|
|
||||||
Log.v(TAG, item.toString());
|
|
||||||
count++;
|
|
||||||
time += item.getAverageTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "TOTAL: Decoded " + count + " images in " + time + " us";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(String totals) {
|
|
||||||
benchmarkActivity.onBenchmarkDone(totals);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void walkTree(MultiFormatReader reader,
|
|
||||||
File fileOrDir,
|
|
||||||
List<BenchmarkItem> items) {
|
|
||||||
Log.i(TAG, "Decoding " + fileOrDir);
|
|
||||||
if (fileOrDir.isDirectory()) {
|
|
||||||
File[] files = fileOrDir.listFiles();
|
|
||||||
if (files != null) {
|
|
||||||
Arrays.sort(files);
|
|
||||||
for (File file : files) {
|
|
||||||
walkTree(reader, file, items);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
BenchmarkItem item = decode(reader, fileOrDir);
|
|
||||||
if (item != null) {
|
|
||||||
items.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BenchmarkItem decode(MultiFormatReader reader, File file) {
|
|
||||||
|
|
||||||
Bitmap imageBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
|
|
||||||
if (imageBitmap == null) {
|
|
||||||
Log.e(TAG, "Couldn't open " + file);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int width = imageBitmap.getWidth();
|
|
||||||
int height = imageBitmap.getHeight();
|
|
||||||
int[] pixels = new int[width * height];
|
|
||||||
imageBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
|
|
||||||
|
|
||||||
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
|
|
||||||
|
|
||||||
BenchmarkItem item = new BenchmarkItem(file, RUNS);
|
|
||||||
for (int x = 0; x < RUNS; x++) {
|
|
||||||
boolean success;
|
|
||||||
Result result = null;
|
|
||||||
// Using this call instead of getting the time should eliminate a lot of variability due to
|
|
||||||
// scheduling and what else is happening in the system.
|
|
||||||
long now = Debug.threadCpuTimeNanos();
|
|
||||||
try {
|
|
||||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
|
||||||
result = reader.decodeWithState(bitmap);
|
|
||||||
success = true;
|
|
||||||
} catch (ReaderException ignored) {
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
now = Debug.threadCpuTimeNanos() - now;
|
|
||||||
if (x == 0) {
|
|
||||||
item.setDecoded(success);
|
|
||||||
item.setFormat(result != null ? result.getBarcodeFormat() : null);
|
|
||||||
}
|
|
||||||
item.addResult((int) (now / 1000));
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2008 Google Inc.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.androidtest;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
|
||||||
|
|
||||||
final class BenchmarkItem {
|
|
||||||
|
|
||||||
private final File file;
|
|
||||||
private final int[] times;
|
|
||||||
private int position;
|
|
||||||
private boolean decoded;
|
|
||||||
private BarcodeFormat format;
|
|
||||||
|
|
||||||
BenchmarkItem(File file, int runs) {
|
|
||||||
if (runs <= 0) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
this.file = file;
|
|
||||||
times = new int[runs];
|
|
||||||
position = 0;
|
|
||||||
decoded = false;
|
|
||||||
format = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addResult(int microseconds) {
|
|
||||||
times[position] = microseconds;
|
|
||||||
position++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDecoded(boolean decoded) {
|
|
||||||
this.decoded = decoded;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFormat(BarcodeFormat format) {
|
|
||||||
this.format = format;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return (decoded ? "DECODED " + format + ": " : "FAILED: ") + file +
|
|
||||||
" (" + getAverageTime() + " us average)";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the average time but throws out the maximum as an outlier first.
|
|
||||||
*
|
|
||||||
* @return The average decoding time in microseconds.
|
|
||||||
*/
|
|
||||||
int getAverageTime() {
|
|
||||||
int size = times.length;
|
|
||||||
int total = 0;
|
|
||||||
int max = times[0];
|
|
||||||
for (int x = 0; x < size; x++) {
|
|
||||||
int time = times[x];
|
|
||||||
total += time;
|
|
||||||
if (time > max) {
|
|
||||||
max = time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
total -= max;
|
|
||||||
size--;
|
|
||||||
return size > 0 ? total / size : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,307 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.androidtest;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.hardware.Camera;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.provider.ContactsContract;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import com.google.zxing.client.android.camera.CameraConfigurationUtils;
|
|
||||||
import com.google.zxing.integration.android.IntentIntegrator;
|
|
||||||
import com.google.zxing.integration.android.IntentResult;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main test app activity.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation") // camera APIs
|
|
||||||
public final class ZXingTestActivity extends Activity {
|
|
||||||
|
|
||||||
private static final String TAG = ZXingTestActivity.class.getSimpleName();
|
|
||||||
private static final String PACKAGE_NAME = ZXingTestActivity.class.getPackage().getName();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
setContentView(R.layout.test);
|
|
||||||
findViewById(R.id.get_camera_parameters).setOnClickListener(getCameraParameters);
|
|
||||||
findViewById(R.id.scan_product).setOnClickListener(scanProduct);
|
|
||||||
findViewById(R.id.scan_qr_code).setOnClickListener(scanQRCode);
|
|
||||||
findViewById(R.id.scan_anything).setOnClickListener(scanAnything);
|
|
||||||
findViewById(R.id.search_book_contents).setOnClickListener(searchBookContents);
|
|
||||||
findViewById(R.id.encode_url).setOnClickListener(encodeURL);
|
|
||||||
findViewById(R.id.encode_email).setOnClickListener(encodeEmail);
|
|
||||||
findViewById(R.id.encode_phone).setOnClickListener(encodePhone);
|
|
||||||
findViewById(R.id.encode_sms).setOnClickListener(encodeSMS);
|
|
||||||
findViewById(R.id.encode_contact).setOnClickListener(encodeContact);
|
|
||||||
findViewById(R.id.encode_location).setOnClickListener(encodeLocation);
|
|
||||||
findViewById(R.id.encode_hidden_data).setOnClickListener(encodeHiddenData);
|
|
||||||
findViewById(R.id.encode_bad_data).setOnClickListener(encodeBadData);
|
|
||||||
findViewById(R.id.share_via_barcode).setOnClickListener(shareViaBarcode);
|
|
||||||
findViewById(R.id.run_benchmark).setOnClickListener(runBenchmark);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
MenuInflater menuInflater = getMenuInflater();
|
|
||||||
menuInflater.inflate(R.menu.main, menu);
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
if (item.getItemId() == R.id.menu_about) {
|
|
||||||
int versionCode;
|
|
||||||
String versionName;
|
|
||||||
try {
|
|
||||||
PackageInfo info = getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
|
|
||||||
versionCode = info.versionCode;
|
|
||||||
versionName = info.versionName;
|
|
||||||
} catch (PackageManager.NameNotFoundException ignored) {
|
|
||||||
versionCode = 0;
|
|
||||||
versionName = "unknown";
|
|
||||||
}
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
builder.setTitle(
|
|
||||||
getString(R.string.app_name) + ' ' + versionName + " (" + versionCode + ')');
|
|
||||||
builder.setMessage(getString(R.string.about_message));
|
|
||||||
builder.setPositiveButton(R.string.ok_button, null);
|
|
||||||
builder.show();
|
|
||||||
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
||||||
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
|
||||||
if (result != null) {
|
|
||||||
if (result.getContents() != null) {
|
|
||||||
showDialog(R.string.result_succeeded, result.toString());
|
|
||||||
} else {
|
|
||||||
showDialog(R.string.result_failed, getString(R.string.result_failed_why));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private final View.OnClickListener getCameraParameters = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
String stats = CameraConfigurationUtils.collectStats(getFlattenedParams());
|
|
||||||
writeStats(stats);
|
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
||||||
intent.putExtra(Intent.EXTRA_EMAIL, "zxing-external@google.com");
|
|
||||||
intent.putExtra(Intent.EXTRA_SUBJECT, "Camera parameters report");
|
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, stats);
|
|
||||||
intent.setType("text/plain");
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener runBenchmark = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
intent.setClassName(ZXingTestActivity.this, BenchmarkActivity.class.getName());
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener scanProduct = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
|
|
||||||
integrator.addExtra("SCAN_WIDTH", 800);
|
|
||||||
integrator.addExtra("SCAN_HEIGHT", 200);
|
|
||||||
integrator.addExtra("RESULT_DISPLAY_DURATION_MS", 3000L);
|
|
||||||
integrator.addExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
|
|
||||||
integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener scanQRCode = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
|
|
||||||
integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener scanAnything = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
|
|
||||||
integrator.initiateScan();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener searchBookContents = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Intent intent = new Intent("com.google.zxing.client.android.SEARCH_BOOK_CONTENTS");
|
|
||||||
intent.putExtra("ISBN", "9780441014989");
|
|
||||||
intent.putExtra("QUERY", "future");
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener encodeURL = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
encodeBarcode("TEXT_TYPE", "http://www.nytimes.com");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener encodeEmail = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
encodeBarcode("EMAIL_TYPE", "foo@example.com");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener encodePhone = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
encodeBarcode("PHONE_TYPE", "2125551212");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener encodeSMS = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
encodeBarcode("SMS_TYPE", "2125551212");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener encodeContact = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(ContactsContract.Intents.Insert.NAME, "Jenny");
|
|
||||||
bundle.putString(ContactsContract.Intents.Insert.PHONE, "8675309");
|
|
||||||
bundle.putString(ContactsContract.Intents.Insert.EMAIL, "jenny@the80s.com");
|
|
||||||
bundle.putString(ContactsContract.Intents.Insert.POSTAL, "123 Fake St. San Francisco, CA 94102");
|
|
||||||
encodeBarcode("CONTACT_TYPE", bundle);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener encodeLocation = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putFloat("LAT", 40.829208f);
|
|
||||||
bundle.putFloat("LONG", -74.191279f);
|
|
||||||
encodeBarcode("LOCATION_TYPE", bundle);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener encodeHiddenData = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
|
|
||||||
integrator.addExtra("ENCODE_SHOW_CONTENTS", false);
|
|
||||||
integrator.shareText("SURPRISE!");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener encodeBadData = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
encodeBarcode(null, "bar");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final View.OnClickListener shareViaBarcode = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
startActivity(new Intent("com.google.zxing.client.android.SHARE"));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void showDialog(int title, CharSequence message) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
builder.setTitle(title);
|
|
||||||
builder.setMessage(message);
|
|
||||||
builder.setPositiveButton(R.string.ok_button, null);
|
|
||||||
builder.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void encodeBarcode(CharSequence type, CharSequence data) {
|
|
||||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
|
||||||
integrator.shareText(data, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void encodeBarcode(CharSequence type, Bundle data) {
|
|
||||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
|
||||||
integrator.addExtra("ENCODE_DATA", data);
|
|
||||||
integrator.shareText(data.toString(), type); // data.toString() isn't used
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CharSequence getFlattenedParams() {
|
|
||||||
Camera camera = Camera.open();
|
|
||||||
if (camera == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Camera.Parameters parameters = camera.getParameters();
|
|
||||||
if (parameters == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return parameters.flatten();
|
|
||||||
} finally {
|
|
||||||
camera.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeStats(String resultString) {
|
|
||||||
File cameraParamsFile = new File(Environment.getExternalStorageDirectory().getPath() + "/CameraParameters.txt");
|
|
||||||
Writer out = null;
|
|
||||||
try {
|
|
||||||
out = new OutputStreamWriter(new FileOutputStream(cameraParamsFile), Charset.forName("UTF-8"));
|
|
||||||
out.write(resultString);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Cannot write parameters file ", e);
|
|
||||||
} finally {
|
|
||||||
if (out != null) {
|
|
||||||
try {
|
|
||||||
out.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.w(TAG, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2014 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.
|
|
||||||
-->
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.google.zxing.client.glass"
|
|
||||||
android:versionCode="4"
|
|
||||||
android:versionName="0.2.2">
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.CAMERA"/>
|
|
||||||
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
|
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19"/>
|
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.camera" />
|
|
||||||
|
|
||||||
<application android:label="@string/app_name"
|
|
||||||
android:icon="@drawable/ic_launcher"
|
|
||||||
android:allowBackup="true">
|
|
||||||
|
|
||||||
<activity android:name=".CaptureActivity">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="com.google.zxing.client.android.SCAN"/>
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<meta-data android:name="com.google.android.glass.VoiceTrigger"
|
|
||||||
android:resource="@xml/barcode_scanner_show" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
</application>
|
|
||||||
|
|
||||||
</manifest>
|
|
|
@ -1,72 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2014 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.
|
|
||||||
-->
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>glass</artifactId>
|
|
||||||
<version>0.2.2</version>
|
|
||||||
<packaging>apk</packaging>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.zxing</groupId>
|
|
||||||
<artifactId>core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.zxing</groupId>
|
|
||||||
<artifactId>android-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.android</groupId>
|
|
||||||
<artifactId>android</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.google.zxing</groupId>
|
|
||||||
<artifactId>zxing-parent</artifactId>
|
|
||||||
<version>3.3.1-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<sourceDirectory>src</sourceDirectory>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.simpligility.maven.plugins</groupId>
|
|
||||||
<artifactId>android-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<name>Android Barcode Scanner app for Google Glass</name>
|
|
||||||
<description>Provides the Google Glass app "Barcode Scanner"</description>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1 +0,0 @@
|
||||||
../android/proguard.cfg
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.6 KiB |
|
@ -1,34 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2014 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.
|
|
||||||
-->
|
|
||||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<SurfaceView android:id="@+id/preview_view"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"/>
|
|
||||||
|
|
||||||
<TextView android:id="@+id/status_view"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_gravity="bottom|center_horizontal"
|
|
||||||
android:background="@color/result_view"
|
|
||||||
android:textSize="54sp"
|
|
||||||
android:padding="10dip"
|
|
||||||
android:textColor="@color/result_text"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
</merge>
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2014 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.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<color name="result_text">#ffffffff</color>
|
|
||||||
<color name="result_view">#b0000000</color>
|
|
||||||
</resources>
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2014 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.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<item type="id" name="decode_start"/>
|
|
||||||
<item type="id" name="decode"/>
|
|
||||||
<item type="id" name="decode_failed"/>
|
|
||||||
<item type="id" name="decode_succeeded"/>
|
|
||||||
<item type="id" name="quit"/>
|
|
||||||
</resources>
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2014 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.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<string name="app_name">Barcode Scanner for Glass</string>
|
|
||||||
</resources>
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2014 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.
|
|
||||||
-->
|
|
||||||
<trigger keyword="BARCODE SCANNER">
|
|
||||||
<constraints camera="true" />
|
|
||||||
</trigger>
|
|
|
@ -1,62 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2014 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.glass;
|
|
||||||
|
|
||||||
import android.hardware.Camera;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.google.zxing.client.android.camera.CameraConfigurationUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Sean Owen
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation") // camera APIs
|
|
||||||
final class CameraConfigurationManager {
|
|
||||||
|
|
||||||
private static final String TAG = "CameraConfiguration";
|
|
||||||
|
|
||||||
static final int ZOOM = 2;
|
|
||||||
|
|
||||||
private CameraConfigurationManager() {
|
|
||||||
}
|
|
||||||
|
|
||||||
static void configure(Camera camera) {
|
|
||||||
Camera.Parameters parameters = camera.getParameters();
|
|
||||||
parameters.setPreviewSize(1280, 720);
|
|
||||||
//parameters.setPreviewSize(1920, 1080);
|
|
||||||
configureAdvanced(parameters);
|
|
||||||
camera.setParameters(parameters);
|
|
||||||
//logAllParameters(parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void configureAdvanced(Camera.Parameters parameters) {
|
|
||||||
CameraConfigurationUtils.setBestPreviewFPS(parameters);
|
|
||||||
CameraConfigurationUtils.setBarcodeSceneMode(parameters);
|
|
||||||
CameraConfigurationUtils.setVideoStabilization(parameters);
|
|
||||||
CameraConfigurationUtils.setMetering(parameters);
|
|
||||||
CameraConfigurationUtils.setZoom(parameters, ZOOM);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void logAllParameters(Camera.Parameters parameters) {
|
|
||||||
if (Log.isLoggable(TAG, Log.INFO)) {
|
|
||||||
for (String line : CameraConfigurationUtils.collectStats(parameters).split("\n")) {
|
|
||||||
Log.i(TAG, line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,202 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2014 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.glass;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.hardware.Camera;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.SurfaceHolder;
|
|
||||||
import android.view.SurfaceView;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.Window;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import com.google.zxing.Result;
|
|
||||||
import com.google.zxing.client.result.ParsedResult;
|
|
||||||
import com.google.zxing.client.result.ParsedResultType;
|
|
||||||
import com.google.zxing.client.result.ResultParser;
|
|
||||||
import com.google.zxing.client.result.TextParsedResult;
|
|
||||||
import com.google.zxing.client.result.URIParsedResult;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Sean Owen
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation") // camera APIs
|
|
||||||
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback {
|
|
||||||
|
|
||||||
private static final String TAG = CaptureActivity.class.getSimpleName();
|
|
||||||
private static final String SCAN_ACTION = "com.google.zxing.client.android.SCAN";
|
|
||||||
|
|
||||||
private boolean hasSurface;
|
|
||||||
private boolean returnResult;
|
|
||||||
private SurfaceHolder holderWithCallback;
|
|
||||||
private Camera camera;
|
|
||||||
private DecodeRunnable decodeRunnable;
|
|
||||||
private Result result;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
|
|
||||||
// returnResult should be true if activity was started using
|
|
||||||
// startActivityForResult() with SCAN_ACTION intent
|
|
||||||
Intent intent = getIntent();
|
|
||||||
returnResult = intent != null && SCAN_ACTION.equals(intent.getAction());
|
|
||||||
|
|
||||||
Window window = getWindow();
|
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
||||||
setContentView(R.layout.capture);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
|
|
||||||
SurfaceHolder surfaceHolder = surfaceView.getHolder();
|
|
||||||
if (surfaceHolder == null) {
|
|
||||||
throw new IllegalStateException("No SurfaceHolder?");
|
|
||||||
}
|
|
||||||
if (hasSurface) {
|
|
||||||
initCamera(surfaceHolder);
|
|
||||||
} else {
|
|
||||||
surfaceHolder.addCallback(this);
|
|
||||||
holderWithCallback = surfaceHolder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onPause() {
|
|
||||||
result = null;
|
|
||||||
if (decodeRunnable != null) {
|
|
||||||
decodeRunnable.stop();
|
|
||||||
decodeRunnable = null;
|
|
||||||
}
|
|
||||||
if (camera != null) {
|
|
||||||
camera.stopPreview();
|
|
||||||
camera.release();
|
|
||||||
camera = null;
|
|
||||||
}
|
|
||||||
if (holderWithCallback != null) {
|
|
||||||
holderWithCallback.removeCallback(this);
|
|
||||||
holderWithCallback = null;
|
|
||||||
}
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void surfaceCreated(SurfaceHolder holder) {
|
|
||||||
Log.i(TAG, "Surface created");
|
|
||||||
holderWithCallback = null;
|
|
||||||
if (!hasSurface) {
|
|
||||||
hasSurface = true;
|
|
||||||
initCamera(holder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void surfaceDestroyed(SurfaceHolder holder) {
|
|
||||||
Log.i(TAG, "Surface destroyed");
|
|
||||||
holderWithCallback = null;
|
|
||||||
hasSurface = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
||||||
if (result != null) {
|
|
||||||
switch (keyCode) {
|
|
||||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
|
||||||
handleResult(result);
|
|
||||||
return true;
|
|
||||||
case KeyEvent.KEYCODE_BACK:
|
|
||||||
reset();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.onKeyDown(keyCode, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initCamera(SurfaceHolder holder) {
|
|
||||||
if (camera != null) {
|
|
||||||
throw new IllegalStateException("Camera not null on initialization");
|
|
||||||
}
|
|
||||||
camera = Camera.open();
|
|
||||||
if (camera == null) {
|
|
||||||
throw new IllegalStateException("Camera is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
CameraConfigurationManager.configure(camera);
|
|
||||||
|
|
||||||
try {
|
|
||||||
camera.setPreviewDisplay(holder);
|
|
||||||
camera.startPreview();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Cannot start preview", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
decodeRunnable = new DecodeRunnable(this, camera);
|
|
||||||
new Thread(decodeRunnable).start();
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setResult(Result result) {
|
|
||||||
if (returnResult) {
|
|
||||||
Intent scanResult = new Intent("com.google.zxing.client.android.SCAN");
|
|
||||||
scanResult.putExtra("SCAN_RESULT", result.getText());
|
|
||||||
setResult(RESULT_OK, scanResult);
|
|
||||||
finish();
|
|
||||||
} else {
|
|
||||||
TextView statusView = (TextView) findViewById(R.id.status_view);
|
|
||||||
String text = result.getText();
|
|
||||||
statusView.setText(text);
|
|
||||||
statusView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.max(14, 56 - text.length() / 4));
|
|
||||||
statusView.setVisibility(View.VISIBLE);
|
|
||||||
this.result = result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleResult(Result result) {
|
|
||||||
ParsedResult parsed = ResultParser.parseResult(result);
|
|
||||||
Intent intent;
|
|
||||||
if (parsed.getType() == ParsedResultType.URI) {
|
|
||||||
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(((URIParsedResult) parsed).getURI()));
|
|
||||||
} else {
|
|
||||||
intent = new Intent(Intent.ACTION_WEB_SEARCH);
|
|
||||||
intent.putExtra("query", ((TextParsedResult) parsed).getText());
|
|
||||||
}
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void reset() {
|
|
||||||
TextView statusView = (TextView) findViewById(R.id.status_view);
|
|
||||||
statusView.setVisibility(View.GONE);
|
|
||||||
result = null;
|
|
||||||
decodeRunnable.startScanning();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,180 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2014 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.zxing.client.glass;
|
|
||||||
|
|
||||||
import android.hardware.Camera;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
|
||||||
import com.google.zxing.BinaryBitmap;
|
|
||||||
import com.google.zxing.DecodeHintType;
|
|
||||||
import com.google.zxing.MultiFormatReader;
|
|
||||||
import com.google.zxing.PlanarYUVLuminanceSource;
|
|
||||||
import com.google.zxing.ReaderException;
|
|
||||||
import com.google.zxing.Result;
|
|
||||||
import com.google.zxing.common.HybridBinarizer;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Sean Owen
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation") // camera APIs
|
|
||||||
final class DecodeRunnable implements Runnable, Camera.PreviewCallback {
|
|
||||||
|
|
||||||
private static final String TAG = DecodeRunnable.class.getSimpleName();
|
|
||||||
|
|
||||||
private final CaptureActivity activity;
|
|
||||||
private final Camera camera;
|
|
||||||
private final int height;
|
|
||||||
private final int width;
|
|
||||||
private final byte[] previewBuffer;
|
|
||||||
private boolean running;
|
|
||||||
private Handler handler;
|
|
||||||
private final CountDownLatch handlerInitLatch;
|
|
||||||
|
|
||||||
DecodeRunnable(CaptureActivity activity, Camera camera) {
|
|
||||||
this.activity = activity;
|
|
||||||
this.camera = camera;
|
|
||||||
Camera.Parameters parameters = camera.getParameters();
|
|
||||||
Camera.Size previewSize = parameters.getPreviewSize();
|
|
||||||
height = previewSize.height;
|
|
||||||
width = previewSize.width;
|
|
||||||
previewBuffer = new byte[(height * width * 3) / 2];
|
|
||||||
running = true;
|
|
||||||
handlerInitLatch = new CountDownLatch(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Handler getHandler() {
|
|
||||||
try {
|
|
||||||
handlerInitLatch.await();
|
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
// continue?
|
|
||||||
}
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Looper.prepare();
|
|
||||||
handler = new DecodeHandler();
|
|
||||||
handlerInitLatch.countDown();
|
|
||||||
Looper.loop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void startScanning() {
|
|
||||||
getHandler().obtainMessage(R.id.decode_start).sendToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
void stop() {
|
|
||||||
getHandler().obtainMessage(R.id.quit).sendToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPreviewFrame(byte[] data, Camera camera) {
|
|
||||||
if (running) {
|
|
||||||
getHandler().obtainMessage(R.id.decode, data).sendToTarget();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class DecodeHandler extends Handler {
|
|
||||||
|
|
||||||
private final Map<DecodeHintType,Object> hints;
|
|
||||||
|
|
||||||
DecodeHandler() {
|
|
||||||
hints = new EnumMap<>(DecodeHintType.class);
|
|
||||||
hints.put(DecodeHintType.POSSIBLE_FORMATS,
|
|
||||||
Arrays.asList(BarcodeFormat.AZTEC, BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message message) {
|
|
||||||
if (!running) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (message.what) {
|
|
||||||
case R.id.decode_start:
|
|
||||||
camera.setPreviewCallbackWithBuffer(DecodeRunnable.this);
|
|
||||||
camera.addCallbackBuffer(previewBuffer);
|
|
||||||
break;
|
|
||||||
case R.id.decode:
|
|
||||||
decode((byte[]) message.obj);
|
|
||||||
break;
|
|
||||||
case R.id.decode_succeeded:
|
|
||||||
final Result result = (Result) message.obj;
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
activity.setResult(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case R.id.decode_failed:
|
|
||||||
camera.addCallbackBuffer(previewBuffer);
|
|
||||||
break;
|
|
||||||
case R.id.quit:
|
|
||||||
running = false;
|
|
||||||
Looper.myLooper().quit();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void decode(byte[] data) {
|
|
||||||
Result rawResult = null;
|
|
||||||
|
|
||||||
int subtendedWidth = width / CameraConfigurationManager.ZOOM;
|
|
||||||
int subtendedHeight = height / CameraConfigurationManager.ZOOM;
|
|
||||||
int excessWidth = width - subtendedWidth;
|
|
||||||
int excessHeight = height - subtendedHeight;
|
|
||||||
|
|
||||||
//long start = System.currentTimeMillis();
|
|
||||||
PlanarYUVLuminanceSource source =
|
|
||||||
new PlanarYUVLuminanceSource(data,
|
|
||||||
width, height,
|
|
||||||
excessWidth / 2, excessHeight / 2,
|
|
||||||
subtendedWidth, subtendedHeight,
|
|
||||||
false);
|
|
||||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
|
||||||
try {
|
|
||||||
rawResult = new MultiFormatReader().decode(bitmap, hints);
|
|
||||||
} catch (ReaderException re) {
|
|
||||||
// continue
|
|
||||||
}
|
|
||||||
|
|
||||||
//long end = System.currentTimeMillis();
|
|
||||||
//Log.i(TAG, "Decode in " + (end - start));
|
|
||||||
Handler handler = getHandler();
|
|
||||||
Message message;
|
|
||||||
if (rawResult == null) {
|
|
||||||
message = handler.obtainMessage(R.id.decode_failed);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Decode succeeded: " + rawResult.getText());
|
|
||||||
message = handler.obtainMessage(R.id.decode_succeeded, rawResult);
|
|
||||||
}
|
|
||||||
message.sendToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
4
pom.xml
4
pom.xml
|
@ -325,7 +325,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.19.1</version>
|
<version>2.20</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<forkCount>0.5C</forkCount>
|
<forkCount>0.5C</forkCount>
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
|
@ -714,8 +714,6 @@
|
||||||
<module>android-core</module>
|
<module>android-core</module>
|
||||||
<module>android-integration</module>
|
<module>android-integration</module>
|
||||||
<module>android</module>
|
<module>android</module>
|
||||||
<module>androidtest</module>
|
|
||||||
<module>glass</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
Loading…
Reference in a new issue