]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/IsoUtils.java
Put language buttons in Layout for better performance.
[Dictionary.git] / src / com / hughes / android / dictionary / IsoUtils.java
index 4cafedc11bee6f049a95b4f42da22a8ee94d2dc4..9b381fbb456384ec28aacc3d891487ead984cd88 100644 (file)
@@ -234,4 +234,26 @@ public enum IsoUtils {
         result.setLayoutParams(new LinearLayout.LayoutParams(size, size * 2 / 3));
         return result;
     }
+
+    public View setupButton(Button textButton, ImageButton imageButton,
+                            final DictionaryInfo dictionaryInfo,
+                            final IndexInfo indexInfo, int size) {
+        LanguageResources languageResources = isoCodeToResources.get(indexInfo.shortName);
+        View result;
+
+        if (languageResources == null || languageResources.flagId <= 0) {
+            textButton.setText(indexInfo.shortName);
+            textButton.setVisibility(View.VISIBLE);
+            imageButton.setVisibility(View.GONE);
+            result = textButton;
+        } else {
+            imageButton.setImageResource(languageResources.flagId);
+            imageButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
+            textButton.setVisibility(View.GONE);
+            imageButton.setVisibility(View.VISIBLE);
+            result = imageButton;
+        }
+        // Assume dimensions have been set before in Layout
+        return result;
+    }
 }