import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.text.SimpleDateFormat;
+import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import com.hughes.android.dictionary.Dictionary.IndexEntry;
import com.hughes.android.dictionary.Dictionary.LanguageData;
import com.hughes.android.dictionary.Dictionary.Row;
+import com.ibm.icu.text.Collator;
public class DictionaryActivity extends ListActivity {
// Visible for testing.
LanguageListAdapter languageList = null;
private SearchOperation searchOperation = null;
+
+ public DictionaryActivity() {
+
+ searchExecutor.execute(new Runnable() {
+ public void run() {
+ final long startMillis = System.currentTimeMillis();
+ for (final String lang : Arrays.asList("EN", "DE")) {
+ Language.lookup(lang).getFindCollator();
+ final Collator c = Language.lookup(lang).getSortCollator();
+ if (c.compare("pre-print", "preppy") >= 0) {
+ Log.e(LOG, c.getClass() + " is buggy, lookups may not work properly.");
+ }
+ }
+ Log.d(LOG, "Loading collators took:" + (System.currentTimeMillis() - startMillis));
+ }
+ });
+
+ }
/** Called when the activity is first created. */
@Override
super.onCreate(savedInstanceState);
Log.d(LOG, "onCreate:" + this);
- if (Language.EN.sortCollator.compare("pre-print", "preppy") >= 0) {
- Log
- .e(LOG,
- Language.EN.sortCollator.getClass() + " is buggy, lookups may not work properly.");
- }
-
try {
initDictionaryAndPrefs();
} catch (Exception e) {
Log.d(LOG, "dictFile=" + dictFile);
try {
- if (!dictFile.canRead()) {
- throw new IOException("Unable to read dictionary file.");
- }
-
- dictRaf = new RandomAccessFile(dictFile, "r");
- dictionary = new Dictionary(dictRaf);
+ if (!dictFile.canRead()) {
+ throw new IOException("Unable to read dictionary file.");
+ }
+
+ dictRaf = new RandomAccessFile(dictFile, "r");
+ final long startMillis = System.currentTimeMillis();
+ dictionary = new Dictionary(dictRaf);
+ Log.d(LOG, "Read dictionary millis: " + (System.currentTimeMillis() - startMillis));
} catch (IOException e) {
Log.e(LOG, "Couldn't open dictionary.", e);
this.startActivity(new Intent(this, NoDictionaryActivity.class));
private void closeCurrentDictionary() {
Log.i(LOG, "closeCurrentDictionary");
+ if (dictionary == null) {
+ return;
+ }
waitForSearchEnd();
languageList = null;
setListAdapter(null);
+ Log.d(LOG, "setListAdapter finished.");
dictionary = null;
try {
if (dictRaf != null) {
void waitForSearchEnd() {
synchronized (this) {
while (searchOperation != null) {
+ Log.d(LOG, "waitForSearchEnd");
try {
this.wait();
} catch (InterruptedException e) {
final String symbol;\r
final Locale locale;\r
\r
- final Collator sortCollator;\r
+ private Collator sortCollator;\r
final Comparator<String> sortComparator;\r
\r
- final Collator findCollator;\r
+ private Collator findCollator;\r
final Comparator<String> findComparator;\r
\r
public Language(final String symbol, final Locale locale) {\r
this.symbol = symbol;\r
this.locale = locale;\r
\r
- this.sortCollator = Collator.getInstance(locale);\r
- this.sortCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
- this.sortCollator.setStrength(Collator.IDENTICAL);\r
this.sortComparator = new Comparator<String>() {\r
public int compare(final String s1, final String s2) {\r
- return sortCollator.compare(textNorm(s1), textNorm(s2));\r
+ return getSortCollator().compare(textNorm(s1), textNorm(s2));\r
}\r
};\r
\r
- this.findCollator = Collator.getInstance(locale);\r
- this.findCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
- this.findCollator.setStrength(Collator.SECONDARY);\r
this.findComparator = new Comparator<String>() {\r
public int compare(final String s1, final String s2) {\r
- return findCollator.compare(textNorm(s1), textNorm(s2));\r
+ return getFindCollator().compare(textNorm(s1), textNorm(s2));\r
}\r
};\r
\r
public String toString() {\r
return symbol;\r
}\r
+ \r
+ synchronized Collator getFindCollator() {\r
+ if (findCollator == null) {\r
+ findCollator = Collator.getInstance(locale);\r
+ findCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
+ findCollator.setStrength(Collator.SECONDARY);\r
+ }\r
+ return findCollator;\r
+ }\r
+\r
+ synchronized Collator getSortCollator() {\r
+ if (sortCollator == null) {\r
+ sortCollator = Collator.getInstance(locale);\r
+ sortCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);\r
+ sortCollator.setStrength(Collator.IDENTICAL);\r
+ }\r
+ return sortCollator;\r
+ }\r
\r
// ----------------------------------------------------------------\r
\r