From: Thad Hughes Date: Wed, 25 Dec 2013 21:46:21 +0000 (-0800) Subject: Using external storage dir properly, better notifications when missing. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=668f0c4dc71677f782ac40f01415595e43a0a93c Using external storage dir properly, better notifications when missing. --- diff --git a/res/drawable/arrow_down_float.png b/res/drawable-mdpi/arrow_down_float.png similarity index 100% rename from res/drawable/arrow_down_float.png rename to res/drawable-mdpi/arrow_down_float.png diff --git a/res/drawable/arrow_up_float.png b/res/drawable-mdpi/arrow_up_float.png similarity index 100% rename from res/drawable/arrow_up_float.png rename to res/drawable-mdpi/arrow_up_float.png diff --git a/res/drawable/btn_check_buttonless_on.png b/res/drawable-mdpi/btn_check_buttonless_on.png similarity index 100% rename from res/drawable/btn_check_buttonless_on.png rename to res/drawable-mdpi/btn_check_buttonless_on.png diff --git a/res/drawable/ic_input_delete.png b/res/drawable-mdpi/ic_input_delete.png similarity index 100% rename from res/drawable/ic_input_delete.png rename to res/drawable-mdpi/ic_input_delete.png diff --git a/res/drawable/ic_menu_forward.png b/res/drawable-mdpi/ic_menu_forward.png similarity index 100% rename from res/drawable/ic_menu_forward.png rename to res/drawable-mdpi/ic_menu_forward.png diff --git a/res/drawable/icon.png b/res/drawable-mdpi/icon.png similarity index 100% rename from res/drawable/icon.png rename to res/drawable-mdpi/icon.png diff --git a/res/drawable/thadolina.jpg b/res/drawable-mdpi/thadolina.jpg similarity index 100% rename from res/drawable/thadolina.jpg rename to res/drawable-mdpi/thadolina.jpg diff --git a/res/layout/dictionaries_on_device_row.xml b/res/layout/dictionaries_on_device_row.xml deleted file mode 100644 index 63f459b..0000000 --- a/res/layout/dictionaries_on_device_row.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/downloadable_dictionaries_header_row.xml b/res/layout/dictionary_manager_header_row_downloadable.xml similarity index 100% rename from res/layout/downloadable_dictionaries_header_row.xml rename to res/layout/dictionary_manager_header_row_downloadable.xml diff --git a/res/layout/dictionaries_on_device_header_row.xml b/res/layout/dictionary_manager_header_row_on_device.xml similarity index 100% rename from res/layout/dictionaries_on_device_header_row.xml rename to res/layout/dictionary_manager_header_row_on_device.xml diff --git a/res/layout/downloadable_dictionary_row.xml b/res/layout/dictionary_manager_row.xml similarity index 100% rename from res/layout/downloadable_dictionary_row.xml rename to res/layout/dictionary_manager_row.xml diff --git a/res/menu/dictionary_manager_options_menu.xml b/res/menu/dictionary_manager_options_menu.xml index 89164bd..867abff 100644 --- a/res/menu/dictionary_manager_options_menu.xml +++ b/res/menu/dictionary_manager_options_menu.xml @@ -7,10 +7,4 @@ android:showAsAction="always" android:actionViewClass="com.actionbarsherlock.widget.SearchView" /> - - \ No newline at end of file diff --git a/res/values-de/languages.xml b/res/values-de/languages.xml index f92c4f8..8af2fe0 100644 --- a/res/values-de/languages.xml +++ b/res/values-de/languages.xml @@ -26,6 +26,7 @@ Finnisch Französisch Schottisch-Gälisch + Manx Deutsch Griechisch Altgriechisch diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 83c06cb..dddd191 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -46,7 +46,7 @@ Datei: %s - Grosse: %,d bytes + Größe: %,d bytes Hergestellt: %tc Index: %s Wortzahl: %,d @@ -73,7 +73,7 @@ Verbindungsaufbau… Herunterladen: %1$,d von %2$,d Bytes. Entpackung: %1$,d von %2$,d Bytes. - Fertig: %,d Bytes. + Fertig: \n%s. "Fehler beim Herunterladen: \n%s" diff --git a/res/values-es/languages.xml b/res/values-es/languages.xml index be41662..851d9f0 100644 --- a/res/values-es/languages.xml +++ b/res/values-es/languages.xml @@ -14,6 +14,7 @@ Catalán Checo Chino (Mandarín) + Mandarín Danés Holandés Inglés @@ -22,6 +23,7 @@ Finés Francés Gaélico escocés + Manx Alemán Griego Griego Antiguo diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml index eab0144..cd7fa4b 100644 --- a/res/values-es/strings.xml +++ b/res/values-es/strings.xml @@ -24,6 +24,9 @@ Listar filtro Sólo local + + Terminado: \n%s. + Error descargando archivo: \n%s 4.0.1_en_a @@ -68,14 +71,6 @@ Por favor envíe comentarios, sugerencias, informes de error o simplemente un sa QuickDic contiene código con derechos de autor de Google y publicado bajo la licencia Apache 2.0. http://www.apache.org/licenses/LICENSE-2.0 - - - Abriendo conexión… - Descargando: %1$,d of %2$,d bytes. - Descomprimiendo: %1$,d of %2$,d bytes. - Terminado: %,d bytes. - Error descargando archivo: \n%s - @@ -115,6 +110,6 @@ Por favor envíe comentarios, sugerencias, informes de error o simplemente un sa theme Tema - Color y tema del interfaz de usuario. + Color y tema de la interfaz de usuario. diff --git a/res/values-it/languages.xml b/res/values-it/languages.xml index 0351f3b..9a2555a 100644 --- a/res/values-it/languages.xml +++ b/res/values-it/languages.xml @@ -23,6 +23,7 @@ Finlandese Francese Gaelico scozzese + Manx Tedesco Greco Greco antico diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml index 0bbcfc6..618e795 100644 --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -67,8 +67,8 @@ QuickDic contiene codice con copyright di Google e rilasciato sotto licenza Apac Apertura connessione… Downloading: %1$,d of %2$,d bytes. Decompressione: %1$,d of %2$,d bytes. -Terminato: %,d bytes. -Errore nel dowload del file: \n%s +Terminato: \n%s. +Errore nel dowload del file: \n%s QuickDic Directory QuickDic Directory diff --git a/res/values/strings.xml b/res/values/strings.xml index 0f4c7b9..6d06d6e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -21,12 +21,22 @@ No dictionaries on device Downloadable dictionaries %.1fMB + UPDATE! Move to top Delete dictionary %1$s: %2$,d words List filter Show Hide + + Error + Unable to read dictionary directory: \n%1$s\n\nAndroid external storage directory: \n%2$s + + + Download finished: \n%s. + Download failed: \n%s. + + 4.0.1_en_a @@ -59,7 +69,6 @@ Sources %1$s : %2$,d entries - Thad Hughes @@ -74,11 +83,6 @@ http://www.apache.org/licenses/LICENSE-2.0 - - Download finished: \n%s. - Download failed: \n%s. - - defaultddic @@ -88,8 +92,7 @@ quickdicDirectory QuickDic directory - The directory where QuickDic stores dictionaries. - /sdcard/quickDic/ + The directory where QuickDic stores dictionaries (empty for default quickDic folder on external storage). wordListFile Word list file @@ -112,10 +115,6 @@ Click opens context menu Open context menu for clicks on entries (long-click will always open-context menu). - showClearSearchTextButton - Show \'clear search text\' button - Show the button to clear the search text. You can also just move focus away from search text and start typing. - showPrevNextButtons Show up/down buttons Show or hide the previous and next word buttons in the dictionary view. diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 4b948a0..56df4ff 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -11,7 +11,7 @@ android:key="@string/quickdicDirectoryKey" android:title="@string/quickdicDirectoryTitle" android:summary="@string/quickdicDirectorySummary" - android:defaultValue="@string/quickdicDirectoryDefault" + android:defaultValue="" android:persistent="true" /> diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index c3c6775..f8dca37 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -196,7 +196,7 @@ public class DictionaryActivity extends SherlockListActivity { public void onCreate(Bundle savedInstanceState) { Log.d(LOG, "onCreate:" + this); super.onCreate(savedInstanceState); - + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Don't auto-launch if this fails. diff --git a/src/com/hughes/android/dictionary/DictionaryApplication.java b/src/com/hughes/android/dictionary/DictionaryApplication.java index 52c3af2..30d8067 100644 --- a/src/com/hughes/android/dictionary/DictionaryApplication.java +++ b/src/com/hughes/android/dictionary/DictionaryApplication.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.net.Uri; +import android.os.Environment; import android.preference.PreferenceManager; import android.util.Log; import android.util.TypedValue; @@ -119,7 +120,6 @@ public class DictionaryApplication extends Application { languageButtonPixels = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 60, getResources().getDisplayMetrics()); - // Load the dictionaries we know about. dictionaryConfig = PersistentObjectCache.init(getApplicationContext()).read( @@ -191,14 +191,17 @@ public class DictionaryApplication extends Application { } public synchronized File getDictDir() { - // This metaphore doesn't work, because we've already reset prefsMightHaveChanged. + // This metaphor doesn't work, because we've already reset prefsMightHaveChanged. // if (dictDir == null || PreferenceActivity.prefsMightHaveChanged) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - final String dir = prefs.getString(getString(R.string.quickdicDirectoryKey), getString(R.string.quickdicDirectoryDefault)); + final File defaultDictDir = new File(Environment.getExternalStorageDirectory(), "quickDic"); + String dir = prefs.getString(getString(R.string.quickdicDirectoryKey), defaultDictDir.getAbsolutePath()); + if (dir.isEmpty()) { + dir = defaultDictDir.getAbsolutePath(); + } dictDir = new File(dir); dictDir.mkdirs(); -// } - return dictDir; + return dictDir; } public C.Theme getSelectedTheme() { diff --git a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java index 094034c..e3e76ad 100644 --- a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java @@ -14,6 +14,8 @@ package com.hughes.android.dictionary; +import android.app.AlertDialog; +import android.app.Dialog; import android.app.DownloadManager; import android.app.DownloadManager.Request; import android.content.BroadcastReceiver; @@ -39,6 +41,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CompoundButton; +import android.widget.ListView; import android.widget.Toast; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.LinearLayout; @@ -165,6 +168,7 @@ public class DictionaryManagerActivity extends SherlockListActivity { return intent; } + @Override public void onCreate(Bundle savedInstanceState) { setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId); @@ -172,15 +176,17 @@ public class DictionaryManagerActivity extends SherlockListActivity { Log.d(LOG, "onCreate:" + this); application = (DictionaryApplication) getApplication(); - + + blockAutoLaunch = false; + // UI init. setContentView(R.layout.dictionary_manager_activity); dictionariesOnDeviceHeaderRow = (LinearLayout) LayoutInflater.from(getListView().getContext()).inflate( - R.layout.dictionaries_on_device_header_row, getListView(), false); + R.layout.dictionary_manager_header_row_on_device, getListView(), false); downloadableDictionariesHeaderRow = (LinearLayout) LayoutInflater.from(getListView().getContext()).inflate( - R.layout.downloadable_dictionaries_header_row, getListView(), false); + R.layout.dictionary_manager_header_row_downloadable, getListView(), false); showDownloadable = (ToggleButton) downloadableDictionariesHeaderRow.findViewById(R.id.hideDownloadable); showDownloadable.setOnCheckedChangeListener(new OnCheckedChangeListener() { @@ -190,7 +196,6 @@ public class DictionaryManagerActivity extends SherlockListActivity { } }); - blockAutoLaunch = false; final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final String thanksForUpdatingLatestVersion = getString(R.string.thanksForUpdatingVersion); if (!prefs.getString(C.THANKS_FOR_UPDATING_VERSION, "").equals( @@ -207,10 +212,24 @@ public class DictionaryManagerActivity extends SherlockListActivity { setListAdapater(); registerForContextMenu(getListView()); + + final File dictDir = application.getDictDir(); + if (!dictDir.canRead() || !dictDir.canExecute()) { + blockAutoLaunch = true; + + AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext()); + builder.setTitle(getString(R.string.error)); + builder.setMessage(getString( + R.string.unableToReadDictionaryDir, + dictDir.getAbsolutePath(), + Environment.getExternalStorageDirectory())); + builder.create().show(); + } } @Override public void onDestroy() { + super.onDestroy(); unregisterReceiver(broadcastReceiver); } @@ -429,6 +448,8 @@ public class DictionaryManagerActivity extends SherlockListActivity { if (convertView instanceof LinearLayout && convertView != dictionariesOnDeviceHeaderRow && convertView != downloadableDictionariesHeaderRow) { + /* This is done to try to avoid leaking memory that used to + * happen on Android 4.0.3 */ ((LinearLayout)convertView).removeAllViews(); } @@ -438,15 +459,13 @@ public class DictionaryManagerActivity extends SherlockListActivity { if (row.dictionaryInfo == null) { return dictionariesOnDeviceHeaderRow; } - return createDictionaryRow(row.dictionaryInfo, - parent, R.layout.dictionaries_on_device_row, true); + return createDictionaryRow(row.dictionaryInfo, parent, true); } if (row.dictionaryInfo == null) { return downloadableDictionariesHeaderRow; } - return createDictionaryRow(row.dictionaryInfo, - parent, R.layout.downloadable_dictionary_row, false); + return createDictionaryRow(row.dictionaryInfo, parent, false); } } @@ -457,41 +476,36 @@ public class DictionaryManagerActivity extends SherlockListActivity { setListAdapter(new MyListAdapter(filters)); } - private View createDictionaryRow(final DictionaryInfo dictionaryInfo, final ViewGroup parent, - final int viewResource, final boolean canLaunch) { + private View createDictionaryRow(final DictionaryInfo dictionaryInfo, + final ViewGroup parent, final boolean canLaunch) { View row = LayoutInflater.from(parent.getContext()).inflate( - viewResource, parent, false); + R.layout.dictionary_manager_row, parent, false); final TextView name = (TextView) row.findViewById(R.id.dictionaryName); final TextView details = (TextView) row.findViewById(R.id.dictionaryDetails); name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename)); - if (!canLaunch) { - final Button downloadButton = (Button) row.findViewById(R.id.downloadButton); - downloadButton.setText(getString(R.string.downloadButton, dictionaryInfo.zipBytes / 1024.0 / 1024.0)); + final boolean updateAvailable = application.updateAvailable(dictionaryInfo); + final Button downloadButton = (Button) row.findViewById(R.id.downloadButton); + if (!canLaunch || updateAvailable) { + downloadButton.setText(getString(R.string.downloadButton, application.getDownloadable(dictionaryInfo.uncompressedFilename).zipBytes / 1024.0 / 1024.0)); downloadButton.setMinWidth(application.languageButtonPixels * 3 / 2); downloadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { - DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); - Request request = new Request( - Uri.parse(dictionaryInfo.downloadUrl)); - try { - final String destFile = new File(new URL(dictionaryInfo.downloadUrl).getFile()).getName(); - Log.d(LOG, "Downloading to: " + destFile); - - request.setDestinationUri(Uri.fromFile(new File(Environment.getExternalStorageDirectory(), destFile))); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - downloadManager.enqueue(request); + downloadDictionary(dictionaryInfo); } }); + } else { + downloadButton.setVisibility(View.INVISIBLE); } - final StringBuilder builder = new StringBuilder(); LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons); final List sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos); + final StringBuilder builder = new StringBuilder(); + if (updateAvailable) { + builder.append(getString(R.string.updateButton)); + } for (IndexInfo indexInfo : sortedIndexInfos) { final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo); buttons.addView(button); @@ -520,5 +534,20 @@ public class DictionaryManagerActivity extends SherlockListActivity { return row; } + + private void downloadDictionary(final DictionaryInfo dictionaryInfo) { + DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); + Request request = new Request( + Uri.parse(dictionaryInfo.downloadUrl)); + try { + final String destFile = new File(new URL(dictionaryInfo.downloadUrl).getFile()).getName(); + Log.d(LOG, "Downloading to: " + destFile); + + request.setDestinationUri(Uri.fromFile(new File(Environment.getExternalStorageDirectory(), destFile))); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + downloadManager.enqueue(request); + } } diff --git a/todo.txt b/todo.txt index adbbcd1..72f25ff 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,3 @@ -* Application: fix which directory the thing uses: use default SD card instead of what's in prefs. -* Show download button when dictionaries can be updated. -* Text rows are too tall. \ No newline at end of file +* Contributions from: +* Unable to read quickdic dir message. +* HtmlEntries inline, expandable. \ No newline at end of file