import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import android.app.Application;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
+import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
import com.hughes.android.dictionary.engine.Dictionary;
import com.hughes.android.dictionary.engine.Language;
import com.hughes.android.dictionary.engine.TransliteratorManager;
import com.hughes.android.util.PersistentObjectCache;
+import com.hughes.util.ListUtil;
import com.ibm.icu.text.Collator;
public class DictionaryApplication extends Application {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
- Log.d("THAD", "prefs changed: " + key);
+ Log.d("QuickDic", "prefs changed: " + key);
if (key.equals(getString(R.string.themeKey))) {
setTheme(getSelectedTheme().themeId);
}
return false;
}
});
+
+
+ final MenuItem reportIssue = menu.add(getString(R.string.reportIssue));
+ reportIssue.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ public boolean onMenuItemClick(final MenuItem menuItem) {
+ final Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri.parse("http://code.google.com/p/quickdic-dictionary/issues/entry"));
+ context.startActivity(intent);
+ return false;
+ }
+ });
}
public synchronized File getDictDir() {
}
+
+ String defaultLangISO2 = Locale.getDefault().getLanguage().toLowerCase();
final Map<String, String> fileToNameCache = new LinkedHashMap<String, String>();
public String getLanguageName(final String isoCode) {
final String lang = languageResources != null ? getApplicationContext().getString(languageResources.nameId) : isoCode;
return lang;
}
+
public synchronized String getDictionaryName(final String uncompressedFilename) {
+ final String currentLocale = Locale.getDefault().getLanguage().toLowerCase();
+ if (!currentLocale.equals(defaultLangISO2)) {
+ defaultLangISO2 = currentLocale;
+ fileToNameCache.clear();
+ }
+
String name = fileToNameCache.get(uncompressedFilename);
if (name != null) {
return name;
final DictionaryInfo dictionaryInfo = DOWNLOADABLE_NAME_TO_INFO.get(uncompressedFilename);
if (dictionaryInfo != null) {
final StringBuilder nameBuilder = new StringBuilder();
+
+ // Hack to put the default locale first in the name.
+ boolean swapped = false;
+ if (dictionaryInfo.indexInfos.size() > 1 &&
+ dictionaryInfo.indexInfos.get(1).shortName.toLowerCase().equals(defaultLangISO2)) {
+ ListUtil.swap(dictionaryInfo.indexInfos, 0, 1);
+ swapped = true;
+ }
for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) {
if (i > 0) {
nameBuilder.append("-");
}
nameBuilder.append(getLanguageName(dictionaryInfo.indexInfos.get(i).shortName));
}
+ if (swapped) {
+ ListUtil.swap(dictionaryInfo.indexInfos, 0, 1);
+ }
name = nameBuilder.toString();
} else {
name = uncompressedFilename.replace(".quickdic", "");
// Pick them up and put them at the end of the list.
final List<String> toAddSorted = new ArrayList<String>();
final File[] dictDirFiles = getDictDir().listFiles();
- for (final File file : dictDirFiles) {
- if (file.getName().endsWith(".zip")) {
- if (DOWNLOADABLE_NAME_TO_INFO.containsKey(file.getName().replace(".zip", ""))) {
- file.delete();
+ if (dictDirFiles != null) {
+ for (final File file : dictDirFiles) {
+ if (file.getName().endsWith(".zip")) {
+ if (DOWNLOADABLE_NAME_TO_INFO.containsKey(file.getName().replace(".zip", ""))) {
+ file.delete();
+ }
}
+ if (!file.getName().endsWith(".quickdic")) {
+ continue;
+ }
+ if (newDictionaryConfig.dictionaryInfoCache.containsKey(file.getName())) {
+ // We have it in our list already.
+ continue;
+ }
+ final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(file);
+ if (dictionaryInfo == null) {
+ Log.e(LOG, "Unable to parse dictionary: " + file.getPath());
+ continue;
+ }
+
+ toAddSorted.add(file.getName());
+ newDictionaryConfig.dictionaryInfoCache.put(file.getName(), dictionaryInfo);
}
- if (!file.getName().endsWith(".quickdic")) {
- continue;
- }
- if (newDictionaryConfig.dictionaryInfoCache.containsKey(file.getName())) {
- // We have it in our list already.
- continue;
- }
- final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(file);
- if (dictionaryInfo == null) {
- Log.e(LOG, "Unable to parse dictionary: " + file.getPath());
- continue;
- }
-
- toAddSorted.add(file.getName());
- newDictionaryConfig.dictionaryInfoCache.put(file.getName(), dictionaryInfo);
+ } else {
+ Log.w(LOG, "dictDir is not a diretory: " + getDictDir().getPath());
}
if (!toAddSorted.isEmpty()) {
Collections.sort(toAddSorted, uncompressedFilenameComparator);