X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2FIsoUtils.java;h=6ca5003ba1f5d07d3a8525015f4add3e13d86cce;hb=83d9dc7cd871082a82c2dd0dbb7a0ceabd7c83a0;hp=4cafedc11bee6f049a95b4f42da22a8ee94d2dc4;hpb=01332c7697b595328bbd5397e95341a0dd575493;p=Dictionary.git diff --git a/src/com/hughes/android/dictionary/IsoUtils.java b/src/com/hughes/android/dictionary/IsoUtils.java index 4cafedc..6ca5003 100644 --- a/src/com/hughes/android/dictionary/IsoUtils.java +++ b/src/com/hughes/android/dictionary/IsoUtils.java @@ -35,8 +35,8 @@ public enum IsoUtils { // Useful: // http://www.loc.gov/standards/iso639-2/php/code_list.php - private final Map isoCodeToResources = new HashMap(); - private IsoUtils() { + private final Map isoCodeToResources = new HashMap<>(); + IsoUtils() { isoCodeToResources.put("AF", new LanguageResources("Afrikaans", R.string.AF, R.drawable.flag_of_south_africa)); isoCodeToResources.put("SQ", new LanguageResources("Albanian", R.string.SQ, @@ -185,14 +185,12 @@ public enum IsoUtils { isoCodeToResources.put("LO", new LanguageResources("Lao", R.string.LO, R.drawable.flag_of_laos)); isoCodeToResources.put("ML", new LanguageResources("Malayalam", R.string.ML)); - isoCodeToResources.put("SL", new LanguageResources("Slovenian", R.string.SL, - R.drawable.flag_of_slovenia)); isoCodeToResources.put("TA", new LanguageResources("Tamil", R.string.TA)); isoCodeToResources.put("SH", new LanguageResources("Serbo-Croatian", R.string.SH)); isoCodeToResources.put("SD", new LanguageResources("Sindhi", R.string.SD)); // Hack to allow lower-case ISO codes to work: - for (final String isoCode : new ArrayList(isoCodeToResources.keySet())) { + for (final String isoCode : new ArrayList<>(isoCodeToResources.keySet())) { isoCodeToResources.put(isoCode.toLowerCase(), isoCodeToResources.get(isoCode)); } } @@ -216,7 +214,7 @@ public enum IsoUtils { return lang; } - public View createButton(final Context context, final DictionaryInfo dictionaryInfo, + public View createButton(final Context context, final IndexInfo indexInfo, int size) { LanguageResources languageResources = isoCodeToResources.get(indexInfo.shortName); View result; @@ -234,4 +232,25 @@ public enum IsoUtils { result.setLayoutParams(new LinearLayout.LayoutParams(size, size * 2 / 3)); return result; } + + public View setupButton(Button textButton, ImageButton imageButton, + final IndexInfo indexInfo) { + 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; + } }