From 2521f18e396b989043387ef0cd14eeb101c14263 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 25 Apr 2010 00:33:15 +0200 Subject: Use a separate thread for populating database. Still doesn't work. I don't understand the point of this whole rigmarole, nor do I understand why it doesn't work... :-( --- .../madore/android/unicodeMap/UnicodeDatabase.java | 51 ++++++++++++---------- .../android/unicodeMap/UnicodeMapActivity.java | 26 +++++++++++ 2 files changed, 54 insertions(+), 23 deletions(-) (limited to 'src/org') diff --git a/src/org/madore/android/unicodeMap/UnicodeDatabase.java b/src/org/madore/android/unicodeMap/UnicodeDatabase.java index ef12b66..b0b5c77 100644 --- a/src/org/madore/android/unicodeMap/UnicodeDatabase.java +++ b/src/org/madore/android/unicodeMap/UnicodeDatabase.java @@ -8,10 +8,12 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.sql.SQLException; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; import android.content.Context; import android.content.res.AssetManager; import android.app.Activity; -import android.app.ProgressDialog; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; @@ -59,35 +61,38 @@ public class UnicodeDatabase { db = dbinit.getReadableDatabase(); } - public void populate() { + protected void reportProgress(Handler progressHandler, + int done, int total) { + Message msg = progressHandler.obtainMessage(); + Bundle b = new Bundle(); + b.putInt("done", done); + b.putInt("total", total); + msg.setData(b); + progressHandler.sendMessage(msg); + } + + public void populate(Handler progressHandler) { SQLiteDatabase db = dbinit.getWritableDatabase(); db.execSQL("DELETE FROM "+UNICODE_TABLE_NAME); AssetManager amgr = activity.getAssets(); SQLiteStatement cmd = db.compileStatement("INSERT INTO "+UNICODE_TABLE_NAME +" VALUES ( ? , ? , ? )"); - ProgressDialog progress = new ProgressDialog(activity); - progress.setOwnerActivity(activity); - progress.setTitle("Loading Unicode database"); - progress.setMessage("Please wait"); - progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progress.show(); + final String[] pieces = { + "UnicodeData-00.txt", "UnicodeData-01.txt", + "UnicodeData-02.txt", "UnicodeData-03.txt", + "UnicodeData-04.txt", "UnicodeData-05.txt", + "UnicodeData-06.txt", "UnicodeData-07.txt", + "UnicodeData-08.txt", "UnicodeData-09.txt", + "UnicodeData-10.txt", "UnicodeData-11.txt", + "UnicodeData-12.txt", "UnicodeData-13.txt", + "UnicodeData-14.txt", "UnicodeData-15.txt", + "UnicodeData-16.txt", "UnicodeData-17.txt", + "UnicodeData-18.txt", "UnicodeData-19.txt" + }; try { - final String[] pieces = { - "UnicodeData-00.txt", "UnicodeData-01.txt", - "UnicodeData-02.txt", "UnicodeData-03.txt", - "UnicodeData-04.txt", "UnicodeData-05.txt", - "UnicodeData-06.txt", "UnicodeData-07.txt", - "UnicodeData-08.txt", "UnicodeData-09.txt", - "UnicodeData-10.txt", "UnicodeData-11.txt", - "UnicodeData-12.txt", "UnicodeData-13.txt", - "UnicodeData-14.txt", "UnicodeData-15.txt", - "UnicodeData-16.txt", "UnicodeData-17.txt", - "UnicodeData-18.txt", "UnicodeData-19.txt" - }; for ( int cnt=0 ; cnt= total ) + progress.dismiss(); + } + }; + final Thread thr = new Thread() { + public void run() { + UnicodeDatabase db + = new UnicodeDatabase(UnicodeMapActivity.this); + db.populate(handler); + } + }; + thr.start(); setListAdapter(new ArrayAdapter(this, R.layout.list_item, list)); ListView lv = getListView(); lv.setTextFilterEnabled(true); -- cgit v1.2.3