limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.google.zxing.client.androidtest">
+ package="com.google.zxing.client.androidtest"
+ android:versionName="1.0"
+ android:versionCode="1">
<uses-sdk android:minSdkVersion="3"/>
<application android:label="@string/app_name"
android:icon="@drawable/icon"
android:debuggable="true">
<activity android:name="ZXingTestActivity"
- android:label="@string/app_name">
+ android:label="@string/app_name"
+ android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
android:screenOrientation="landscape">
</activity>
<activity android:name="BenchmarkActivity"
- android:label="@string/benchmark_name"/>
+ android:label="@string/benchmark_name"
+ android:screenOrientation="portrait"/>
</application>
<uses-permission android:name="android.permission.CAMERA"/>
</manifest>
--- /dev/null
+<?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.
+ -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <SurfaceView android:id="@+id/preview_view"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_centerInParent="true"/>
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@color/transparent">
+
+ <FrameLayout
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:background="@color/transparent"/>
+
+ <TextView android:id="@+id/status_text_view"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="left|center_vertical"
+ android:layout_weight="0"
+ android:text="@string/parameters_message"
+ android:textColor="@color/status_text"
+ android:background="@color/status_view"
+ android:padding="4px"/>
+
+ </LinearLayout>
+
+</FrameLayout>
android:layout_weight="1"
android:background="@color/transparent"/>
- <FrameLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="0"
- android:background="@color/status_view"
- android:baselineAligned="false"
- android:padding="4px">
-
- <TextView android:id="@+id/status_text_view"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="left|center_vertical"
- android:text="@string/status_message"
- android:textColor="@color/status_text"/>
-
- </FrameLayout>
+ <TextView android:id="@+id/status_text_view"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="left|center_vertical"
+ android:layout_weight="0"
+ android:text="@string/status_message"
+ android:textColor="@color/status_text"
+ android:background="@color/status_view"
+ android:padding="4px"/>
</LinearLayout>
android:gravity="center_horizontal"
android:padding="10px">
<TableRow>
- <Button android:id="@+id/test_camera"
+ <Button android:id="@+id/take_test_photos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/test_camera"/>
- <Button android:id="@+id/run_benchmark"
+ android:text="@string/take_test_photos"/>
+ <Button android:id="@+id/get_camera_parameters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/benchmark_run"/>
+ android:text="@string/get_camera_parameters"/>
</TableRow>
<TableRow>
<Button android:id="@+id/scan_product"
android:layout_height="wrap_content"
android:text="@string/share_via_barcode"/>
</TableRow>
+ <TableRow>
+ <Button android:id="@+id/run_benchmark"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/benchmark_run"/>
+ </TableRow>
</TableLayout>
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="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="test_camera">Test camera</string>
- <string name="encode_url">Encode URL</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_location">Encode location</string>
<string name="encode_phone">Encode phone</string>
<string name="encode_sms">Encode SMS</string>
- <string name="encode_contact">Encode contact</string>
- <string name="encode_location">Encode location</string>
- <string name="encode_bad_data">Encode bad data</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="parameters_message">Collecting camera parameters to email to ZXing Team\u2026</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="status_message">Press the shutter button or Search to save test images to the
- SD card. Press DPAD_CENTER to trigger autofocus.</string>
- <string name="save_succeeded">Save succeeded</string>
+
<string name="save_failed">Save failed - is the SD card installed?</string>
+ <string name="save_succeeded">Save succeeded</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>
-
- <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="status_message">Press the shutter button or Search to save test images to the
+ SD card. Press DPAD_CENTER to trigger autofocus.</string>
+ <string name="take_test_photos">Take test photos</string>
</resources>
mPreviewing = false;
}
- public void openDriver(SurfaceHolder holder) throws IOException {
- // "throws IOException added to accommodate Android 1.5
+ // Throws IOException added to accommodate Android 1.5.
+ public String openDriver(SurfaceHolder holder, boolean getParameters) throws IOException {
+ String result = null;
if (mCamera == null) {
mCamera = Camera.open();
mCamera.setPreviewDisplay(holder);
+ if (getParameters) {
+ result = collectCameraParameters();
+ }
setCameraParameters();
}
+ return result;
}
public void closeDriver() {
if (mCamera != null && mPreviewing) {
mPreviewHandler = handler;
mPreviewMessage = message;
- mCamera.setOneShotPreviewCallback(previewCallback);
+ mCamera.setPreviewCallback(previewCallback);
}
}
*/
public Rect getFramingRect() {
if (mFramingRect == null) {
- int width = mScreenResolution.x;
+ int width = mScreenResolution.x * 3 / 4;
int height = mScreenResolution.y * 3 / 4;
int leftOffset = (mScreenResolution.x - width) / 2;
int topOffset = (mScreenResolution.y - height) / 2;
private final Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
if (mPreviewHandler != null) {
+ mCamera.setPreviewCallback(null);
Message message = mPreviewHandler.obtainMessage(mPreviewMessage,
mScreenResolution.x, mScreenResolution.y, data);
message.sendToTarget();
mCamera.setParameters(parameters);
}
+ private String collectCameraParameters() {
+ Camera.Parameters parameters = mCamera.getParameters();
+ String[] params = parameters.flatten().split(";");
+ StringBuffer result = new StringBuffer();
+ result.append("Default camera parameters:");
+ for (String param : params) {
+ result.append("\n ");
+ result.append(param);
+ }
+ result.append('\n');
+ return result.toString();
+ }
+
private Point getScreenResolution() {
if (mScreenResolution == null) {
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
package com.google.zxing.client.androidtest;
import android.app.Activity;
+import android.content.Intent;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
public final class CameraTestActivity extends Activity implements SurfaceHolder.Callback {
- private SaveThread mSaveThread;
+ public static final String GET_CAMERA_PARAMETERS = "GET_CAMERA_PARAMETERS";
+ private static final String[] EMAIL_ADDRESS = {"zxing@googlegroups.com"};
+
+ private SaveThread mSaveThread = null;
+ private boolean mGetCameraParameters;
@Override
public void onCreate(Bundle icicle) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.camera_test);
+ mGetCameraParameters = getIntent().getBooleanExtra(GET_CAMERA_PARAMETERS, false);
+ if (mGetCameraParameters) {
+ setContentView(R.layout.camera_parameters);
+ } else {
+ setContentView(R.layout.camera_test);
+ }
CameraManager.init(getApplication());
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
@Override
protected void onResume() {
super.onResume();
- if (mSaveThread == null) {
+ if (mSaveThread == null && !mGetCameraParameters) {
mSaveThread = new SaveThread(this, CameraManager.get().getFramingRect());
mSaveThread.start();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
- if (event.getRepeatCount() == 0) {
- CameraManager.get().requestAutoFocus(mHandler, R.id.auto_focus);
- }
- return true;
- } else if (keyCode == KeyEvent.KEYCODE_CAMERA || keyCode == KeyEvent.KEYCODE_SEARCH) {
- if (event.getRepeatCount() == 0) {
- CameraManager.get().requestPreviewFrame(mSaveThread.mHandler, R.id.save);
+ if (!mGetCameraParameters) {
+ if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
+ if (event.getRepeatCount() == 0) {
+ CameraManager.get().requestAutoFocus(mHandler, R.id.auto_focus);
+ }
+ return true;
+ } else if (keyCode == KeyEvent.KEYCODE_CAMERA || keyCode == KeyEvent.KEYCODE_SEARCH) {
+ if (event.getRepeatCount() == 0) {
+ CameraManager.get().requestPreviewFrame(mSaveThread.mHandler, R.id.save);
+ }
+ return true;
}
- return true;
}
return super.onKeyDown(keyCode, event);
}
public void surfaceCreated(SurfaceHolder holder) {
try {
- CameraManager.get().openDriver(holder);
- } catch (IOException ioe) {
+ String parameters = CameraManager.get().openDriver(holder, mGetCameraParameters);
+ CameraManager.get().startPreview();
+ if (mGetCameraParameters) {
+ collectStatsAndSendEmail(parameters);
+ }
+ } catch (IOException e) {
// IOException clause added for Android 1.5
- throw new RuntimeException(ioe);
+ throw new RuntimeException(e);
}
- CameraManager.get().startPreview();
}
public void surfaceDestroyed(SurfaceHolder holder) {
}
+ private void collectStatsAndSendEmail(String parameters) {
+ StringBuffer result = new StringBuffer();
+ result.append("Device info:");
+ result.append("\n Board: ");
+ result.append(Build.BOARD);
+ result.append("\n Brand: ");
+ result.append(Build.BRAND);
+ result.append("\n Device: ");
+ result.append(Build.DEVICE);
+ result.append("\n Display: ");
+ result.append(Build.DISPLAY);
+ result.append("\n Fingerprint: ");
+ result.append(Build.FINGERPRINT);
+ result.append("\n Host: ");
+ result.append(Build.HOST);
+ result.append("\n ID: ");
+ result.append(Build.ID);
+ result.append("\n Model: ");
+ result.append(Build.MODEL);
+ result.append("\n Product: ");
+ result.append(Build.PRODUCT);
+ result.append("\n Tags: ");
+ result.append(Build.TAGS);
+ result.append("\n Type: ");
+ result.append(Build.TYPE);
+ result.append("\n User: ");
+ result.append(Build.USER);
+ result.append("\n Version Incremental: ");
+ result.append(Build.VERSION.INCREMENTAL);
+ result.append("\n Version Release: ");
+ result.append(Build.VERSION.RELEASE);
+ result.append("\n Version SDK: ");
+ result.append(Build.VERSION.SDK);
+
+ result.append("\n\n");
+ result.append(parameters);
+
+ Intent intent = new Intent(Intent.ACTION_SEND);
+ intent.putExtra(Intent.EXTRA_EMAIL, EMAIL_ADDRESS);
+ intent.putExtra(Intent.EXTRA_SUBJECT, "Camera parameters report");
+ intent.putExtra(Intent.EXTRA_TEXT, result.toString());
+ intent.setType("text/plain");
+ startActivity(intent);
+ }
+
}
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.Contacts;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public final class ZXingTestActivity extends Activity {
+ private static final int ABOUT_ID = Menu.FIRST;
+ private static final String PACKAGE_NAME = "com.google.zxing.client.androidtest";
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
-
setContentView(R.layout.test);
- View test_camera = findViewById(R.id.test_camera);
- test_camera.setOnClickListener(mTestCamera);
-
- View run_benchmark = findViewById(R.id.run_benchmark);
- run_benchmark.setOnClickListener(mRunBenchmark);
-
- View scan_product = findViewById(R.id.scan_product);
- scan_product.setOnClickListener(mScanProduct);
-
- View scan_qr_code = findViewById(R.id.scan_qr_code);
- scan_qr_code.setOnClickListener(mScanQRCode);
-
- View scan_anything = findViewById(R.id.scan_anything);
- scan_anything.setOnClickListener(mScanAnything);
-
- View search_book_contents = findViewById(R.id.search_book_contents);
- search_book_contents.setOnClickListener(mSearchBookContents);
-
- View encode_url = findViewById(R.id.encode_url);
- encode_url.setOnClickListener(mEncodeURL);
-
- View encode_email = findViewById(R.id.encode_email);
- encode_email.setOnClickListener(mEncodeEmail);
-
- View encode_phone = findViewById(R.id.encode_phone);
- encode_phone.setOnClickListener(mEncodePhone);
-
- View encode_sms = findViewById(R.id.encode_sms);
- encode_sms.setOnClickListener(mEncodeSMS);
-
- View encode_contact = findViewById(R.id.encode_contact);
- encode_contact.setOnClickListener(mEncodeContact);
-
- View encode_location = findViewById(R.id.encode_location);
- encode_location.setOnClickListener(mEncodeLocation);
+ findViewById(R.id.take_test_photos).setOnClickListener(mTakeTestPhotos);
+ findViewById(R.id.get_camera_parameters).setOnClickListener(mGetCameraParameters);
+ findViewById(R.id.run_benchmark).setOnClickListener(mRunBenchmark);
+ findViewById(R.id.scan_product).setOnClickListener(mScanProduct);
+ findViewById(R.id.scan_qr_code).setOnClickListener(mScanQRCode);
+ findViewById(R.id.scan_anything).setOnClickListener(mScanAnything);
+ findViewById(R.id.search_book_contents).setOnClickListener(mSearchBookContents);
+ findViewById(R.id.encode_url).setOnClickListener(mEncodeURL);
+ findViewById(R.id.encode_email).setOnClickListener(mEncodeEmail);
+ findViewById(R.id.encode_phone).setOnClickListener(mEncodePhone);
+ findViewById(R.id.encode_sms).setOnClickListener(mEncodeSMS);
+ findViewById(R.id.encode_contact).setOnClickListener(mEncodeContact);
+ findViewById(R.id.encode_location).setOnClickListener(mEncodeLocation);
+ findViewById(R.id.encode_bad_data).setOnClickListener(mEncodeBadData);
+ findViewById(R.id.share_via_barcode).setOnClickListener(mShareViaBarcode);
+ }
- View encode_bad_data = findViewById(R.id.encode_bad_data);
- encode_bad_data.setOnClickListener(mEncodeBadData);
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ menu.add(0, ABOUT_ID, 0, R.string.about_menu)
+ .setIcon(android.R.drawable.ic_menu_info_details);
+ return true;
+ }
- View share_via_barcode = findViewById(R.id.share_via_barcode);
- share_via_barcode.setOnClickListener(mShareViaBarcode);
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case ABOUT_ID:
+ int versionCode = 0;
+ String versionName = "unknown";
+ try {
+ PackageInfo info = getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
+ versionCode = info.versionCode;
+ versionName = info.versionName;
+ } catch (PackageManager.NameNotFoundException e) {
+ }
+ 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();
+ break;
+ }
+ return super.onOptionsItemSelected(item);
}
- public final Button.OnClickListener mTestCamera = new Button.OnClickListener() {
+ public final Button.OnClickListener mTakeTestPhotos = new Button.OnClickListener() {
+ public void onClick(View v) {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setClassName(ZXingTestActivity.this, CameraTestActivity.class.getName());
+ intent.putExtra(CameraTestActivity.GET_CAMERA_PARAMETERS, false);
+ startActivity(intent);
+ }
+ };
+
+ public final Button.OnClickListener mGetCameraParameters = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(ZXingTestActivity.this, CameraTestActivity.class.getName());
+ intent.putExtra(CameraTestActivity.GET_CAMERA_PARAMETERS, true);
startActivity(intent);
}
};