More reckless refactoring and code style tweaks -- mostly adding braces around condit...
[zxing.git] / androidtest / src / com / google / zxing / client / androidtest / BenchmarkActivity.java
1 /*
2  * Copyright (C) 2008 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.androidtest;
18
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;
27
28 import java.util.List;
29
30 public final class BenchmarkActivity extends Activity {
31
32   private static final String PATH = "/sdcard/zxingbenchmark";
33   private static final String TAG = "ZXingBenchmark";
34
35   private Button mRunBenchmarkButton;
36   private TextView mTextView;
37   private BenchmarkThread mBenchmarkThread;
38
39   @Override
40   public void onCreate(Bundle icicle) {
41     super.onCreate(icicle);
42
43     setContentView(R.layout.benchmark);
44
45     mRunBenchmarkButton = (Button) findViewById(R.id.benchmark_run);
46     mRunBenchmarkButton.setOnClickListener(mRunBenchmark);
47     mTextView = (TextView) findViewById(R.id.benchmark_help);
48
49     mBenchmarkThread = null;
50   }
51
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();
59       }
60     }
61   };
62
63   public final Handler mHandler = new Handler() {
64     @Override
65     public void handleMessage(Message message) {
66       switch (message.what) {
67         case R.id.benchmark_done:
68           handleBenchmarkDone(message);
69           mBenchmarkThread = null;
70           mRunBenchmarkButton.setEnabled(true);
71           mTextView.setText(R.string.benchmark_help);
72           break;
73         default:
74           break;
75       }
76     }
77   };
78
79   private void handleBenchmarkDone(Message message) {
80     List<BenchmarkItem> items = (List<BenchmarkItem>) message.obj;
81     int count = 0;
82     for (int x = 0; x < items.size(); x++) {
83       BenchmarkItem item = items.get(x);
84       if (item != null) {
85         Log.v(TAG, item.toString());
86         count++;
87       }
88     }
89     Log.v(TAG, "TOTAL: Decoded " + count + " images");
90   }
91
92 }