diff --git a/androidtest/AndroidManifest.xml b/androidtest/AndroidManifest.xml index 65ae1400e..2d3003740 100755 --- a/androidtest/AndroidManifest.xml +++ b/androidtest/AndroidManifest.xml @@ -21,8 +21,9 @@ android:installLocation="auto"> + - + diff --git a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java index c19b3861c..1052083f6 100755 --- a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java +++ b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java @@ -16,6 +16,8 @@ package com.google.zxing.client.androidtest; +import java.io.File; + import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; @@ -37,7 +39,8 @@ public final class BenchmarkActivity extends Activity { public void onClick(View v) { if (benchmarkTask == null) { String path = Environment.getExternalStorageDirectory().getPath() + "/zxingbenchmark"; - benchmarkTask = new BenchmarkAsyncTask(BenchmarkActivity.this, path); + 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); diff --git a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkAsyncTask.java b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkAsyncTask.java index 4fd2bfded..97d129d98 100644 --- a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkAsyncTask.java +++ b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkAsyncTask.java @@ -42,11 +42,11 @@ public final class BenchmarkAsyncTask extends AsyncTask { private static final int RUNS = 10; private final BenchmarkActivity benchmarkActivity; - private final String path; + private final File file; - BenchmarkAsyncTask(BenchmarkActivity benchmarkActivity, String path) { + BenchmarkAsyncTask(BenchmarkActivity benchmarkActivity, File file) { this.benchmarkActivity = benchmarkActivity; - this.path = path; + this.file = file; } @Override @@ -57,7 +57,7 @@ public final class BenchmarkAsyncTask extends AsyncTask { System.gc(); List items = new ArrayList<>(); - walkTree(reader, path, items); + walkTree(reader, file, items); int count = 0; int time = 0; @@ -76,27 +76,31 @@ public final class BenchmarkAsyncTask extends AsyncTask { benchmarkActivity.onBenchmarkDone(totals); } - private static void walkTree(MultiFormatReader reader, String currentPath, List items) { - File file = new File(currentPath); - if (file.isDirectory()) { - String[] files = file.list(); - Arrays.sort(files); - for (String fileName : files) { - walkTree(reader, file.getAbsolutePath() + '/' + fileName, items); + private static void walkTree(MultiFormatReader reader, + File fileOrDir, + List 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, currentPath); + BenchmarkItem item = decode(reader, fileOrDir); if (item != null) { items.add(item); } } } - private static BenchmarkItem decode(MultiFormatReader reader, String path) { + private static BenchmarkItem decode(MultiFormatReader reader, File file) { - Bitmap imageBitmap = BitmapFactory.decodeFile(path); + Bitmap imageBitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); if (imageBitmap == null) { - Log.e(TAG, "Couldn't open " + path); + Log.e(TAG, "Couldn't open " + file); return null; } @@ -107,7 +111,7 @@ public final class BenchmarkAsyncTask extends AsyncTask { RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); - BenchmarkItem item = new BenchmarkItem(path, RUNS); + BenchmarkItem item = new BenchmarkItem(file, RUNS); for (int x = 0; x < RUNS; x++) { boolean success; Result result = null; diff --git a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkItem.java b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkItem.java index acb9bfad2..f93e6193c 100644 --- a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkItem.java +++ b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkItem.java @@ -16,21 +16,23 @@ package com.google.zxing.client.androidtest; +import java.io.File; + import com.google.zxing.BarcodeFormat; final class BenchmarkItem { - private final String path; + private final File file; private final int[] times; private int position; private boolean decoded; private BarcodeFormat format; - BenchmarkItem(String path, int runs) { + BenchmarkItem(File file, int runs) { if (runs <= 0) { throw new IllegalArgumentException(); } - this.path = path; + this.file = file; times = new int[runs]; position = 0; decoded = false; @@ -52,7 +54,7 @@ final class BenchmarkItem { @Override public String toString() { - return (decoded ? "DECODED " + format + ": " : "FAILED: ") + path + + return (decoded ? "DECODED " + format + ": " : "FAILED: ") + file + " (" + getAverageTime() + " us average)"; }