summaryrefslogtreecommitdiffstats
path: root/src/org/madore
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/madore')
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeDatabase.java103
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeListActivity.java2
2 files changed, 66 insertions, 39 deletions
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<pieces.length ; cnt++ ) {
+ progress.show();
+ progress.setProgress(cnt*10000/pieces.length);
+ String file = pieces[cnt];
+ BufferedReader rd
+ = new BufferedReader(new InputStreamReader(amgr.open(file),
+ "US-ASCII"));
+ 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();
+ }
+ rd.close();
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new AssertionError("US-ASCII encoding unsupported");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
+ progress.dismiss();
+ db.close();
}
protected final static String[] queryColumns = { "id", "name", "category" };
diff --git a/src/org/madore/android/unicodeMap/UnicodeListActivity.java b/src/org/madore/android/unicodeMap/UnicodeListActivity.java
index 8f962f0..1495bbc 100644
--- a/src/org/madore/android/unicodeMap/UnicodeListActivity.java
+++ b/src/org/madore/android/unicodeMap/UnicodeListActivity.java
@@ -25,7 +25,7 @@ public final class UnicodeListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- this.db = new UnicodeDatabase(getApplicationContext());
+ this.db = new UnicodeDatabase(this);
Intent intent = getIntent();
int from = intent.getIntExtra(EXTRA_FROM, 0);
int to = intent.getIntExtra(EXTRA_TO, from+128);