]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Add TTS.
authorthadh <thadh@thadh-macbookpro>
Sun, 30 Sep 2012 17:04:01 +0000 (10:04 -0700)
committerthadh <thadh@thadh-macbookpro>
Sun, 30 Sep 2012 17:04:01 +0000 (10:04 -0700)
Slovenian.
Change HTMLEntry presentation to include source.
Synonyms, antonyms.

res/values-de/strings.xml
res/values-it/strings.xml
res/values/strings.xml
src/com/hughes/android/dictionary/DictionaryActivity.java
src/com/hughes/android/dictionary/HtmlDisplayActivity.java
src/com/hughes/android/dictionary/engine/AbstractEntry.java
src/com/hughes/android/dictionary/engine/EntryTypeName.java
src/com/hughes/android/dictionary/engine/HtmlEntry.java
src/com/hughes/android/dictionary/engine/Language.java

index 3f361425799a5e6b9b89d85191ee123230630792..e89e4f470a933aad1ba97b0525789e0f33a08a93 100644 (file)
@@ -40,7 +40,8 @@
   <string name="aboutDictionary">Über Wörterbuch…</string> 
   <string name="randomWord">Random Wort</string> 
   <string name="fontFailure">Font failure: %s</string> 
-  <string name="seeAlso">vgl.: %s</string>
+  <string name="seeAlso">vgl.: %1$s (%2$s)</string>
+  <string name="speak">Sprechen</string> 
   
   
   <!-- About dictionary. -->
index 44224f62ec87ddd974c5f4c0577db1c67b93d940..137b4cb34e5a182659142c5d0088e307f7dc9490 100644 (file)
@@ -35,7 +35,9 @@ Rilevato problema di font (comune su apparecchi Sony Ericsson), ritorno a font d
 <string name="aboutDictionary">About dictionary…</string>
 <string name="randomWord">Parola a caso</string>
 <string name="fontFailure">Problema di Font: %s</string>
-<string name="seeAlso">Vedi anche: %s</string>
+<string name="seeAlso">Vedi anche: %1$s (%2$s)</string>
+<string name="speak">Pronuncia</string> 
+
 <!-- About dictionary. -->
 <string name="dictionaryPath">File: %s</string>
 <string name="dictionarySize">Dimenzione: %,d bytes</string>
index 86e5b9c219b77479b8c813aff6ff36326d347263..9cb903f2d5309237823b8732c4f782ed50f26146 100644 (file)
@@ -41,7 +41,8 @@
   <string name="aboutDictionary">About dictionary…</string> 
   <string name="randomWord">Random word</string> 
   <string name="fontFailure">Font failure: %s</string> 
-  <string name="seeAlso">See also: %s</string> 
+  <string name="seeAlso">See also: %1$s (%2$s)</string> 
+  <string name="speak">Speak</string> 
   
 
   <!-- About dictionary. -->
index 158c1fcb326b5e46533fd53edb1049c20dfb5a04..1516ce4d5e69f626e18579de6d2ada76bc4867ed 100644 (file)
@@ -24,6 +24,8 @@ import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
 import android.preference.PreferenceManager;
+import android.speech.tts.TextToSpeech;
+import android.speech.tts.TextToSpeech.OnInitListener;
 import android.text.ClipboardManager;
 import android.text.Editable;
 import android.text.Selection;
