import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.FrameLayout;
+import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
if (row.dictionaryInfo == null) {
return row.onDevice ? 0 : 1;
}
+ assert row.dictionaryInfo.indexInfos.size() <= 2;
return 2;
}
if (row == null) {
row = LayoutInflater.from(parent.getContext()).inflate(
R.layout.dictionary_manager_row, parent, false);
- } else {
- // TODO: avoid this
- LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
- buttons.removeAllViews();
}
final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
final TextView details = (TextView) row.findViewById(R.id.dictionaryDetails);
downloadDictionary(downloadable.downloadUrl, downloadable.zipBytes, downloadButton);
}
});
+ downloadButton.setVisibility(View.VISIBLE);
} else {
- downloadButton.setVisibility(View.INVISIBLE);
+ downloadButton.setVisibility(View.GONE);
}
LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
+
final List<IndexInfo> sortedIndexInfos = application
.sortedIndexInfos(dictionaryInfo.indexInfos);
final StringBuilder builder = new StringBuilder();
if (updateAvailable) {
builder.append(getString(R.string.updateAvailable));
}
- for (IndexInfo indexInfo : sortedIndexInfos) {
- final View button = IsoUtils.INSTANCE.createButton(buttons.getContext(), dictionaryInfo,
+ assert buttons.getChildCount() == 4;
+ for (int i = 0; i < 2; i++) {
+ final Button textButton = (Button)buttons.getChildAt(2*i);
+ final ImageButton imageButton = (ImageButton)buttons.getChildAt(2*i + 1);
+ if (i >= sortedIndexInfos.size()) {
+ textButton.setVisibility(View.GONE);
+ imageButton.setVisibility(View.GONE);
+ continue;
+ }
+ final IndexInfo indexInfo = sortedIndexInfos.get(i);
+ final View button = IsoUtils.INSTANCE.setupButton(textButton, imageButton, dictionaryInfo,
indexInfo, application.languageButtonPixels);
- buttons.addView(button);
if (canLaunch) {
button.setOnClickListener(
application.getPath(dictionaryInfo.uncompressedFilename),
indexInfo.shortName, "")));
- } else {
- button.setEnabled(false);
- button.setFocusable(false);
}
+ button.setEnabled(canLaunch);
+ button.setFocusable(canLaunch);
if (builder.length() != 0) {
builder.append("; ");
}
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;
+ }
}