]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Fixed crashes, Slovenian fix, hide up/down buttons, proper keyboard
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index 75751c711c1a165c01dd46544a5d0134c7136c9b..fe0e57fb2243c767e8d62b18cba48fabd301bc64 100644 (file)
@@ -79,6 +79,7 @@ import com.hughes.android.dictionary.engine.TokenRow;
 import com.hughes.android.dictionary.engine.TransliteratorManager;
 import com.hughes.android.util.IntentLauncher;
 import com.hughes.android.util.NonLinkClickableSpan;
+import com.hughes.util.StringUtil;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -127,6 +128,7 @@ public class DictionaryActivity extends ListActivity {
     volatile boolean ttsReady;
     
     int textColorFg = Color.BLACK;
+    
 
     private final Executor searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
         @Override
@@ -371,6 +373,12 @@ public class DictionaryActivity extends ListActivity {
                 onUpDownButton(false);
             }
         });
+        upButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this)
+                .getBoolean(getString(R.string.showPrevNextButtonsKey), true) ? View.VISIBLE
+                : View.GONE);
+        downButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this)
+                .getBoolean(getString(R.string.showPrevNextButtonsKey), true) ? View.VISIBLE
+                : View.GONE);
 
 //        getListView().setOnItemSelectedListener(new ListView.OnItemSelectedListener() {
 //            @Override
@@ -486,8 +494,13 @@ public class DictionaryActivity extends ListActivity {
             @Override
             public void run() {
                 Log.d(LOG, "Trying to show soft keyboard.");
+                final boolean searchTextHadFocus = searchText.hasFocus();
+                searchText.requestFocus();
                 final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                 manager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);
+                if (!searchTextHadFocus) {
+                    defocusSearchText();
+                }
             }}, 100);
     }
 
@@ -505,13 +518,15 @@ public class DictionaryActivity extends ListActivity {
     }
 
     private void updateTTSLanuage() {
-        if (!ttsReady) {
+        if (!ttsReady || index == null || textToSpeech == null) {
+            Log.d(LOG, "Can't updateTTSLanguage.");
             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.LANG_AVAILABLE || ttsResult != TextToSpeech.LANG_COUNTRY_AVAILABLE) {
+        if (ttsResult != TextToSpeech.LANG_AVAILABLE || 
+            ttsResult != TextToSpeech.LANG_COUNTRY_AVAILABLE) {
             Log.e(LOG, "TTS not available in this language: ttsResult=" + ttsResult);
         }
     }
@@ -1022,7 +1037,7 @@ public class DictionaryActivity extends ListActivity {
         boolean done = false;
 
         SearchOperation(final String searchText, final Index index) {
-            this.searchText = searchText.trim();
+            this.searchText = StringUtil.normalizeWhitespace(searchText);
             this.index = index;
         }
 
@@ -1039,7 +1054,7 @@ public class DictionaryActivity extends ListActivity {
                     searchResult = index.findInsertionPoint(searchText, interrupted);
                 } else {
                     searchTokens = Arrays.asList(searchTokenArray);
-                    multiWordSearchResult = index.multiWordSearch(searchTokens, interrupted);
+                    multiWordSearchResult = index.multiWordSearch(searchText, searchTokens, interrupted);
                 }
                 Log.d(LOG,
                         "searchText=" + searchText + ", searchDuration="
@@ -1295,7 +1310,8 @@ public class DictionaryActivity extends ListActivity {
                 textView.setOnClickListener(new OnClickListener() {
                     @Override
                     public void onClick(View v) {
-                        final String html = HtmlEntry.htmlBody(htmlEntries, index.shortName);
+                        String html = HtmlEntry.htmlBody(htmlEntries, index.shortName);
+                        //Log.d(LOG, "html=" + html);
                         startActivityForResult(
                                 HtmlDisplayActivity.getHtmlIntent(String.format(
                                         "<html><head></head><body>%s</body></html>", html),