@@ -84,8 +86,10 @@ import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.Executor;
@@ -117,6 +121,9 @@ public class DictionaryActivity extends ListActivity {
 
     // package for test.
     final Handler uiHandler = new Handler();
+    
+    TextToSpeech textToSpeech;
+    volatile boolean ttsReady;
 
     private final Executor searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
         @Override
@@ -201,6 +208,15 @@ public class DictionaryActivity extends ListActivity {
 
         final Intent intent = getIntent();
         dictFile = new File(intent.getStringExtra(C.DICT_FILE));
+        
+        ttsReady = false;
+        textToSpeech = new TextToSpeech(getApplicationContext(), new OnInitListener() {
+            @Override
+            public void onInit(int status) {
+                ttsReady = true;
+                updateTTSLanuage();
+            }
+        });
 
         try {
             final String name = application.getDictionaryName(dictFile.getName());
@@ -465,6 +481,19 @@ public class DictionaryActivity extends ListActivity {
         // langButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
         langButton.setText(index.shortName);
         // }
+        updateTTSLanuage();
+    }
+    
+    private void updateTTSLanuage() {
+        if (!ttsReady) {
+            return;
+        }
+        final Locale locale = new Locale(index.sortLanguage.getIsoCode());
+        Log.d(LOG, "Setting TTS locale to: " + locale);
+        final int ttsResult = textToSpeech.setLanguage(locale);
+        if (ttsResult != TextToSpeech.SUCCESS) {
+            Log.e(LOG, "TTS not available in this language.");
+        }
     }
 
     void onLanguageButton() {
@@ -510,14 +539,19 @@ public class DictionaryActivity extends ListActivity {
         listView.setAdapter(new BaseAdapter() {
             @Override
             public View getView(int position, View convertView, ViewGroup parent) {
-                final LinearLayout result = new LinearLayout(parent.getContext());
-
                 final DictionaryInfo dictionaryInfo = getItem(position);
+
+                final LinearLayout result = new LinearLayout(parent.getContext());
+                
                 for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) {
+                    if (i > 0) {
+                        final TextView dash = new TextView(parent.getContext());
+                        dash.setText("-");
+                        result.addView(dash);
+                    }
+                    
                     final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i);
                     final Button button = new Button(parent.getContext());
-//                    final String name = application
-//                            .getDictionaryName(dictionaryInfo.uncompressedFilename);
                     button.setText(indexInfo.shortName);
                     final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(),
                             getLaunchIntent(application.getPath(dictionaryInfo.uncompressedFilename),
@@ -529,19 +563,21 @@ public class DictionaryActivity extends ListActivity {
                         };
                     };
                     button.setOnClickListener(intentLauncher);
-                    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
-                            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
-                    layoutParams.width = 0;
-                    layoutParams.weight = 1.0f;
-                    button.setLayoutParams(layoutParams);
                     result.addView(button);
                     
-                    if (i > 0) {
-                        final TextView dash = new TextView(parent.getContext());
-                        dash.setText("-");
-                        result.addView(dash);
-                    }
                 }
+                
+                final TextView nameView = new TextView(parent.getContext());
+                final String name = application
+                        .getDictionaryName(dictionaryInfo.uncompressedFilename);
+                nameView.setText(name);
+                final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
+                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+                layoutParams.width = 0;
+                layoutParams.weight = 1.0f;
+                nameView.setLayoutParams(layoutParams);
+                result.addView(nameView);
+
                 return result;
             }
 
@@ -752,11 +788,8 @@ public class DictionaryActivity extends ListActivity {
                         indexToUse = selectedSpannableIndex;
                     }
                     final boolean changeIndex = indexIndex != indexToUse;
-                    setSearchText(selectedText, !changeIndex); // If we're not
-                                                               // changing
-                                                               // index, we have
-                                                               // to
-                                                               // triggerSearch.
+                    // If we're not changing index, we have to trigger search:
+                    setSearchText(selectedText, !changeIndex); 
                     if (changeIndex) {
                         changeIndexGetFocusAndResearch(indexToUse);
                     }
@@ -766,6 +799,17 @@ public class DictionaryActivity extends ListActivity {
                 }
             });
         }
+        
+        if (row instanceof TokenRow) {
+            final MenuItem speak = menu.add(R.string.speak);
+            speak.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+                @Override
+                public boolean onMenuItemClick(MenuItem item) {
+                    textToSpeech.speak(((TokenRow) row).getToken(), TextToSpeech.QUEUE_FLUSH, new HashMap<String, String>());
+                    return false;
+                }
+            });
+        }
 
     }
 
@@ -1167,7 +1211,7 @@ public class DictionaryActivity extends ListActivity {
             return result;
         }
 
-        private TableLayout getPossibleHtmlEntryView(final boolean isTokenRow, final String text, final boolean hasMainEntry, final List<HtmlEntry> htmlEntries, final String htmlTextToHighlight, ViewGroup parent, final TableLayout result) {
+        private TableLayout getPossibleLinkToHtmlEntryView(final boolean isTokenRow, final String text, final boolean hasMainEntry, final List<HtmlEntry> htmlEntries, final String htmlTextToHighlight, ViewGroup parent, final TableLayout result) {
             final Context context = parent.getContext();
             
             final TableRow tableRow = new TableRow(result.getContext());
@@ -1216,18 +1260,20 @@ public class DictionaryActivity extends ListActivity {
                 //result.setColumnStretchable(0, true);
                 //result.setColumnStretchable(1, false);
             }
+            result.setLongClickable(true);
             return result;
         }
         
         private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) {
             final IndexEntry indexEntry = row.getIndexEntry();
-            return getPossibleHtmlEntryView(true, indexEntry.token, row.hasMainEntry, indexEntry.htmlEntries, null, parent, result);
+            return getPossibleLinkToHtmlEntryView(true, indexEntry.token, row.hasMainEntry, indexEntry.htmlEntries, null, parent, result);
         }
         
         private TableLayout getView(HtmlEntry.Row row, ViewGroup parent, final TableLayout result) {
             final HtmlEntry htmlEntry = row.getEntry();
             final TokenRow tokenRow = row.getTokenRow(true);
-            return getPossibleHtmlEntryView(false, getString(R.string.seeAlso, htmlEntry.title), false, Collections.singletonList(htmlEntry), tokenRow.getToken(), parent, result);
+            return getPossibleLinkToHtmlEntryView(false, getString(R.string.seeAlso, htmlEntry.title, htmlEntry.entrySource.getName()), 
+                    false, Collections.singletonList(htmlEntry), tokenRow.getToken(), parent, result);
         }
 
 
