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 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);
}
final MenuItem help = menu.add(getString(R.string.help));
help.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem menuItem) {
- context.startActivity(HelpActivity.getLaunchIntent());
+ context.startActivity(HtmlDisplayActivity.getHelpLaunchIntent());
return false;
}
});
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();
+ String defaultLangName = null;
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();
+ defaultLangName = null;
+ }
+ if (defaultLangName == null) {
+ defaultLangName = getLanguageName(defaultLangISO2);
+ }
+
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", "");
final Comparator<String> uncompressedFilenameComparator = new Comparator<String>() {
@Override
public int compare(String uncompressedFilename1, String uncompressedFilename2) {
- return collator.compare(getDictionaryName(uncompressedFilename1), getDictionaryName(uncompressedFilename2));
+ final String name1 = getDictionaryName(uncompressedFilename1);
+ final String name2 = getDictionaryName(uncompressedFilename2);
+ if (defaultLangName.length() > 0) {
+ if (name1.startsWith(defaultLangName) && !name2.startsWith(defaultLangName)) {
+ return -1;
+ } else if (name2.startsWith(defaultLangName) && !name1.startsWith(defaultLangName)) {
+ return 1;
+ }
+ }
+ return collator.compare(name1, name2);
}
};
final Comparator<DictionaryInfo> dictionaryInfoComparator = new Comparator<DictionaryInfo>() {