01: package org.garret.bench;
02:
03: import android.app.Activity;
04: import android.os.Bundle;
05: import android.widget.*;
06: import android.view.*;
07: import java.io.*;
08:
09: public class Benchmark extends Activity {
10:
11: static final private int PERST_ID = Menu.FIRST;
12: static final private int SQLITE_ID = Menu.FIRST + 1;
13: static final private int DB4O_ID = Menu.FIRST + 2;
14:
15: TextView tv;
16:
17: /**
18: * Called when your activity's options menu needs to be created.
19: */
20: @Override
21: public boolean onCreateOptionsMenu(Menu menu) {
22: super .onCreateOptionsMenu(menu);
23:
24: // We are going to create two menus. Note that we assign them
25: // unique integer IDs, labels from our string resources, and
26: // given them shortcuts.
27: menu.add(0, PERST_ID, R.string.perst);
28: //menu.add(0, DB4O_ID, R.string.db4o);
29: menu.add(0, SQLITE_ID, R.string.sqlite);
30:
31: return true;
32: }
33:
34: /** Called when the activity is first created. */
35: @Override
36: public void onCreate(Bundle icicle) {
37: super .onCreate(icicle);
38: tv = new TextView(this );
39: tv.setText(R.string.about);
40: setContentView(tv);
41: }
42:
43: /**
44: * Called when a menu item is selected.
45: */
46: @Override
47: public boolean onOptionsItemSelected(Menu.Item item) {
48: ByteArrayOutputStream out = new ByteArrayOutputStream();
49: String databasePath = "testindex.dbs";
50:
51: try {
52: this .openFileOutput(databasePath, 0).close();
53: databasePath = getFileStreamPath(databasePath)
54: .getAbsolutePath();
55: } catch (IOException x) {
56: }
57:
58: PrintStream ps = new PrintStream(out);
59: Test test;
60: switch (item.getId()) {
61: case PERST_ID:
62: test = new PerstTest(databasePath, ps);
63: break;
64: case SQLITE_ID:
65: test = new SqlLiteTest(databasePath, ps);
66: break;
67: /*
68: case DB4O_ID:
69: test = new Db4oTest(databasePath, ps);
70: break;
71: */
72: default:
73: return super .onOptionsItemSelected(item);
74: }
75: new Thread(test).start();
76: new Thread(new ProgressMonitor(test, tv, out)).start();
77: return true;
78: }
79:
80: }
|