import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;
+import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView.ScaleType;
+import android.widget.LinearLayout;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
final Map<String, DictionaryInfo> uncompressedFilenameToDictionaryInfo = new LinkedHashMap<String, DictionaryInfo>();
}
DictionaryConfig dictionaryConfig = null;
+
+
+ int languageButtonPixels = 22;
// static final class DictionaryHistory implements Serializable {
// private static final long serialVersionUID = -4842995032541390284L;
TransliteratorManager.init(null);
staticInit(getApplicationContext());
+ languageButtonPixels = (int) TypedValue.applyDimension(
+ TypedValue.COMPLEX_UNIT_DIP, 60, getResources().getDisplayMetrics());
+
+
// Load the dictionaries we know about.
dictionaryConfig = PersistentObjectCache.init(getApplicationContext()).read(
C.DICTIONARY_CONFIGS, DictionaryConfig.class);
final IndexInfo indexInfo) {
LanguageResources languageResources = Language.isoCodeToResources.get(indexInfo.shortName);
View result;
+
if (languageResources == null || languageResources.flagId <= 0) {
Button button = new Button(context);
button.setText(indexInfo.shortName);
button.setScaleType(ScaleType.FIT_CENTER);
result = button;
}
+ result.setMinimumWidth(languageButtonPixels);
+ result.setMinimumHeight(languageButtonPixels * 2 / 3);
result.setOnClickListener(
new IntentLauncher(context,
DictionaryActivity.getLaunchIntent(getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName, "")));
+// result.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
return result;
}
return result;
}
- public synchronized List<DictionaryInfo> getAllDictionaries() {
- final List<DictionaryInfo> result = getDictionariesOnDevice();
-
- // The downloadable ones.
- final Map<String,DictionaryInfo> remaining = new LinkedHashMap<String, DictionaryInfo>(DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO);
- remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered);
- final List<DictionaryInfo> toAddSorted = new ArrayList<DictionaryInfo>(remaining.values());
- Collections.sort(toAddSorted, dictionaryInfoComparator);
- result.addAll(toAddSorted);
-
- return result;
+ public List<DictionaryInfo> getDownloadableDictionaries() {
+ final List<DictionaryInfo> result = new ArrayList<DictionaryInfo>(dictionaryConfig.dictionaryFilesOrdered.size());
+
+ // The downloadable ones.
+ final Map<String,DictionaryInfo> remaining = new LinkedHashMap<String, DictionaryInfo>(DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO);
+ remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered);
+ final List<DictionaryInfo> toAddSorted = new ArrayList<DictionaryInfo>(remaining.values());
+ Collections.sort(toAddSorted, dictionaryInfoComparator);
+ result.addAll(toAddSorted);
+
+ return result;
}
-
+
public synchronized boolean isDictionaryOnDevice(String uncompressedFilename) {
return dictionaryConfig.uncompressedFilenameToDictionaryInfo.get(uncompressedFilename) != null;
}
// EditText filterText;
SearchView filterSearchView;
- ToggleButton hideDownloadable;
+ ToggleButton showDownloadable;
LinearLayout dictionariesOnDevice;
LinearLayout downloadableDictionaries;
// }
// });
- hideDownloadable = (ToggleButton) findViewById(R.id.hideDownloadable);
- hideDownloadable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+ showDownloadable = (ToggleButton) findViewById(R.id.hideDownloadable);
+ showDownloadable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
onShowLocalChanged();
}
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- hideDownloadable.setChecked(prefs.getBoolean(C.SHOW_LOCAL, false));
+ showDownloadable.setChecked(prefs.getBoolean(C.SHOW_DOWNLOADABLE, false));
if (!blockAutoLaunch &&
getIntent().getBooleanExtra(C.CAN_AUTO_LAUNCH_DICT, true) &&
}
private void onShowLocalChanged() {
- downloadableDictionaries.setVisibility(hideDownloadable.isChecked() ? View.GONE
- : View.VISIBLE);
+// downloadableDictionaries.setVisibility(showDownloadable.isChecked() ? View.GONE
+// : View.VISIBLE);
+ if (filterSearchView != null) {
+ populateDictionaryLists(filterSearchView.getQuery().toString());
+ } else {
+ populateDictionaryLists("");
+ }
Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
- prefs.putBoolean(C.SHOW_LOCAL, hideDownloadable.isChecked());
+ prefs.putBoolean(C.SHOW_DOWNLOADABLE, showDownloadable.isChecked());
prefs.commit();
}
private void populateDictionaryLists(String filterText) {
// On device.
dictionariesOnDevice.removeAllViews();
- final List<DictionaryInfo> dictionaryInfos = application.getDictionariesOnDevice();
- for (final DictionaryInfo dictionaryInfo : dictionaryInfos) {
- View row = LayoutInflater.from(dictionariesOnDevice.getContext()).inflate(
- R.layout.dictionary_on_device_row, dictionariesOnDevice, false);
- final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
- name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));
-
- LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
- final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
- for (IndexInfo indexInfo : sortedIndexInfos) {
- final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
- buttons.addView(button);
+ {
+ final List<DictionaryInfo> dictionaryInfos = application.getDictionariesOnDevice();
+ for (final DictionaryInfo dictionaryInfo : dictionaryInfos) {
+ View row = LayoutInflater.from(dictionariesOnDevice.getContext()).inflate(
+ R.layout.dictionary_on_device_row, dictionariesOnDevice, false);
+ final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
+ name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));
+
+ LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
+ final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
+ for (IndexInfo indexInfo : sortedIndexInfos) {
+ final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
+ buttons.addView(button);
+ }
+
+ dictionariesOnDevice.addView(row);
}
-
- dictionariesOnDevice.addView(row);
}
// Downloadable.
-
+ downloadableDictionaries.removeAllViews();
+ if (showDownloadable.isChecked()) {
+ final List<DictionaryInfo> dictionaryInfos = application.getDownloadableDictionaries();
+ for (final DictionaryInfo dictionaryInfo : dictionaryInfos) {
+ View row = LayoutInflater.from(dictionariesOnDevice.getContext()).inflate(
+ R.layout.dictionary_on_device_row, dictionariesOnDevice, false);
+ final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
+ name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));
+
+ LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
+ final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
+ for (IndexInfo indexInfo : sortedIndexInfos) {
+ final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
+ buttons.addView(button);
+ }
+ downloadableDictionaries.addView(row);
+ }
+ }
}
-// class Adapter extends BaseAdapter {
-//
-// final List<DictionaryInfo> dictionaryInfos = new ArrayList<DictionaryInfo>();
-//
-// Adapter() {
-// final String filter = filterSearchView.getText().toString().trim().toLowerCase();
-// for (final DictionaryInfo dictionaryInfo : application.getAllDictionaries()) {
-// boolean canShow = true;
-// if (hideDownloadable.isChecked()
-// && !application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
-// canShow = false;
-// }
-// if (canShow && filter.length() > 0) {
-// if (!application.getDictionaryName(dictionaryInfo.uncompressedFilename)
-// .toLowerCase().contains(filter)) {
-// canShow = false;
-// }
-// }
-// if (canShow) {
-// dictionaryInfos.add(dictionaryInfo);
-// }
-// }
-// }
-//
-// @Override
-// public int getCount() {
-// return dictionaryInfos.size();
-// }
-//
-// @Override
-// public DictionaryInfo getItem(int position) {
-// return dictionaryInfos.get(position);
-// }
-//
-// @Override
-// public long getItemId(int position) {
-// return position;
-// }
-//
-// @Override
-// public View getView(final int position, View convertView, final ViewGroup parent) {
-// if (convertView == null) {
-// convertView = LayoutInflater.from(parent.getContext()).inflate(
-// R.layout.dictionary_manager_row, parent, false);
-// }
-//
-// final DictionaryInfo dictionaryInfo = getItem(position);
-//
-// final TextView textView = (TextView) convertView.findViewById(R.id.dictionaryName);
-// final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);
-// textView.setText(name);
-//
-// final Button downloadButton = (Button) convertView
-// .findViewById(R.id.dictionaryDownloadButton);
-// final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
-// final DictionaryInfo downloadable = application
-// .getDownloadable(dictionaryInfo.uncompressedFilename);
-// if (updateAvailable) {
-// downloadButton.setCompoundDrawablesWithIntrinsicBounds(
-// android.R.drawable.ic_menu_add,
-// 0, 0, 0);
-// downloadButton.setText(getString(R.string.downloadButton,
-// downloadable.zipBytes / 1024.0 / 1024.0));
-// } else if (!application.isDictionaryOnDevice(dictionaryInfo.uncompressedFilename)) {
-// downloadButton.setCompoundDrawablesWithIntrinsicBounds(
-// android.R.drawable.ic_menu_add,
-// 0, 0, 0);
-// downloadButton.setText(getString(R.string.downloadButton,
-// downloadable.zipBytes / 1024.0 / 1024.0));
-// } else {
-// downloadButton.setCompoundDrawablesWithIntrinsicBounds(
-// android.R.drawable.checkbox_on_background,
-// 0, 0, 0);
-// downloadButton.setText("");
-// }
-// final Intent intent = getDownloadIntent(downloadable);
-// downloadButton.setOnClickListener(new IntentLauncher(parent.getContext(), intent));
-//
-// // Add the information about each index.
-// final TextView dictionaryDetails = (TextView) convertView
-// .findViewById(R.id.dictionaryDetails);
-// final StringBuilder builder = new StringBuilder();
-// for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {
-// if (builder.length() > 0) {
-// builder.append(" | ");
-// }
-// builder.append(getString(R.string.indexInfo, indexInfo.shortName,
-// indexInfo.mainTokenCount));
-// }
-// dictionaryDetails.setText(builder.toString());
-//
-// // // Because we have a Button inside a ListView row:
-// // //
-// // http://groups.google.com/group/android-developers/browse_thread/thread/3d96af1530a7d62a?pli=1
-// // convertView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
-// convertView.setClickable(true);
-// convertView.setFocusable(true);
-// convertView.setLongClickable(true);
-// // result.setBackgroundResource(android.R.drawable.menuitem_background);
-// convertView.setOnClickListener(new TextView.OnClickListener() {
-// @Override
-// public void onClick(View v) {
-// DictionaryManagerActivity.this.onClick(position);
-// }
-// });
-//
-// return convertView;
-// }
-// }
-
}