]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
1.6
authorthadh <thadh@THADH-LAPTOP.ad.corp.google.com>
Thu, 29 Oct 2009 08:08:28 +0000 (01:08 -0700)
committerthadh <thadh@THADH-LAPTOP.ad.corp.google.com>
Thu, 29 Oct 2009 08:08:28 +0000 (01:08 -0700)
12 files changed:
AndroidManifest.xml
res/layout/download.xml
res/layout/main.xml
res/layout/no_dictionary.xml
res/values-de/strings.xml
res/values/strings.xml
res/xml/preferences.xml
src/com/hughes/android/dictionary/Dictionary.java
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/DownloadActivity.java
src/com/hughes/android/dictionary/Entry.java
src/com/hughes/android/dictionary/NoDictionaryActivity.java

index 4acdfe26e70586fc38c2d2022abc779958832420..3107cf0fb1b273c43ad0eeb50a463da896b1a5a8 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-       package="com.hughes.android.dictionary" android:versionName="1.2" android:versionCode="5">
+       package="com.hughes.android.dictionary" android:versionName="1.6" android:versionCode="6">
 
        <uses-sdk android:minSdkVersion="2" />
        <uses-permission android:name="android.permission.INTERNET"/>
index a0edb5ad140978a601600f6caae2460ecba4fd5c..af67bd8c8bcbac498396719085b707076d14bdde 100755 (executable)
@@ -4,30 +4,31 @@
        android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
 
        <TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
-               android:layout_height="wrap_content" android:text="Downloading..."></TextView>
+               android:layout_height="wrap_content" android:text="Downloading..."/>
 
        <LinearLayout android:id="@+id/sourceLayout"
                android:orientation="horizontal" android:layout_width="fill_parent"
                android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
                <TextView android:id="@+id/sourceTitle" android:layout_width="wrap_content"
-                       android:layout_height="wrap_content" android:text="Source: "></TextView>
+                       android:layout_height="wrap_content" android:text="Source: "/>
                <TextView android:id="@+id/source" android:layout_width="wrap_content"
-                       android:layout_height="wrap_content" android:text="source"></TextView>
+                       android:layout_height="wrap_content" android:text="source"/>
        </LinearLayout>
 
        <LinearLayout android:id="@+id/destLayout"
                android:orientation="horizontal" android:layout_width="fill_parent"
                android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
                <TextView android:id="@+id/destTitle" android:layout_width="wrap_content"
-                       android:layout_height="wrap_content" android:text="Destination: "></TextView>
+                       android:layout_height="wrap_content" android:text="Destination: "/>
                <TextView android:id="@+id/dest" android:layout_width="wrap_content"
-                       android:layout_height="wrap_content" android:text="dest"></TextView>
+                       android:layout_height="wrap_content" android:text="dest"/>
        </LinearLayout>
 
-       <ProgressBar android:id="@+id/downloadProgressBar"
-               android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminate="false"></ProgressBar>
+       <ProgressBar android:id="@+id/downloadProgressBar" style="?android:attr/progressBarStyleHorizontal"
+    android:max="100" android:progress="50"
+               android:layout_width="fill_parent" android:layout_height="wrap_content" android:indeterminate="false"/>
 
        <TextView android:id="@+id/downloadStatus" android:layout_width="wrap_content"
-               android:layout_height="wrap_content" android:visibility="visible" android:text="Download status."></TextView>
+               android:layout_height="wrap_content" android:visibility="visible" android:text="Download status."/>
 
 </LinearLayout>
index 2862dcdcce86a10ef349f21fd72a154fcd51026e..c12bb0f4b2210ae173b752de5dd4b8c113596e14 100755 (executable)
                                android:inputType="text" 
                                android:layout_weight="1.0"/>
                                
+      <Button 
+        android:id="@+id/ClearSearchTextButton"
+        android:text="&lt;x"
+        android:minWidth="50dip"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        />
+
                        <Button 
                                android:id="@+id/LangButton"
                                android:text="LANG"
index 9ab0b85c635ba5d9ddcf52e90c68c4e282183f51..abc1b86b7d084b8ca542b8a4c2fce2576130cd58 100755 (executable)
@@ -15,6 +15,7 @@
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|fill_vertical"
+               android:layout_marginBottom="5dip"
        />
 
   <Button 
