use of com.foobnix.pdf.info.DictsHelper.DictItem in project LibreraReader by foobnix.
the class DialogTranslateFromTo method show.
public static AlertDialog show(final Activity a, final Runnable runnable) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(a);
alertDialog.setTitle(R.string.remember_dictionary);
View body = LayoutInflater.from(a).inflate(R.layout.dialog_translate_from_to, null, false);
final Spinner spinnerFrom = (Spinner) body.findViewById(R.id.spinnerFrom);
final Spinner spinnerTo = (Spinner) body.findViewById(R.id.spinnerTo);
ImageView imageOk = (ImageView) body.findViewById(R.id.imageOK);
final List<String> langNames = new ArrayList<String>(langs.keySet());
final List<String> langCodes = new ArrayList<String>(langs.values());
spinnerFrom.setAdapter(new BaseItemLayoutAdapter<String>(a, android.R.layout.simple_spinner_dropdown_item, langNames) {
@Override
public void populateView(View inflate, int arg1, String value) {
Views.text(inflate, android.R.id.text1, "" + value);
}
});
spinnerFrom.setSelection(langCodes.indexOf(AppState.get().fromLang));
spinnerTo.setAdapter(new BaseItemLayoutAdapter<String>(a, android.R.layout.simple_spinner_dropdown_item, langNames) {
@Override
public void populateView(View inflate, int arg1, String value) {
Views.text(inflate, android.R.id.text1, "" + value);
}
});
spinnerTo.setSelection(langCodes.indexOf(AppState.get().toLang));
final ListView dictSpinner = (ListView) body.findViewById(R.id.dictionaries);
final List<DictItem> list = DictsHelper.getAllResolveInfoAsDictItem1(a, "");
list.addAll(DictsHelper.getOnlineDicts(a, ""));
dictSpinner.setAdapter(new BaseItemLayoutAdapter<DictItem>(a, R.layout.item_dict_line, list) {
@Override
public void populateView(View layout, int position, DictItem item) {
((TextView) layout.findViewById(R.id.text1)).setText(item.name);
((TextView) layout.findViewById(R.id.type1)).setText(item.type);
if (item.image == null) {
((ImageView) layout.findViewById(R.id.image1)).setImageResource(R.drawable.web);
} else {
((ImageView) layout.findViewById(R.id.image1)).setImageDrawable(item.image);
}
}
});
body.findViewById(R.id.onReverse).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int p1 = spinnerFrom.getSelectedItemPosition();
int p2 = spinnerTo.getSelectedItemPosition();
spinnerTo.setSelection(p1);
spinnerFrom.setSelection(p2);
}
});
alertDialog.setView(body);
alertDialog.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
final AlertDialog show = alertDialog.show();
dictSpinner.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AppState.get().rememberDict = list.get(position).toString();
AppState.get().fromLang = langCodes.get(spinnerFrom.getSelectedItemPosition());
AppState.get().toLang = langCodes.get(spinnerTo.getSelectedItemPosition());
try {
show.dismiss();
} catch (Exception e) {
}
runnable.run();
}
});
imageOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().fromLang = langCodes.get(spinnerFrom.getSelectedItemPosition());
AppState.get().toLang = langCodes.get(spinnerTo.getSelectedItemPosition());
try {
show.dismiss();
} catch (Exception e) {
}
}
});
return show;
}
Aggregations