From 0e64b9e42047a96e26395002b8287a70f2da2eea Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 25 Apr 2010 10:22:19 +0200 Subject: Repair progress bar. Use a transaction for populating db. Default max for progress bar is not 10000 contrary to what doc says. SQLite is excruciatingly slow in the absence of transactions, so we use one. --- src/org/madore/android/unicodeMap/UnicodeDatabase.java | 7 +++++-- src/org/madore/android/unicodeMap/UnicodeMapActivity.java | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/org') diff --git a/src/org/madore/android/unicodeMap/UnicodeDatabase.java b/src/org/madore/android/unicodeMap/UnicodeDatabase.java index b0b5c77..c40cf67 100644 --- a/src/org/madore/android/unicodeMap/UnicodeDatabase.java +++ b/src/org/madore/android/unicodeMap/UnicodeDatabase.java @@ -73,6 +73,7 @@ public class UnicodeDatabase { public void populate(Handler progressHandler) { SQLiteDatabase db = dbinit.getWritableDatabase(); + db.beginTransaction(); db.execSQL("DELETE FROM "+UNICODE_TABLE_NAME); AssetManager amgr = activity.getAssets(); SQLiteStatement cmd @@ -116,9 +117,11 @@ public class UnicodeDatabase { throw new AssertionError("US-ASCII encoding unsupported"); } catch (IOException e) { throw new RuntimeException(e); + } finally { + db.endTransaction(); + db.close(); + reportProgress(progressHandler, pieces.length, pieces.length); } - reportProgress(progressHandler, pieces.length, pieces.length); - db.close(); } protected final static String[] queryColumns = { "id", "name", "category" }; diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java index 7d70186..a1917a4 100644 --- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java +++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java @@ -44,12 +44,14 @@ public final class UnicodeMapActivity extends ListActivity { progress.setTitle("Loading Unicode database"); progress.setMessage("Please wait"); progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + progress.setCancelable(false); progress.show(); final Handler handler = new Handler() { public void handleMessage(Message msg) { int done = msg.getData().getInt("done"); int total = msg.getData().getInt("total"); - progress.setProgress(done*10000/total); + progress.setMax(total); + progress.setProgress(done); if ( done >= total ) progress.dismiss(); } -- cgit v1.2.3