index a7662f69332d122fa9e727fccdbcf1d0a722609e..c461463472145d3f5997e689b046396561246714 100755 (executable)
   <string name="failedAddingToWordList">Fehler bei Wortliste hinzufugen: %s</string>
 
        <!-- About. -->
-       <string name="titleWithVersion">QuickDic 1.2</string>
+       <string name="titleWithVersion">QuickDic 1.6</string>
        <string name="thadHughes">Thad Hughes</string>
        <string name="contactMe">Wenn QuickDic dir gefällt, würde ich gern von dir hören.  Bitte schicke Bemerkungen, Aufforderungen, oder Programmfehler an:</string>
        <string name="myEmail">thad.hughes+quickdic@gmail.com</string>
        <string name="currentDictInfo">Wörterbuch Info:</string>
        <string name="noDictLoaded">Kein Wörterbuch geöffnet.</string>
+  <string name="aboutText"><![CDATA[%s\n
+\n
+Einträgezahl: %d\n
+%s:\n
+  Wörterzahl: %d\n
+  Reihezahl: %d\n
+%s:\n
+  Wörterzahl: %d\n
+  Reihezahl: %d\n
+]]></string>
        
        <!-- Download. -->
-       <string name="downloading">%d Bytes heruntergeladen...</string>
+       <string name="downloading">%d von %d Bytes heruntergeladen...</string>
        <string name="downloadFinished">Herunterladen fertig, %d Bytes heruntergeladen.</string>
        <string name="errorDownloadingFile">"Fehler während des Herunterladens: \n%s"</string>
 
   <!-- NoDictionary. -->
-  <string name="unableToReadDictionaryFile">Wörterbuch Datei existiert nicht: %s</string>
+  <string name="unableToReadDictionaryFile">Wörterbuch Datei existiert nicht (oder ist eine alte Version): %s</string>
   <string name="DictionaryFileExists">Wörterbuch Datei existiert: %s</string>
   <string name="launchDict">"Launch dictionary."</string>
 
        <string name="wordListFileSummary">Die Datei, in der neue Worte hinzugefügt werden.</string>
        <string name="wordListFileDefault">/sdcard/wordList.txt</string>
 
+  <string name="saveOnlyFirstSubentryKey">saveOnlyFirstSubentry</string>
+  <string name="saveOnlyFirstSubentryTitle">Save only first sub-entry</string>
+  <string name="saveOnlyFirstSubentrySummary">For entries with multiple sub-entries, only write the first to the word list.</string>
+
+  <string name="showClearSearchTextButtonKey">showClearSearchTextButton</string>
+  <string name="showClearSearchTextButtonTitle">Show 'clear search text' button</string>
+  <string name="showClearSearchTextButtonSummary">Show the button to clear the search text. You can also just move focus away from search text and start typing.</string>
+  
        <string name="dictFileKey">dictFile</string>
        <string name="dictFileTitle">Wörterbuch Datei</string>
        <string name="dictFileSummary">Die Datei, die das Wörterbuch enthält (und worein das Wörterbuch heruntergeladen wird).</string>
index 1a8a8f40675a2ea173ef2442b877c290bd1d64fa..6ffc831480d10d907ed3860de2479f801890f0ca 100755 (executable)
   <string name="failedAddingToWordList">Failure adding to word list: %s</string>
 
        <!-- About. -->
-       <string name="titleWithVersion">QuickDic 1.2</string>
+       <string name="titleWithVersion">QuickDic 1.6</string>
        <string name="thadHughes">Thad Hughes</string>
        <string name="contactMe">If you're using QuickDic, I'd love to hear from you.  Please send comments, suggestions, bug reports, or just a quick hello to:</string>
        <string name="myEmail">thad.hughes+quickdic@gmail.com</string>
        <string name="currentDictInfo">Current dictionary info:</string>
        <string name="noDictLoaded">No dictionary loaded.</string>
+  <string name="aboutText"><![CDATA[%s\n
+\n
+Entry count: %d\n
+%s:\n
+  Unique token count: %d\n
+  Row count: %d\n
+%s:\n
+  Unique token count: %d\n
+  Row count: %d\n
+]]></string>
        
        <!-- Download. -->
-       <string name="downloading">Downloading, %d bytes so far</string>
+       <string name="downloading">Downloading, %d of %d bytes.</string>
        <string name="downloadFinished">Download finished, %d bytes downloaded.</string>
        <string name="errorDownloadingFile">"Error downloading file: \n%s"</string>
 
   <!-- NoDictionary. -->
