]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Move code using ISO to language resources into IsoUtils.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index 9523215e9bd72e5cab208d4205e946c18daeec7d..ac77c8558c8d6be0e62a06ac36522f261436a0bd 100644 (file)
@@ -42,6 +42,7 @@ import android.text.Spannable;
 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;
@@ -718,10 +719,9 @@ public class DictionaryActivity extends ActionBarActivity {
     }
 
     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);
@@ -806,8 +806,8 @@ public class DictionaryActivity extends ActionBarActivity {
 
                 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),
@@ -1473,7 +1473,12 @@ public class DictionaryActivity extends ActionBarActivity {
 
         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);