From f62aafcf44f4a724c82c8c92df155a119052ad31 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sat, 24 Apr 2010 23:16:49 +0200 Subject: Full Unicode database. But progress bar does not work. The Unicode database should be populated from the assets by calling .populate() on it: this works but, for some reason, the progress bar does not appear. --- .../madore/android/unicodeMap/UnicodeDatabase.java | 103 +++++++++++++-------- .../android/unicodeMap/UnicodeListActivity.java | 2 +- 2 files changed, 66 insertions(+), 39 deletions(-) (limited to 'src/org') diff --git a/src/org/madore/android/unicodeMap/UnicodeDatabase.java b/src/org/madore/android/unicodeMap/UnicodeDatabase.java index 9dff87f..ef12b66 100644 --- a/src/org/madore/android/unicodeMap/UnicodeDatabase.java +++ b/src/org/madore/android/unicodeMap/UnicodeDatabase.java @@ -2,6 +2,7 @@ package org.madore.android.unicodeMap; import java.util.Iterator; import java.util.NoSuchElementException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; @@ -9,6 +10,8 @@ import java.io.UnsupportedEncodingException; import java.sql.SQLException; 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; @@ -29,42 +32,12 @@ public class UnicodeDatabase { this.context = context; } - protected void parseUnicodeData(SQLiteDatabase db) { - AssetManager amgr = context.getAssets(); - try { - BufferedReader rd - = new BufferedReader(new InputStreamReader(amgr.open("UnicodeData.txt"), - "US-ASCII")); - SQLiteStatement cmd - = db.compileStatement("INSERT INTO "+UNICODE_TABLE_NAME - +" VALUES ( ? , ? , ? )"); - String line; - while ( ( line = rd.readLine() ) != null ) { - String[] fields = line.split(";"); - int codePoint = Integer.parseInt(fields[0], 16); - String name = fields[1]; - String category = fields[2]; - if ( name.charAt(0) == '<' ) - continue; - cmd.bindLong(1, codePoint); - cmd.bindString(2, name); - cmd.bindString(3, category); - cmd.execute(); - } - } catch (UnsupportedEncodingException e) { - throw new AssertionError("US-ASCII encoding unsupported"); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE "+UNICODE_TABLE_NAME+" ( " +"id INTEGER PRIMARY KEY , " +"name TEXT , " +"category TEXT )"); - parseUnicodeData(db); } @Override @@ -76,17 +49,71 @@ public class UnicodeDatabase { } + Activity activity; + DatabaseInit dbinit; SQLiteDatabase db; - public UnicodeDatabase(Context context) { - DatabaseInit dbinit = new DatabaseInit(context); - if ( true ) - db = dbinit.getReadableDatabase(); - else { - db = dbinit.getWritableDatabase(); - db.execSQL("DELETE FROM "+UNICODE_TABLE_NAME); - dbinit.parseUnicodeData(db); + public UnicodeDatabase(Activity activity) { + this.activity = activity; + this.dbinit = new DatabaseInit(activity); + db = dbinit.getReadableDatabase(); + } + + public void populate() { + 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(); + 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