2 * Copyright (C) 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.androidtest;
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.os.Handler;
22 import android.os.Message;
23 import android.util.Log;
24 import android.view.View;
25 import android.widget.Button;
26 import android.widget.TextView;
28 import java.util.List;
30 public final class BenchmarkActivity extends Activity {
32 private static final String PATH = "/sdcard/zxingbenchmark";
33 private static final String TAG = "ZXingBenchmark";
35 private Button mRunBenchmarkButton;
36 private TextView mTextView;
37 private BenchmarkThread mBenchmarkThread;
40 public final void onCreate(Bundle icicle) {
41 super.onCreate(icicle);
43 setContentView(R.layout.benchmark);
45 mRunBenchmarkButton = (Button) findViewById(R.id.benchmark_run);
46 mRunBenchmarkButton.setOnClickListener(mRunBenchmark);
47 mTextView = (TextView) findViewById(R.id.benchmark_help);
49 mBenchmarkThread = null;
52 public final Button.OnClickListener mRunBenchmark = new Button.OnClickListener() {
53 public void onClick(View v) {
54 if (mBenchmarkThread == null) {
55 mRunBenchmarkButton.setEnabled(false);
56 mTextView.setText(R.string.benchmark_running);
57 mBenchmarkThread = new BenchmarkThread(BenchmarkActivity.this, PATH);
58 mBenchmarkThread.start();
63 public final Handler mHandler = new Handler() {
64 public void handleMessage(Message message) {
65 switch (message.what) {
66 case R.id.benchmark_done:
67 handleBenchmarkDone(message);
68 mBenchmarkThread = null;
69 mRunBenchmarkButton.setEnabled(true);
70 mTextView.setText(R.string.benchmark_help);
78 private void handleBenchmarkDone(Message message) {
79 List<BenchmarkItem> items = (List<BenchmarkItem>) message.obj;
81 for (int x = 0; x < items.size(); x++) {
82 BenchmarkItem item = items.get(x);
84 Log.v(TAG, item.toString());
88 Log.v(TAG, "TOTAL: Decoded " + count + " images");