]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/DictionaryApplication.java
Add menu item to download dictionaries in browser.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryApplication.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.hughes.android.dictionary;
16
17 import android.app.Application;
18 import android.content.Context;
19 import android.content.Intent;
20 import android.content.SharedPreferences;
21 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
22 import android.net.Uri;
23 import android.os.Build;
24 import android.os.Environment;
25 import android.preference.PreferenceManager;
26 import android.support.v4.view.MenuItemCompat;
27 import android.util.Log;
28 import android.util.TypedValue;
29 import android.view.Menu;
30 import android.view.MenuItem;
31 import android.view.MenuItem.OnMenuItemClickListener;
32 import android.view.View;
33 import android.widget.Button;
34 import android.widget.ImageButton;
35 import android.widget.ImageView.ScaleType;
36 import android.widget.LinearLayout;
37 import android.widget.Toast;
38
39 import com.hughes.android.dictionary.CollatorWrapper;
40 import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
41 import com.hughes.android.dictionary.engine.Dictionary;
42 import com.hughes.android.dictionary.engine.Language;
43 import com.hughes.android.dictionary.engine.Language.LanguageResources;
44 import com.hughes.android.dictionary.engine.TransliteratorManager;
45 import com.hughes.android.util.PersistentObjectCache;
46 import com.hughes.util.ListUtil;
47
48 import java.io.BufferedReader;
49 import java.io.File;
50 import java.io.IOException;
51 import java.io.InputStreamReader;
52 import java.io.Serializable;
53 import java.util.ArrayList;
54 import java.util.Collections;
55 import java.util.Comparator;
56 import java.util.HashMap;
57 import java.util.List;
58 import java.util.Locale;
59 import java.util.Map;
60
61 public enum DictionaryApplication {
62     INSTANCE;
63
64     private Context appContext;
65
66     static final String LOG = "QuickDicApp";
67
68     // If set to false, avoid use of ICU collator
69     // Works well enough for most european languages,
70     // gives faster startup and avoids crashes on some
71     // devices due to Dalvik bugs (e.g. ARMv6, S5570i, CM11)
72     // when using ICU4J.
73     // Leave it enabled by default for correctness except
74     // for my known broken development/performance test device config.
75     //static public final boolean USE_COLLATOR = !android.os.Build.FINGERPRINT.equals("Samsung/cm_tassve/tassve:4.4.4/KTU84Q/20150211:userdebug/release-keys");
76     static public final boolean USE_COLLATOR = true;
77
78     static public final TransliteratorManager.ThreadSetup threadBackground = new TransliteratorManager.ThreadSetup() {
79         @Override
80         public void onThreadStart() {
81             // THREAD_PRIORITY_BACKGROUND seemed like a good idea, but it
82             // can make Transliterator go from 20 seconds to 3 minutes (!)
83             android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE);
84         }
85     };
86
87     // Static, determined by resources (and locale).
88     // Unordered.
89     static Map<String, DictionaryInfo> DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = null;
90
91     enum Theme {
92         DEFAULT(R.style.Theme_Default,
93         R.style.Theme_Default_TokenRow_Fg,
94         R.color.theme_default_token_row_fg,
95         R.drawable.theme_default_token_row_main_bg,
96         R.drawable.theme_default_token_row_other_bg,
97         R.drawable.theme_default_normal_row_bg),
98
99         LIGHT(R.style.Theme_Light,
100         R.style.Theme_Light_TokenRow_Fg,
101         R.color.theme_light_token_row_fg,
102         R.drawable.theme_light_token_row_main_bg,
103         R.drawable.theme_light_token_row_other_bg,
104         R.drawable.theme_light_normal_row_bg);
105
106         Theme(final int themeId, final int tokenRowFg,
107         final int tokenRowFgColor,
108         final int tokenRowMainBg, final int tokenRowOtherBg,
109         final int normalRowBg) {
110             this.themeId = themeId;
111             this.tokenRowFg = tokenRowFg;
112             this.tokenRowFgColor = tokenRowFgColor;
113             this.tokenRowMainBg = tokenRowMainBg;
114             this.tokenRowOtherBg = tokenRowOtherBg;
115             this.normalRowBg = normalRowBg;
116         }
117
118         final int themeId;
119         final int tokenRowFg;
120         final int tokenRowFgColor;
121         final int tokenRowMainBg;
122         final int tokenRowOtherBg;
123         final int normalRowBg;
124     }
125
126     public static final class DictionaryConfig implements Serializable {
127         private static final long serialVersionUID = -1444177164708201263L;
128         // User-ordered list, persisted, just the ones that are/have been
129         // present.
130         final List<String> dictionaryFilesOrdered = new ArrayList<String>();
131
132         final Map<String, DictionaryInfo> uncompressedFilenameToDictionaryInfo = new HashMap<String, DictionaryInfo>();
133
134         /**
135          * Sometimes a deserialized version of this data structure isn't valid.
136          * @return
137          */
138         boolean isValid() {
139             return uncompressedFilenameToDictionaryInfo != null && dictionaryFilesOrdered != null;
140         }
141     }
142
143     DictionaryConfig dictionaryConfig = null;
144
145     public int languageButtonPixels = -1;
146
147     static synchronized void staticInit(final Context context) {
148         if (DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO != null) {
149             return;
150         }
151         DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = new HashMap<String, DictionaryInfo>();
152         final BufferedReader reader = new BufferedReader(
153             new InputStreamReader(context.getResources().openRawResource(R.raw.dictionary_info)));
154         try {
155             String line;
156             while ((line = reader.readLine()) != null) {
157                 if (line.length() == 0 || line.charAt(0) == '#') {
158                     continue;
159                 }
160                 final DictionaryInfo dictionaryInfo = new DictionaryInfo(line);
161                 DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.put(
162                     dictionaryInfo.uncompressedFilename, dictionaryInfo);
163             }
164         } catch (IOException e) {
165             Log.e(LOG, "Failed to load downloadable dictionary lists.", e);
166         }
167         try {
168             reader.close();
169         } catch (IOException e) {}
170     }
171
172     private File dictDir;
173
174     public synchronized void init(Context c) {
175         if (appContext != null) {
176             assert c == appContext;
177             return;
178         }
179         appContext = c;
180         Log.d("QuickDic", "Application: onCreate");
181         TransliteratorManager.init(null, threadBackground);
182         staticInit(appContext);
183
184         languageButtonPixels = (int) TypedValue.applyDimension(
185                                    TypedValue.COMPLEX_UNIT_DIP, 60, appContext.getResources().getDisplayMetrics());
186
187         // Load the dictionaries we know about.
188         dictionaryConfig = PersistentObjectCache.init(appContext).read(
189                                C.DICTIONARY_CONFIGS, DictionaryConfig.class);
190         if (dictionaryConfig == null) {
191             dictionaryConfig = new DictionaryConfig();
192         }
193         if (!dictionaryConfig.isValid()) {
194             dictionaryConfig = new DictionaryConfig();
195         }
196
197         // Theme stuff.
198         appContext.setTheme(getSelectedTheme().themeId);
199         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
200         prefs.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
201             @Override
202             public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
203                                                   String key) {
204                 Log.d("QuickDic", "prefs changed: " + key);
205                 if (key.equals(appContext.getString(R.string.themeKey))) {
206                     appContext.setTheme(getSelectedTheme().themeId);
207                 }
208             }
209         });
210     }
211
212     public static void onCreateGlobalOptionsMenu(
213         final Context context, final Menu menu) {
214         final Context c = context.getApplicationContext();
215         final MenuItem about = menu.add(c.getString(R.string.about));
216         MenuItemCompat.setShowAsAction(about, MenuItem.SHOW_AS_ACTION_NEVER);
217         about.setOnMenuItemClickListener(new OnMenuItemClickListener() {
218             public boolean onMenuItemClick(final MenuItem menuItem) {
219                 final Intent intent = new Intent(c, AboutActivity.class);
220                 context.startActivity(intent);
221                 return false;
222             }
223         });
224
225         final MenuItem help = menu.add(c.getString(R.string.help));
226         MenuItemCompat.setShowAsAction(help, MenuItem.SHOW_AS_ACTION_NEVER);
227         help.setOnMenuItemClickListener(new OnMenuItemClickListener() {
228             public boolean onMenuItemClick(final MenuItem menuItem) {
229                 context.startActivity(HtmlDisplayActivity.getHelpLaunchIntent(c));
230                 return false;
231             }
232         });
233
234         final MenuItem preferences = menu.add(c.getString(R.string.settings));
235         MenuItemCompat.setShowAsAction(preferences, MenuItem.SHOW_AS_ACTION_NEVER);
236         preferences.setOnMenuItemClickListener(new OnMenuItemClickListener() {
237             public boolean onMenuItemClick(final MenuItem menuItem) {
238                 PreferenceActivity.prefsMightHaveChanged = true;
239                 final Intent intent = new Intent(c, PreferenceActivity.class);
240                 context.startActivity(intent);
241                 return false;
242             }
243         });
244
245         final MenuItem reportIssue = menu.add(c.getString(R.string.reportIssue));
246         MenuItemCompat.setShowAsAction(reportIssue, MenuItem.SHOW_AS_ACTION_NEVER);
247         reportIssue.setOnMenuItemClickListener(new OnMenuItemClickListener() {
248             public boolean onMenuItemClick(final MenuItem menuItem) {
249                 final Intent intent = new Intent(Intent.ACTION_VIEW);
250                 intent.setData(Uri
251                                .parse("https://github.com/rdoeffinger/Dictionary/issues"));
252                 context.startActivity(intent);
253                 return false;
254             }
255         });
256
257         final MenuItem browserDownload = menu.add(c.getString(R.string.browserDownload));
258         MenuItemCompat.setShowAsAction(browserDownload, MenuItem.SHOW_AS_ACTION_NEVER);
259         browserDownload.setOnMenuItemClickListener(new OnMenuItemClickListener() {
260             public boolean onMenuItemClick(final MenuItem menuItem) {
261                 final Intent intent = new Intent(Intent.ACTION_VIEW);
262                 intent.setData(Uri
263                                .parse("https://github.com/rdoeffinger/Dictionary/releases/v0.2-dictionaries"));
264                 context.startActivity(intent);
265                 return false;
266             }
267         });
268     }
269
270     private String selectDefaultDir() {
271         final File defaultDictDir = new File(Environment.getExternalStorageDirectory(), "quickDic");
272         String dir = defaultDictDir.getAbsolutePath();
273         File dictDir = new File(dir);
274         String[] fileList = dictDir.isDirectory() ? dictDir.list() : null;
275         if (fileList != null && fileList.length > 0) {
276             return dir;
277         }
278         File efd = null;
279         try {
280             efd = appContext.getExternalFilesDir(null);
281         } catch (Exception e) {
282         }
283         if (efd != null) {
284             efd.mkdirs();
285             if (!dictDir.isDirectory() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
286                 appContext.getExternalFilesDirs(null);
287             }
288             if (efd.isDirectory() && efd.canWrite() && checkFileCreate(efd)) {
289                 return efd.getAbsolutePath();
290             }
291         }
292         if (!dictDir.isDirectory() && !dictDir.mkdirs()) {
293             return appContext.getFilesDir().getAbsolutePath();
294         }
295         return dir;
296     }
297
298     public synchronized File getDictDir() {
299         // This metaphor doesn't work, because we've already reset
300         // prefsMightHaveChanged.
301         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
302         String dir = prefs.getString(appContext.getString(R.string.quickdicDirectoryKey), "");
303         if (dir.isEmpty()) {
304             dir = selectDefaultDir();
305         }
306         dictDir = new File(dir);
307         dictDir.mkdirs();
308         if (!dictDir.isDirectory() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
309             appContext.getExternalFilesDirs(null);
310         }
311         return dictDir;
312     }
313
314     static public boolean checkFileCreate(File dir) {
315         boolean res = false;
316         File testfile = new File(dir, "quickdic_writetest");
317         try {
318             testfile.delete();
319             res = testfile.createNewFile() & testfile.delete();
320         } catch (Exception e) {
321         }
322         return res;
323     }
324
325     public File getWordListFile() {
326         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
327         String file = prefs.getString(appContext.getString(R.string.wordListFileKey), "");
328         if (file.isEmpty()) {
329             return new File(getDictDir(), "wordList.txt");
330         }
331         return new File(file);
332     }
333
334     public Theme getSelectedTheme() {
335         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
336         final String theme = prefs.getString(appContext.getString(R.string.themeKey), "themeLight");
337         if (theme.equals("themeLight")) {
338             return Theme.LIGHT;
339         } else {
340             return Theme.DEFAULT;
341         }
342     }
343
344     public File getPath(String uncompressedFilename) {
345         return new File(getDictDir(), uncompressedFilename);
346     }
347
348     String defaultLangISO2 = Locale.getDefault().getLanguage().toLowerCase();
349     String defaultLangName = null;
350     final Map<String, String> fileToNameCache = new HashMap<String, String>();
351
352     public List<IndexInfo> sortedIndexInfos(List<IndexInfo> indexInfos) {
353         // Hack to put the default locale first in the name.
354         if (indexInfos.size() > 1 &&
355                 indexInfos.get(1).shortName.toLowerCase().equals(defaultLangISO2)) {
356             List<IndexInfo> result = new ArrayList<DictionaryInfo.IndexInfo>(indexInfos);
357             ListUtil.swap(result, 0, 1);
358             return result;
359         }
360         return indexInfos;
361     }
362
363     public synchronized String getDictionaryName(final String uncompressedFilename) {
364         final String currentLocale = Locale.getDefault().getLanguage().toLowerCase();
365         if (!currentLocale.equals(defaultLangISO2)) {
366             defaultLangISO2 = currentLocale;
367             fileToNameCache.clear();
368             defaultLangName = null;
369         }
370         if (defaultLangName == null) {
371             defaultLangName = IsoUtils.INSTANCE.isoCodeToLocalizedLanguageName(appContext, defaultLangISO2);
372         }
373
374         String name = fileToNameCache.get(uncompressedFilename);
375         if (name != null) {
376             return name;
377         }
378
379         final DictionaryInfo dictionaryInfo = DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO
380                                               .get(uncompressedFilename);
381         if (dictionaryInfo != null) {
382             final StringBuilder nameBuilder = new StringBuilder();
383
384             List<IndexInfo> sortedIndexInfos = sortedIndexInfos(dictionaryInfo.indexInfos);
385             for (int i = 0; i < sortedIndexInfos.size(); ++i) {
386                 if (i > 0) {
387                     nameBuilder.append("-");
388                 }
389                 nameBuilder
390                 .append(IsoUtils.INSTANCE.isoCodeToLocalizedLanguageName(appContext, sortedIndexInfos.get(i).shortName));
391             }
392             name = nameBuilder.toString();
393         } else {
394             name = uncompressedFilename.replace(".quickdic", "");
395         }
396         fileToNameCache.put(uncompressedFilename, name);
397         return name;
398     }
399
400     public synchronized void moveDictionaryToTop(final DictionaryInfo dictionaryInfo) {
401         dictionaryConfig.dictionaryFilesOrdered.remove(dictionaryInfo.uncompressedFilename);
402         dictionaryConfig.dictionaryFilesOrdered.add(0, dictionaryInfo.uncompressedFilename);
403         PersistentObjectCache.getInstance().write(C.DICTIONARY_CONFIGS, dictionaryConfig);
404     }
405
406     public synchronized void sortDictionaries() {
407         Collections.sort(dictionaryConfig.dictionaryFilesOrdered, uncompressedFilenameComparator);
408         PersistentObjectCache.getInstance().write(C.DICTIONARY_CONFIGS, dictionaryConfig);
409     }
410
411     public synchronized void deleteDictionary(final DictionaryInfo dictionaryInfo) {
412         while (dictionaryConfig.dictionaryFilesOrdered.remove(dictionaryInfo.uncompressedFilename)) {
413         }
414         dictionaryConfig.uncompressedFilenameToDictionaryInfo
415         .remove(dictionaryInfo.uncompressedFilename);
416         getPath(dictionaryInfo.uncompressedFilename).delete();
417         PersistentObjectCache.getInstance().write(C.DICTIONARY_CONFIGS, dictionaryConfig);
418     }
419
420     final Comparator collator = USE_COLLATOR ? CollatorWrapper.getInstance() : String.CASE_INSENSITIVE_ORDER;
421     final Comparator<String> uncompressedFilenameComparator = new Comparator<String>() {
422         @Override
423         public int compare(String uncompressedFilename1, String uncompressedFilename2) {
424             final String name1 = getDictionaryName(uncompressedFilename1);
425             final String name2 = getDictionaryName(uncompressedFilename2);
426             if (defaultLangName.length() > 0) {
427                 if (name1.startsWith(defaultLangName + "-")
428                         && !name2.startsWith(defaultLangName + "-")) {
429                     return -1;
430                 } else if (name2.startsWith(defaultLangName + "-")
431                            && !name1.startsWith(defaultLangName + "-")) {
432                     return 1;
433                 }
434             }
435             return collator.compare(name1, name2);
436         }
437     };
438     final Comparator<DictionaryInfo> dictionaryInfoComparator = new Comparator<DictionaryInfo>() {
439         @Override
440         public int compare(DictionaryInfo d1, DictionaryInfo d2) {
441             // Single-index dictionaries first.
442             if (d1.indexInfos.size() != d2.indexInfos.size()) {
443                 return d1.indexInfos.size() - d2.indexInfos.size();
444             }
445             return uncompressedFilenameComparator.compare(d1.uncompressedFilename,
446                     d2.uncompressedFilename);
447         }
448     };
449
450     public void backgroundUpdateDictionaries(final Runnable onUpdateFinished) {
451         new Thread(new Runnable() {
452             @Override
453             public void run() {
454                 final DictionaryConfig oldDictionaryConfig = new DictionaryConfig();
455                 synchronized (DictionaryApplication.this) {
456                     oldDictionaryConfig.dictionaryFilesOrdered
457                     .addAll(dictionaryConfig.dictionaryFilesOrdered);
458                 }
459                 final DictionaryConfig newDictionaryConfig = new DictionaryConfig();
460                 for (final String uncompressedFilename : oldDictionaryConfig.dictionaryFilesOrdered) {
461                     final File dictFile = getPath(uncompressedFilename);
462                     final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(dictFile);
463                     if (dictionaryInfo.isValid() || dictFile.exists()) {
464                         newDictionaryConfig.dictionaryFilesOrdered.add(uncompressedFilename);
465                         newDictionaryConfig.uncompressedFilenameToDictionaryInfo.put(
466                             uncompressedFilename, dictionaryInfo);
467                     }
468                 }
469
470                 // Are there dictionaries on the device that we didn't know
471                 // about already?
472                 // Pick them up and put them at the end of the list.
473                 final List<String> toAddSorted = new ArrayList<String>();
474                 final File[] dictDirFiles = getDictDir().listFiles();
475                 if (dictDirFiles != null) {
476                     for (final File file : dictDirFiles) {
477                         if (file.getName().endsWith(".zip")) {
478                             if (DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO
479                                     .containsKey(file.getName().replace(".zip", ""))) {
480                                 file.delete();
481                             }
482                         }
483                         if (!file.getName().endsWith(".quickdic")) {
484                             continue;
485                         }
486                         if (newDictionaryConfig.uncompressedFilenameToDictionaryInfo
487                                 .containsKey(file.getName())) {
488                             // We have it in our list already.
489                             continue;
490                         }
491                         final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(file);
492                         if (!dictionaryInfo.isValid()) {
493                             Log.e(LOG, "Unable to parse dictionary: " + file.getPath());
494                         }
495
496                         toAddSorted.add(file.getName());
497                         newDictionaryConfig.uncompressedFilenameToDictionaryInfo.put(
498                             file.getName(), dictionaryInfo);
499                     }
500                 } else {
501                     Log.w(LOG, "dictDir is not a directory: " + getDictDir().getPath());
502                 }
503                 if (!toAddSorted.isEmpty()) {
504                     Collections.sort(toAddSorted, uncompressedFilenameComparator);
505                     newDictionaryConfig.dictionaryFilesOrdered.addAll(toAddSorted);
506                 }
507
508                 try {
509                     PersistentObjectCache.getInstance()
510                     .write(C.DICTIONARY_CONFIGS, newDictionaryConfig);
511                 } catch (Exception e) {
512                     Log.e(LOG, "Failed persisting dictionary configs", e);
513                 }
514
515                 synchronized (DictionaryApplication.this) {
516                     dictionaryConfig = newDictionaryConfig;
517                 }
518
519                 try {
520                     onUpdateFinished.run();
521                 } catch (Exception e) {
522                     Log.e(LOG, "Exception running callback.", e);
523                 }
524             }
525         }).start();
526     }
527
528     public boolean matchesFilters(final DictionaryInfo dictionaryInfo, final String[] filters) {
529         if (filters == null) {
530             return true;
531         }
532         for (final String filter : filters) {
533             if (!getDictionaryName(dictionaryInfo.uncompressedFilename).toLowerCase().contains(
534                         filter)) {
535                 return false;
536             }
537         }
538         return true;
539     }
540
541     public synchronized List<DictionaryInfo> getDictionariesOnDevice(String[] filters) {
542         final List<DictionaryInfo> result = new ArrayList<DictionaryInfo>(
543             dictionaryConfig.dictionaryFilesOrdered.size());
544         for (final String uncompressedFilename : dictionaryConfig.dictionaryFilesOrdered) {
545             final DictionaryInfo dictionaryInfo = dictionaryConfig.uncompressedFilenameToDictionaryInfo
546                                                   .get(uncompressedFilename);
547             if (dictionaryInfo != null && matchesFilters(dictionaryInfo, filters)) {
548                 result.add(dictionaryInfo);
549             }
550         }
551         return result;
552     }
553
554     public List<DictionaryInfo> getDownloadableDictionaries(String[] filters) {
555         final List<DictionaryInfo> result = new ArrayList<DictionaryInfo>(
556             dictionaryConfig.dictionaryFilesOrdered.size());
557
558         final Map<String, DictionaryInfo> remaining = new HashMap<String, DictionaryInfo>(
559             DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO);
560         remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered);
561         for (final DictionaryInfo dictionaryInfo : remaining.values()) {
562             if (matchesFilters(dictionaryInfo, filters)) {
563                 result.add(dictionaryInfo);
564             }
565         }
566         Collections.sort(result, dictionaryInfoComparator);
567         return result;
568     }
569
570     public synchronized boolean isDictionaryOnDevice(String uncompressedFilename) {
571         return dictionaryConfig.uncompressedFilenameToDictionaryInfo.get(uncompressedFilename) != null;
572     }
573
574     public boolean updateAvailable(final DictionaryInfo dictionaryInfo) {
575         final DictionaryInfo downloadable =
576             DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO.get(
577                 dictionaryInfo.uncompressedFilename);
578         return downloadable != null &&
579                downloadable.creationMillis > dictionaryInfo.creationMillis;
580     }
581
582     public DictionaryInfo getDownloadable(final String uncompressedFilename) {
583         final DictionaryInfo downloadable = DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO
584                                             .get(uncompressedFilename);
585         return downloadable;
586     }
587
588 }