-  <string name="unableToReadDictionaryFile">Unable to read dictionary file: %s</string>
+  <string name="unableToReadDictionaryFile">Unable to read dictionary file (or version is old, try downloading again): %s</string>
   <string name="dictionaryFileExists">Dictionary file exists: %s</string>
   <string name="launchDict">Launch dictionary.</string>
 
        <string name="wordListFileSummary">The local file where the word list will be appended.</string>
        <string name="wordListFileDefault">/sdcard/wordList.txt</string>
 
+  <string name="saveOnlyFirstSubentryKey">saveOnlyFirstSubentry</string>
+  <string name="saveOnlyFirstSubentryTitle">Save only first sub-entry</string>
+  <string name="saveOnlyFirstSubentrySummary">For entries with multiple sub-entries, only write the first to the word list.</string>
+
+  <string name="showClearSearchTextButtonKey">showClearSearchTextButton</string>
+  <string name="showClearSearchTextButtonTitle">Show 'clear search text' button</string>
+  <string name="showClearSearchTextButtonSummary">Show the button to clear the search text. You can also just move focus away from search text and start typing.</string>
+  
        <string name="dictFileKey">dictFile</string>
        <string name="dictFileTitle">Dictionary file</string>
        <string name="dictFileSummary">The local filename where the dictionary is stored (and downloaded to).</string>
@@ -46,5 +64,5 @@
        <string name="dictFetchUrlTitle">Dictionary fetch URL</string>
        <string name="dictFetchUrlSummary">URL to use to download the dictionary from the Internet.</string>
        <string name="dictFetchUrlDefault">http://www.stanford.edu/~egirard/dict/de-en.dict</string>
-       
+
 </resources>
index b43d391ba797bc62c74f4669b52c9db8c26a747b..91784be2928acf9e654306bcd9aa97fc15c21e0a 100755 (executable)
@@ -1,27 +1,43 @@
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">\r
 \r
        <EditTextPreference\r
-           android:key="@string/wordListFileKey"\r
-               android:title="@string/wordListFileTitle" \r
-               android:summary="@string/wordListFileSummary"\r
+         android:key="@string/wordListFileKey"\r
+    android:title="@string/wordListFileTitle" \r
+    android:summary="@string/wordListFileSummary"\r
                android:defaultValue="@string/wordListFileDefault"\r
-               android:persistent="true"\r
+    android:persistent="true"\r
        />\r
-               \r
+\r
+  <CheckBoxPreference \r
+    android:key="@string/saveOnlyFirstSubentryKey"\r
+    android:title="@string/saveOnlyFirstSubentryTitle"\r
+    android:summary="@string/saveOnlyFirstSubentrySummary"\r
+    android:defaultValue="false"\r
+    android:persistent="true"\r
+  />\r
+\r
+  <CheckBoxPreference \r
+    android:key="@string/showClearSearchTextButtonKey"\r
+    android:title="@string/showClearSearchTextButtonTitle"\r
+    android:summary="@string/showClearSearchTextButtonSummary"\r
+    android:defaultValue="true"\r
+    android:persistent="true"\r
+  />\r
+\r
        <EditTextPreference \r
-               android:key="@string/dictFileKey"\r
-               android:title="@string/dictFileTitle"\r
-               android:summary="@string/dictFileSummary"\r
-               android:defaultValue="@string/dictFileDefault"\r
-               android:persistent="true" \r
-               />\r
-               
+    android:key="@string/dictFileKey"\r
+    android:title="@string/dictFileTitle"\r
+    android:summary="@string/dictFileSummary"\r
+    android:defaultValue="@string/dictFileDefault"\r
+    android:persistent="true" \r
+    />\r
+    
        <EditTextPreference \r
-           android:key="@string/dictFetchUrlKey"\r
-           android:title="@string/dictFetchUrlTitle"
-               android:summary="@string/dictFetchUrlSummary"\r
-               android:defaultValue="@string/dictFetchUrlDefault"
-               android:persistent="true"\r
+         android:key="@string/dictFetchUrlKey"\r
+         android:title="@string/dictFetchUrlTitle"
+    android:summary="@string/dictFetchUrlSummary"\r
+    android:defaultValue="@string/dictFetchUrlDefault"
+    android:persistent="true"\r
        />
-
+\r
 </PreferenceScreen>  