index a987f5d4146bc85b71387418ecb89e541767760f..0a65290772756bb635372dd5a6cbf73ba0455bfe 100644 (file)
@@ -92,7 +92,7 @@ public final class HtmlDisplayActivity extends Activity {
       }\r
     });\r
     if (!getIntent().getBooleanExtra(SHOW_OK_BUTTON, true)) {\r
-        okButton.setVisibility(View.INVISIBLE);\r
+        okButton.setVisibility(Button.GONE);\r
     }\r
   }\r
 \r
index de221eafc0eae60fa64990ddeabdfc6b0314eb45..f5d0c8d51e27565ba9192d6d3f8c06bce502937f 100644 (file)
@@ -22,7 +22,7 @@ import java.io.RandomAccessFile;
 
 public abstract class AbstractEntry extends IndexedObject {
   
-  final EntrySource entrySource;
+  public final EntrySource entrySource;
   
   protected AbstractEntry(EntrySource entrySource) {
     super(-1);
index 333ee2052a54d26d445c88b5f10cbc7322896407..743681795d2f63ab3e3676326e55e324e6ad4bb1 100644 (file)
@@ -26,6 +26,9 @@ public enum EntryTypeName {
   MULTIROW_HEAD_ONE_WORD(true, true, null),
   MULTIROW_TAIL_ONE_WORD(false, true, null),
 
+  SYNONYM_SINGLE(false, true, null),
+  ANTONYM_SINGLE(false, true, null),
+
   WIKTIONARY_TITLE_MULTI_DETAIL(false, true, WIKTIONARY_TITLE_SINGLE_DETAIL),
   WIKTIONARY_TITLE_MULTI(false, true, WIKTIONARY_TITLE_SINGLE),
   WIKTIONARY_TRANSLITERATION(),
@@ -34,6 +37,10 @@ public enum EntryTypeName {
   WIKTIONARY_ENGLISH_DEF_WIKI_LINK(),
   WIKTIONARY_ENGLISH_DEF_OTHER_LANG(),
   WIKTIONARY_ENGLISH_DEF(),
+  
+  SYNONYM_MULTI(false, true, SYNONYM_SINGLE),
+  ANTONYM_MULTI(false, true, ANTONYM_SINGLE),
+  DERIVED_TERM(false, true, null),
 
   TWO_WORDS(),
   THREE_WORDS(),
@@ -48,6 +55,7 @@ public enum EntryTypeName {
   MULTIROW_HEAD_MANY_WORDS(),
   MULTIROW_TAIL_MANY_WORDS(),
   WIKTIONARY_EXAMPLE(),
+
   // The next two are how we file entries like: "sono: {form of|essere}" under "essere".
   WIKTIONARY_BASE_FORM_SINGLE(),  // These two should be eligible for removal if the links are otherwise present.
   WIKTIONARY_BASE_FORM_MULTI(false, false, WIKTIONARY_BASE_FORM_SINGLE),
@@ -56,6 +64,7 @@ public enum EntryTypeName {
   PARENTHESIZED(),
   WIKTIONARY_TRANSLATION_SENSE(),
   SEE_ALSO(), 
+  WIKTIONARY_MENTIONED(false, true, null),
   ;
 
   final boolean mainWord;
index dc5437ba112dd46474813eb1f731f3290c7d71c0..7e24a441f49b307ed885a9bddcb0690a81680018 100644 (file)
@@ -141,7 +141,9 @@ public class HtmlEntry extends AbstractEntry implements RAFSerializable<HtmlEntr
     public static String htmlBody(final List<HtmlEntry> htmlEntries) {
         final StringBuilder result = new StringBuilder();
         for (final HtmlEntry htmlEntry : htmlEntries) {
-            result.append(String.format("<h1><a href=\"%s\">%s</a></h1>%s\n", htmlEntry.title, htmlEntry.title, htmlEntry.html));
+            result.append(String.format("<h1><a href=\"%s\">%s</a></h1>\n(%s)\n<p>%s\n", 
+                    htmlEntry.title, htmlEntry.title, htmlEntry.entrySource.name,
+                    htmlEntry.html));
         }
         return result.toString();
     }
index deeda18b245658724089eb753bcd68b31ed68a01..a731319473ad003a4a9bd42947b00b67f34f3b1d 100644 (file)
@@ -96,6 +96,7 @@ public class Language {
     isoCodeToResources.put("SA", new LanguageResources("Sanskrit", R.string.SA));\r
     isoCodeToResources.put("SR", new LanguageResources("Serbian", R.string.SR));\r
     isoCodeToResources.put("SK", new LanguageResources("Slovak", R.string.SK));\r
+    isoCodeToResources.put("SK", new LanguageResources("Slovenian", R.string.SL));\r
     isoCodeToResources.put("SO", new LanguageResources("Somali", R.string.SO));\r
     isoCodeToResources.put("ES", new LanguageResources("Spanish", R.string.ES));\r
     isoCodeToResources.put("SW", new LanguageResources("Swahili", R.string.SW));\r