From 5a593262105c474e187dbada6de99b79143b01ce Mon Sep 17 00:00:00 2001 From: Thad Hughes Date: Sun, 15 Dec 2013 15:30:43 -0800 Subject: [PATCH] Got the flags set to a reasonable size. --- res/layout/dictionary_manager_activity.xml | 4 +- res/menu/dictionary_manager_options_menu.xml | 2 +- src/com/hughes/android/dictionary/C.java | 2 +- .../dictionary/DictionaryApplication.java | 38 ++-- .../dictionary/DictionaryManagerActivity.java | 178 +++++------------- 5 files changed, 76 insertions(+), 148 deletions(-) diff --git a/res/layout/dictionary_manager_activity.xml b/res/layout/dictionary_manager_activity.xml index 07d8596..95164c8 100644 --- a/res/layout/dictionary_manager_activity.xml +++ b/res/layout/dictionary_manager_activity.xml @@ -65,8 +65,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" - android:textOff="@string/managerShow" - android:textOn="@string/managerHide" /> + android:textOff="@string/managerHide" + android:textOn="@string/managerShow" /> uncompressedFilenameToDictionaryInfo = new LinkedHashMap(); } DictionaryConfig dictionaryConfig = null; + + + int languageButtonPixels = 22; // static final class DictionaryHistory implements Serializable { // private static final long serialVersionUID = -4842995032541390284L; @@ -111,6 +117,10 @@ public class DictionaryApplication extends Application { 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); @@ -267,6 +277,7 @@ public class DictionaryApplication extends Application { 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); @@ -277,9 +288,12 @@ public class DictionaryApplication extends Application { 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; } @@ -401,19 +415,19 @@ public class DictionaryApplication extends Application { return result; } - public synchronized List getAllDictionaries() { - final List result = getDictionariesOnDevice(); - - // The downloadable ones. - final Map remaining = new LinkedHashMap(DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO); - remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered); - final List toAddSorted = new ArrayList(remaining.values()); - Collections.sort(toAddSorted, dictionaryInfoComparator); - result.addAll(toAddSorted); - - return result; + public List getDownloadableDictionaries() { + final List result = new ArrayList(dictionaryConfig.dictionaryFilesOrdered.size()); + + // The downloadable ones. + final Map remaining = new LinkedHashMap(DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO); + remaining.keySet().removeAll(dictionaryConfig.dictionaryFilesOrdered); + final List toAddSorted = new ArrayList(remaining.values()); + Collections.sort(toAddSorted, dictionaryInfoComparator); + result.addAll(toAddSorted); + + return result; } - + public synchronized boolean isDictionaryOnDevice(String uncompressedFilename) { return dictionaryConfig.uncompressedFilenameToDictionaryInfo.get(uncompressedFilename) != null; } diff --git a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java index b9a85b0..c06ccc3 100644 --- a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java @@ -67,7 +67,7 @@ public class DictionaryManagerActivity extends SherlockActivity { // EditText filterText; SearchView filterSearchView; - ToggleButton hideDownloadable; + ToggleButton showDownloadable; LinearLayout dictionariesOnDevice; LinearLayout downloadableDictionaries; @@ -125,8 +125,8 @@ public class DictionaryManagerActivity extends SherlockActivity { // } // }); - 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(); @@ -171,7 +171,7 @@ public class DictionaryManagerActivity extends SherlockActivity { } 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) && @@ -294,10 +294,15 @@ public class DictionaryManagerActivity extends SherlockActivity { } 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(); } @@ -321,135 +326,44 @@ public class DictionaryManagerActivity extends SherlockActivity { private void populateDictionaryLists(String filterText) { // On device. dictionariesOnDevice.removeAllViews(); - final List 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 sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos); - for (IndexInfo indexInfo : sortedIndexInfos) { - final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo); - buttons.addView(button); + { + final List 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 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 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 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 dictionaryInfos = new ArrayList(); -// -// 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; -// } -// } - } -- 2.43.0