\ No newline at end of file
index 05881295287e4be5a1aecd0ae0027bc0ce4ec2ae..dfca94617d2327b67a307c48436ffada79dbd9af 100755 (executable)
@@ -15,6 +15,8 @@ import com.hughes.util.raf.RAFSerializer;
 import com.hughes.util.raf.UniformFileList;\r
 \r
 public final class Dictionary implements RAFSerializable<Dictionary> {\r
+  \r
+  private static final String VERSION_CODE = "DictionaryVersion=1.5";\r
 \r
   static final RAFSerializer<Entry> ENTRY_SERIALIZER = new RAFSerializableSerializer<Entry>(\r
       Entry.RAF_FACTORY);\r
@@ -40,6 +42,9 @@ public final class Dictionary implements RAFSerializable<Dictionary> {
         .getFilePointer()), 10000);\r
     languageDatas[0] = new LanguageData(this, raf, Entry.LANG1);\r
     languageDatas[1] = new LanguageData(this, raf, Entry.LANG2);\r
+    if (!VERSION_CODE.equals(raf.readUTF())) {\r
+      throw new IOException("Invalid dictionary version, expected: " + VERSION_CODE);\r
+    }\r
   }\r
 \r
   public void write(RandomAccessFile raf) throws IOException {\r
@@ -47,6 +52,7 @@ public final class Dictionary implements RAFSerializable<Dictionary> {
     FileList.write(raf, entries, ENTRY_SERIALIZER);\r
     languageDatas[0].write(raf);\r
     languageDatas[1].write(raf);\r
+    raf.writeUTF(VERSION_CODE);\r
   }\r
 \r
   final class LanguageData implements RAFSerializable<LanguageData> {\r
@@ -83,9 +89,9 @@ public final class Dictionary implements RAFSerializable<Dictionary> {
       FileList.write(raf, sortedIndex, INDEX_ENTRY_SERIALIZER);\r
     }\r
 \r
-    String rowToString(final Row row) {\r
+    String rowToString(final Row row, final boolean onlyFirstSubentry) {\r
       return row.isToken() ? sortedIndex.get(row.getIndex()).word : entries\r
-          .get(row.getIndex()).toString();\r
+          .get(row.getIndex()).getRawText(onlyFirstSubentry);\r
     }\r
 \r
     int lookup(String word, final AtomicBoolean interrupted) {\r
index f1d529d2a593e8f0a9defbc4a498c08c227d1a14..76a79970ecdbf26d55928142fac56447ac21dbf2 100755 (executable)
@@ -52,9 +52,9 @@ import com.hughes.android.dictionary.Dictionary.Row;
 public class DictionaryActivity extends ListActivity {
   
   // TODO:
-  // * Version magic number at end of dictionary, checked for correctness. (Throw exception in ctor, remember to check for it).
-  // * Localize "about" string if % codes
-  // * Toast when word gets added to word list.
+  // * Download latest dicts.
+  //   * http://ftp.tu-chemnitz.de/pub/Local/urz/ding/de-en-devel/
+  //   * http://www1.dict.cc/translation_file_request.php?l=e
   // * Compress all the strings everywhere, put compression table in file.
   // Done:
   // * Only one way to way for current search to end. (won't do).
@@ -69,7 +69,7 @@ public class DictionaryActivity extends ListActivity {
 
   EditText searchText;
   Button langButton;
-  int lastSelectedRow = 0;
+  int lastSelectedRow = 0;  // TODO: I'm evil.
 
   private boolean prefsMightHaveChanged = true;
 
@@ -77,6 +77,7 @@ public class DictionaryActivity extends ListActivity {
   private File wordList;
   private RandomAccessFile dictRaf = null;
   private Dictionary dictionary = null;
+  private boolean saveOnlyFirstSubentry = false;
 
   // Visible for testing.
   LanguageListAdapter languageList = null;
@@ -91,11 +92,12 @@ public class DictionaryActivity extends ListActivity {
     if (Language.EN.sortCollator.compare("pre-print", "preppy") >= 0) {
       Log
           .e(LOG,
-              "Android java.text.Collator is buggy, lookups may not work properly.");
+              Language.EN.sortCollator.getClass() + " is buggy, lookups may not work properly.");
     }
 
-    initDictionaryAndPrefs();
-    if (dictRaf == null) {
+    try {
+      initDictionaryAndPrefs();
+    } catch (Exception e) {
       return;
     }
 
@@ -109,22 +111,41 @@ public class DictionaryActivity extends ListActivity {
     searchText.addTextChangedListener(new SearchTextWatcher());
     
     getListView().setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
-      public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
+      public void onItemSelected(AdapterView<?> arg0, View arg1, int row,
           long arg3) {
-        lastSelectedRow = arg2;
-        updateSearchText();
+        setSelectedRow(row);
       }
       public void onNothingSelected(AdapterView<?> arg0) {
       }
     });
-
-    // Language button.
+    
+    getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+      public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int row,
+          long arg3) {
+        setSelectedRow(row);
+        return false;
+      }
+    });
+    
+    final Button clearSearchTextButton = (Button) findViewById(R.id.ClearSearchTextButton);
+    clearSearchTextButton.setOnClickListener(new OnClickListener() {
+      public void onClick(View v) {
+        clearSearchTextButton.requestFocus();
+        searchText.setText("");
+        searchText.requestFocus();
+      }
+    });
+    clearSearchTextButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
+        getString(R.string.showClearSearchTextButtonKey), true) ? View.VISIBLE
+        : View.GONE);
+    
     final Button langButton = (Button) findViewById(R.id.LangButton);
     langButton.setOnClickListener(new OnClickListener() {
       public void onClick(View v) {
         onLanguageButton();
       }
     });
+    
     final Button upButton = (Button) findViewById(R.id.UpButton);
     upButton.setOnClickListener(new OnClickListener() {
       public void onClick(View v) {
@@ -144,7 +165,7 @@ public class DictionaryActivity extends ListActivity {
     updateLangButton();
   }
   
-  private void initDictionaryAndPrefs() {
+  private void initDictionaryAndPrefs() throws Exception {
     if (!prefsMightHaveChanged) {
       return;
     }
@@ -155,27 +176,30 @@ public class DictionaryActivity extends ListActivity {
     wordList = new File(prefs.getString(getString(R.string.wordListFileKey),
         getString(R.string.wordListFileDefault)));
     Log.d(LOG, "wordList=" + wordList);
+    
+    saveOnlyFirstSubentry = prefs.getBoolean(getString(R.string.saveOnlyFirstSubentryKey), false);
 
     final File dictFile = new File(prefs.getString(getString(R.string.dictFileKey),
         getString(R.string.dictFileDefault)));
     Log.d(LOG, "dictFile=" + dictFile);
+    
+    try {
     if (!dictFile.canRead()) {
-      Log.w(LOG, "Unable to read dictionary file.");
-      this.startActivity(new Intent(this, NoDictionaryActivity.class));
-      finish();
+      throw new IOException("Unable to read dictionary file.");
     }
-
-    try {
-      dictRaf = new RandomAccessFile(dictFile, "r");
-      dictionary = new Dictionary(dictRaf);
-    } catch (Exception e) {
+    
+    dictRaf = new RandomAccessFile(dictFile, "r");
+    dictionary = new Dictionary(dictRaf);
+    } catch (IOException e) {
       Log.e(LOG, "Couldn't open dictionary.", e);
-      return;
+      this.startActivity(new Intent(this, NoDictionaryActivity.class));
+      finish();
+      throw new Exception(e);
     }
-
+    
     final byte lang = prefs.getInt(PREF_DICT_ACTIVE_LANG, Entry.LANG1) == Entry.LANG1 ? Entry.LANG1
         : Entry.LANG2;
-
+    
     languageList = new LanguageListAdapter(dictionary.languageDatas[lang]);
     setListAdapter(languageList);
     prefsMightHaveChanged = false;
@@ -186,15 +210,19 @@ public class DictionaryActivity extends ListActivity {
     super.onResume();
     Log.d(LOG, "onResume:" + this);
 
-    initDictionaryAndPrefs();
+    try {
+      initDictionaryAndPrefs();
+    } catch (Exception e) {
+      return;
+    }
     
     final SharedPreferences prefs = PreferenceManager
         .getDefaultSharedPreferences(this);
     final String searchTextString = prefs
         .getString(PREF_ACTIVE_SEARCH_TEXT, "");
     searchText.setText(searchTextString);
-    onSearchTextChange(searchTextString);
     getListView().requestFocus();
+    onSearchTextChange(searchTextString);
   }
 
   @Override
@@ -234,10 +262,9 @@ public class DictionaryActivity extends ListActivity {
     dictRaf = null;
   }
 
-  public String getSelectedRowRawText() {
-    final int row = getSelectedRow();
-    return row < 0 ? "" : languageList.languageData
-        .rowToString(languageList.languageData.rows.get(row));
+  public String getSelectedRowRawText(final boolean onlyFirstSubentry) {
+    final Row row = languageList.languageData.rows.get(getSelectedRow());
+    return languageList.languageData.rowToString(row, onlyFirstSubentry);
   }
 
   // ----------------------------------------------------------------
@@ -272,22 +299,15 @@ public class DictionaryActivity extends ListActivity {
       public boolean onMenuItemClick(final MenuItem menuItem) {
         final Intent intent = new Intent().setClassName(AboutActivity.class
             .getPackage().getName(), AboutActivity.class.getCanonicalName());
-        final StringBuilder currentDictInfo = new StringBuilder();
+        final String currentDictInfo;
         if (dictionary == null) {
-          currentDictInfo.append(getString(R.string.noDictLoaded));
+          currentDictInfo = getString(R.string.noDictLoaded);
         } else {
-          currentDictInfo.append(dictionary.dictionaryInfo).append("\n\n");
-          currentDictInfo.append("Entry count: " + dictionary.entries.size())
-              .append("\n");
-          for (int i = 0; i < 2; ++i) {
-            final LanguageData languageData = dictionary.languageDatas[i];
-            currentDictInfo.append(languageData.language.symbol).append(":\n");
-            currentDictInfo.append(
-                "  Unique token count: " + languageData.sortedIndex.size())
-                .append("\n");
-            currentDictInfo.append("  Row count: " + languageData.rows.size())
-                .append("\n");
-          }
+          final LanguageData lang0 = dictionary.languageDatas[0];
+          final LanguageData lang1 = dictionary.languageDatas[1];
+          currentDictInfo = getString(R.string.aboutText, dictionary.dictionaryInfo, dictionary.entries.size(), 
+              lang0.language.symbol, lang0.sortedIndex.size(), lang0.rows.size(),
+              lang1.language.symbol, lang1.sortedIndex.size(), lang1.rows.size());
         }
         intent.putExtra(AboutActivity.CURRENT_DICT_INFO, currentDictInfo
             .toString());
@@ -299,6 +319,7 @@ public class DictionaryActivity extends ListActivity {
     final MenuItem download = menu.add(getString(R.string.downloadDictionary));
     download.setOnMenuItemClickListener(new OnMenuItemClickListener() {
       public boolean onMenuItemClick(final MenuItem menuItem) {
+        prefsMightHaveChanged = true;
         startDownloadDictActivity(DictionaryActivity.this);
         return false;
       }
@@ -335,13 +356,13 @@ public class DictionaryActivity extends ListActivity {
   }
 
   void onUpButton() {
-    final int destRowIndex = languageList.languageData.getPrevTokenRow(lastSelectedRow);
+    final int destRowIndex = languageList.languageData.getPrevTokenRow(getSelectedRow());
     Log.d(LOG, "onUpButton, destRowIndex=" + destRowIndex);
     jumpToRow(languageList, destRowIndex);
   }
 
   void onDownButton() {
-    final int destRowIndex = languageList.languageData.getNextTokenRow(lastSelectedRow);
+    final int destRowIndex = languageList.languageData.getNextTokenRow(getSelectedRow());
     Log.d(LOG, "onDownButton, destRowIndex=" + destRowIndex);
     jumpToRow(languageList, destRowIndex);
   }
@@ -357,7 +378,7 @@ public class DictionaryActivity extends ListActivity {
         new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date()))
         .append("\t");
     rawText.append(word).append("\t");
-    rawText.append(getSelectedRowRawText());
+    rawText.append(getSelectedRowRawText(saveOnlyFirstSubentry));
     Log.d(LOG, "Writing : " + rawText);
     try {
       wordList.getParentFile().mkdirs();
@@ -379,7 +400,7 @@ public class DictionaryActivity extends ListActivity {
     }
     Log.d(LOG, "Copy." + DictionaryActivity.this.getSelectedRow());
     final StringBuilder result = new StringBuilder();
-    result.append(getSelectedRowRawText());
+    result.append(getSelectedRowRawText(false));
     final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
     clipboardManager.setText(result.toString());
     Log.d(LOG, "Copied: " + result);
@@ -400,7 +421,7 @@ public class DictionaryActivity extends ListActivity {
 
   @Override
   protected void onListItemClick(ListView l, View v, int row, long id) {
-    Log.d(LOG, "Clicked: " + getSelectedRowRawText());
+    setSelectedRow(row);
     openContextMenu(getListView());
   }
 
@@ -452,8 +473,7 @@ public class DictionaryActivity extends ListActivity {
       return;
     }
     setSelection(rowIndex);
-    lastSelectedRow = rowIndex;  // TODO: find a way to delete this.
-    updateSearchText();
+    setSelectedRow(rowIndex);
     getListView().setSelected(true);
   }
   
@@ -461,6 +481,11 @@ public class DictionaryActivity extends ListActivity {
   private int getSelectedRow() {
     return lastSelectedRow;
   }
+  private void setSelectedRow(final int row) {
+    lastSelectedRow = row;
+    Log.d(LOG, "Selected: " + getSelectedRowRawText(true));
+    updateSearchText();
+  }
 
   private void updateSearchText() {
     Log.d(LOG, "updateSearchText");
@@ -531,7 +556,7 @@ public class DictionaryActivity extends ListActivity {
         if (row == null) {
           return result;
         }
-        result.setText(languageData.rowToString(row));
+        result.setText(languageData.rowToString(row, false));
         result.setTextAppearance(parent.getContext(),
             android.R.style.TextAppearance_Large);
         result.setClickable(false);
index 5723eef3ff247045d59036cae0e64d721b08f96d..cff7463e83d5b262c1e3e795f08c88637977e629 100755 (executable)
@@ -5,6 +5,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.net.URL;\r
+import java.net.URLConnection;\r
 import java.util.concurrent.Executor;\r
 import java.util.concurrent.Executors;\r
 import java.util.concurrent.atomic.AtomicBoolean;\r
@@ -24,6 +25,8 @@ public class DownloadActivity extends Activity {
 \r
   String source;\r
   String dest;\r
+  long bytesDownloaded = 0;\r
+  long contentLength = -1;\r
 \r
   private final Executor downloadExecutor = Executors.newSingleThreadExecutor();\r
   private final Handler uiHandler = new Handler();\r
@@ -61,7 +64,9 @@ public class DownloadActivity extends Activity {
       destTmpFile = File.createTempFile("dictionaryDownload", "tmp", destFile\r
           .getParentFile());\r
       final URL uri = new URL(source);\r
-      in = uri.openStream();\r
+      final URLConnection connection = uri.openConnection();\r
+      contentLength = connection.getContentLength();\r
+      in = connection.getInputStream();\r
       out = new FileOutputStream(destTmpFile);\r
     } catch (Exception e) {\r
       Log.e("THAD", "Error downloading file", e);\r
@@ -72,16 +77,16 @@ public class DownloadActivity extends Activity {
     final Runnable runnable = new Runnable() {\r
       public void run() {\r
         try {\r
-          long byteCount = 0;\r
+          bytesDownloaded = 0;\r
           int bytesRead;\r
           final byte[] bytes = new byte[1024 * 8];\r
           int count = 0;\r
           while ((bytesRead = in.read(bytes)) != -1 && !stop.get()) {\r
             out.write(bytes, 0, bytesRead);\r
-            byteCount += bytesRead;\r
+            bytesDownloaded += bytesRead;\r
             if (count++ % 20 == 0) {\r
-              setDownloadStatus(String.format(getString(R.string.downloading),\r
-                  byteCount));\r
+              setDownloadStatus(getString(R.string.downloading,\r
+                  bytesDownloaded, contentLength));\r
             }\r
           }\r
           in.close();\r
@@ -90,10 +95,10 @@ public class DownloadActivity extends Activity {
             destFile.delete();\r
             destTmpFile.renameTo(destFile);\r
           } else {\r
-            Log.d("THAD", "Stopped downloading file.");\r
+           Log.d("THAD", "Stopped downloading file.");\r
           }\r
           setDownloadStatus(String.format(getString(R.string.downloadFinished),\r
-              byteCount));\r
+              bytesDownloaded));\r
         } catch (IOException e) {\r
           Log.e("THAD", "Error downloading file", e);\r
           setDownloadStatus(String.format(getString(R.string.errorDownloadingFile), e.getLocalizedMessage()));\r
@@ -111,10 +116,14 @@ public class DownloadActivity extends Activity {
   }\r
 \r
   private void setDownloadStatus(final String status) {\r
-    final TextView downloadStatus = (TextView) findViewById(R.id.downloadStatus);\r
-//    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);\r
     uiHandler.post(new Runnable() {\r
       public void run() {\r
+        final ProgressBar progressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);\r
+        if (contentLength > 0) {\r
+          progressBar.setProgress((int) (bytesDownloaded * 100 / contentLength));\r
+        }\r
+        \r
+        final TextView downloadStatus = (TextView) findViewById(R.id.downloadStatus);\r
         downloadStatus.setText(status);\r
       }\r
     });\r
index 87e87a307ef0d83e89f4229c375432aa3d432993..5d1a2d9c05c50433a4da0bebbd3117537d92e518 100755 (executable)
@@ -72,7 +72,7 @@ public final class Entry implements RAFSerializable<Entry> {
 \r
   @Override\r
   public String toString() {\r
-    return getRawText();\r
+    return getRawText(false);\r
   }\r
 \r
   public int getRowCount() {\r
@@ -88,13 +88,13 @@ public final class Entry implements RAFSerializable<Entry> {
     return lang2;\r
   }\r
   \r
-  String getRawText() {\r
+  String getRawText(boolean onlyFirstSubentry) {\r
     final StringBuilder result = new StringBuilder();\r
-    for (int i = 0; i < lang1.length; ++i) {\r
+    for (int i = 0; i < (onlyFirstSubentry ? 1 : lang1.length); ++i) {\r
       result.append(i == 0 ? "" : " | ").append(lang1[i]);\r
     }\r
     result.append("\t");\r
-    for (int i = 0; i < lang2.length; ++i) {\r
+    for (int i = 0; i < (onlyFirstSubentry ? 1 : lang2.length); ++i) {\r
       result.append(i == 0 ? "" : " | ").append(lang2[i]);\r
     }\r
     return result.toString();\r
index c2093c6606b567091ea8c6abde33dc0afbc2ae5e..bc8499f146bdb3c64a45b2ccf1b2fed47efd505d 100755 (executable)
@@ -18,21 +18,8 @@ public class NoDictionaryActivity extends Activity {
   @Override\r
   public void onCreate(final Bundle savedInstanceState) {\r
       super.onCreate(savedInstanceState);\r
-\r
       setContentView(R.layout.no_dictionary);\r
       \r
-      final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);\r
-      final String dictFile = prefs.getString(getString(R.string.dictFileKey), getString(R.string.dictFileDefault));\r
-\r
-      final boolean canReadDict = new File(dictFile).canRead();\r
-        \r
-      final TextView statusText = (TextView) findViewById(R.id.statusTextId);\r
-      if (!canReadDict) {\r
-        statusText.setText(String.format(getString(R.string.unableToReadDictionaryFile), dictFile));\r
-      } else {\r
-        statusText.setText(String.format(getString(R.string.unableToReadDictionaryFile), dictFile));\r
-      }\r
-\r
       final Button downloadButton = (Button) findViewById(R.id.downloadDict);\r
       downloadButton.setOnClickListener(new OnClickListener() {\r
         public void onClick(View arg0) {\r
@@ -46,11 +33,30 @@ public class NoDictionaryActivity extends Activity {
         }});\r
 \r
       final Button launchButton = (Button) findViewById(R.id.launchDict);\r
-      launchButton.setEnabled(canReadDict);\r
       launchButton.setOnClickListener(new OnClickListener() {\r
         public void onClick(View arg0) {\r
           startActivity(new Intent(NoDictionaryActivity.this, DictionaryActivity.class));\r
         }});\r
-}\r
+  }\r
+\r
+  @Override\r
+  protected void onResume() {\r
+    super.onResume();\r
 \r
+    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);\r
+    final String dictFile = prefs.getString(getString(R.string.dictFileKey), getString(R.string.dictFileDefault));\r
+    final boolean canReadDict = new File(dictFile).canRead();\r
+\r
+    final TextView statusText = (TextView) findViewById(R.id.statusTextId);\r
+    if (!canReadDict) {\r
+      statusText.setText(String.format(getString(R.string.unableToReadDictionaryFile), dictFile));\r
+    } else {\r
+      statusText.setText(String.format(getString(R.string.unableToReadDictionaryFile), dictFile));\r
+    }\r
+\r
+    final Button launchButton = (Button) findViewById(R.id.launchDict);\r
+    launchButton.setEnabled(canReadDict);\r
+\r
+  }\r
+  \r
 }\r