]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
go
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
old mode 100755 (executable)
new mode 100644 (file)
index 61061d5..e8d188f
@@ -36,6 +36,7 @@ import android.view.ViewGroup;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.MenuItem.OnMenuItemClickListener;
 import android.view.View.OnClickListener;
+import android.view.inputmethod.InputMethodManager;
 import android.widget.AdapterView;
 import android.widget.BaseAdapter;
 import android.widget.Button;
@@ -53,7 +54,7 @@ import com.ibm.icu.text.Collator;
 
 public class DictionaryActivity extends ListActivity {
   
-  // TODO:
+  // TO DO:
   // * 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
@@ -144,9 +145,7 @@ public class DictionaryActivity extends ListActivity {
     final Button clearSearchTextButton = (Button) findViewById(R.id.ClearSearchTextButton);
     clearSearchTextButton.setOnClickListener(new OnClickListener() {
       public void onClick(View v) {
-        clearSearchTextButton.requestFocus();
-        searchText.setText("");
-        searchText.requestFocus();
+        onClearSearchTextButton(clearSearchTextButton);
       }
     });
     clearSearchTextButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
@@ -213,8 +212,8 @@ public class DictionaryActivity extends ListActivity {
       throw new Exception(e);
     }
     
-    final byte lang = prefs.getInt(PREF_DICT_ACTIVE_LANG, Entry.LANG1) == Entry.LANG1 ? Entry.LANG1
-        : Entry.LANG2;
+    final byte lang = prefs.getInt(PREF_DICT_ACTIVE_LANG, SimpleEntry.LANG1) == SimpleEntry.LANG1 ? SimpleEntry.LANG1
+        : SimpleEntry.LANG2;
     
     languageList = new LanguageListAdapter(dictionary.languageDatas[lang]);
     setListAdapter(languageList);
@@ -351,7 +350,7 @@ public class DictionaryActivity extends ListActivity {
   @Override
   public boolean onPrepareOptionsMenu(final Menu menu) {
     switchLanguageMenuItem.setTitle(getString(R.string.switchToLanguage,
-        dictionary.languageDatas[Entry
+        dictionary.languageDatas[SimpleEntry
             .otherLang(languageList.languageData.lang)].language.symbol));
     return super.onPrepareOptionsMenu(menu);
   }
@@ -448,12 +447,19 @@ public class DictionaryActivity extends ListActivity {
   void onSearchTextChange(final String searchText) {
     Log.d(LOG, "onSearchTextChange: " + searchText);
     synchronized (this) {
-      searchOperation = new SearchOperation(languageList, searchText, searchOperation);
+      searchOperation = new SearchOperation(languageList, searchText.trim(), searchOperation);
       searchExecutor.execute(searchOperation);
     }
   }
 
-  
+  private void onClearSearchTextButton(final Button clearSearchTextButton) {
+    clearSearchTextButton.requestFocus();
+    searchText.setText("");
+    searchText.requestFocus();
+    Log.d(LOG, "Trying to show soft keyboard.");
+    final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+    manager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);
+  }
 
   // ----------------------------------------------------------------
   // ContextMenu
@@ -586,7 +592,7 @@ public class DictionaryActivity extends ListActivity {
       // Entry row(s).
       final TableLayout result = new TableLayout(parent.getContext());
 
-      final Entry entry = dictionary.entries.get(row.getIndex());
+      final SimpleEntry entry = dictionary.entries.get(row.getIndex());
       final int rowCount = entry.getRowCount();
       for (int r = 0; r < rowCount; ++r) {
         final TableRow tableRow = new TableRow(result.getContext());
@@ -598,13 +604,13 @@ public class DictionaryActivity extends ListActivity {
 
         if (r > 0) {
           final TextView spacer = new TextView(tableRow.getContext());
-          spacer.setText(r == 0 ? "\95 " : " \95 ");
+          spacer.setText(r == 0 ? "� " : " � ");
           tableRow.addView(spacer);
         }
         tableRow.addView(column1, layoutParams);
         if (r > 0) {
           final TextView spacer = new TextView(tableRow.getContext());
-          spacer.setText(r == 0 ? "\95 " : " \95 ");
+          spacer.setText(r == 0 ? "� " : " � ");
           tableRow.addView(spacer);
         }
         tableRow.addView(column2, layoutParams);
@@ -626,7 +632,7 @@ public class DictionaryActivity extends ListActivity {
         }
 
         column2.setText(
-            entry.getAllText(Entry.otherLang(languageData.lang))[r],
+            entry.getAllText(SimpleEntry.otherLang(languageData.lang))[r],
             TextView.BufferType.NORMAL);
 
         result.addView(tableRow);