import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.StyleSpan;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextMenu;
@Override
public void onCreate(Bundle savedInstanceState) {
+ DictionaryApplication.INSTANCE.init(getApplicationContext());
+ application = DictionaryApplication.INSTANCE;
// This needs to be before super.onCreate, otherwise ActionbarSherlock
// doesn't makes the background of the actionbar white when you're
// in the dark theme.
- setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);
+ setTheme(application.getSelectedTheme().themeId);
Log.d(LOG, "onCreate:" + this);
super.onCreate(savedInstanceState);
setContentView(R.layout.dictionary_activity);
- application = (DictionaryApplication) getApplication();
theme = application.getSelectedTheme();
textColorFg = getResources().getColor(theme.tokenRowFgColor);
setListAdapter(new IndexAdapter(index));
+ // Pre-load the Transliterator (will spawn its own thread)
+ TransliteratorManager.init(new TransliteratorManager.Callback() {
+ @Override
+ public void onTransliteratorReady() {
+ uiHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ onSearchTextChange(searchView.getQuery().toString());
+ }
+ });
+ }
+ }, DictionaryApplication.threadBackground);
+
// Pre-load the collators.
new Thread(new Runnable() {
public void run() {
- android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
+ android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE);
final long startMillis = System.currentTimeMillis();
try {
- TransliteratorManager.init(new TransliteratorManager.Callback() {
- @Override
- public void onTransliteratorReady() {
- uiHandler.post(new Runnable() {
- @Override
- public void run() {
- onSearchTextChange(searchView.getQuery().toString());
- }
- });
- }
- });
-
for (final Index index : dictionary.indices) {
final String searchToken = index.sortedIndexEntries.get(0).token;
final IndexEntry entry = index.findExact(searchToken);
}
void updateLangButton() {
- final LanguageResources languageResources =
- DictionaryApplication.isoCodeToResources.get(index.shortName);
- if (languageResources != null && languageResources.flagId != 0) {
- languageButton.setImageResource(languageResources.flagId);
+ final int flagId = IsoUtils.INSTANCE.getFlagIdForIsoCode(index.shortName);
+ if (flagId != 0) {
+ languageButton.setImageResource(flagId);
} else {
if (indexIndex % 2 == 0) {
languageButton.setImageResource(android.R.drawable.ic_media_next);
for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) {
final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i);
- final View button = application.createButton(parent.getContext(),
- dictionaryInfo, indexInfo);
+ final View button = IsoUtils.INSTANCE.createButton(parent.getContext(),
+ dictionaryInfo, indexInfo, application.languageButtonPixels);
final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(),
getLaunchIntent(getApplicationContext(),
application.getPath(dictionaryInfo.uncompressedFilename),
private void getMetrics() {
// Get the screen's density scale
- final float scale = getResources().getDisplayMetrics().density;
+ // The previous method getResources().getDisplayMetrics()
+ // used to occasionally trigger a null pointer exception,
+ // so try this instead.
+ DisplayMetrics dm = new DisplayMetrics();
+ getWindowManager().getDefaultDisplay().getMetrics(dm);
+ final float scale = dm.density;
// Convert the dps to pixels, based on density scale
mPaddingDefault = (int) (PADDING_DEFAULT_DP * scale + 0.5f);
mPaddingLarge = (int) (PADDING_LARGE_DP * scale + 0.5f);