]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Font size pref, reorder a few EntryTypes.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index 1bfdc29b9139179265cdefb557cd93d249b3f9b7..00d4576012d7b5356bae9aec3ddcacf15335eee8 100644 (file)
@@ -40,6 +40,7 @@ import android.text.Spannable;
 import android.text.TextWatcher;\r
 import android.text.style.StyleSpan;\r
 import android.util.Log;\r
+import android.util.TypedValue;\r
 import android.view.ContextMenu;\r
 import android.view.ContextMenu.ContextMenuInfo;\r
 import android.view.KeyEvent;\r
@@ -93,12 +94,14 @@ public class DictionaryActivity extends ListActivity {
   });\r
   private SearchOperation currentSearchOperation = null;\r
 \r
+  int fontSizeSp;\r
   EditText searchText;\r
   Button langButton;\r
 \r
   // Never null.\r
   private File wordList = null;\r
   private boolean saveOnlyFirstSubentry = false;\r
+  private boolean clickOpensContextMenu = false;\r
 \r
   // Visible for testing.\r
   ListAdapter indexAdapter = null;\r
@@ -206,10 +209,19 @@ public class DictionaryActivity extends ListActivity {
       }\r
     });\r
     \r
+    final String fontSize = prefs.getString(getString(R.string.fontSizeKey), "12");\r
+    try {\r
+      fontSizeSp = Integer.parseInt(fontSize);\r
+    } catch (NumberFormatException e) {\r
+      fontSizeSp = 12;\r
+    }\r
 \r
     setContentView(R.layout.dictionary_activity);\r
     searchText = (EditText) findViewById(R.id.SearchText);\r
+    searchText.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);\r
+    \r
     langButton = (Button) findViewById(R.id.LangButton);\r
+    langButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);\r
     \r
     searchText.requestFocus();\r
     searchText.addTextChangedListener(searchTextWatcher);\r
@@ -274,6 +286,7 @@ public class DictionaryActivity extends ListActivity {
     wordList = new File(prefs.getString(getString(R.string.wordListFileKey),\r
         getString(R.string.wordListFileDefault)));\r
     saveOnlyFirstSubentry = prefs.getBoolean(getString(R.string.saveOnlyFirstSubentryKey), false);\r
+    clickOpensContextMenu = prefs.getBoolean(getString(R.string.clickOpensContextMenuKey), false);\r
     //if (prefs.getBoolean(getString(R.string.vibrateOnFailedSearchKey), true)) {\r
       // vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);\r
     //}\r
@@ -334,7 +347,7 @@ public class DictionaryActivity extends ListActivity {
     searchText.requestFocus();\r
     Log.d(LOG, "Trying to show soft keyboard.");\r
     final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);\r
-    manager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);\r
+    manager.showSoftInput(searchText, InputMethodManager.SHOW_FORCED);\r
   }\r
   \r
   void updateLangButton() {\r
@@ -419,6 +432,18 @@ public class DictionaryActivity extends ListActivity {
       });\r
     }\r
 \r
+    {\r
+      final MenuItem about = menu.add(getString(R.string.about));\r
+      about.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
+        public boolean onMenuItemClick(final MenuItem menuItem) {\r
+          final Intent intent = new Intent().setClassName(AboutActivity.class\r
+              .getPackage().getName(), AboutActivity.class.getCanonicalName());\r
+          startActivity(intent);\r
+          return false;\r
+        }\r
+      });\r
+    }\r
+\r
     return true;\r
   }\r
 \r
@@ -453,7 +478,9 @@ public class DictionaryActivity extends ListActivity {
   \r
   @Override\r
   protected void onListItemClick(ListView l, View v, int row, long id) {\r
-    openContextMenu(v);\r
+    if (clickOpensContextMenu) {\r
+      openContextMenu(v);\r
+    }\r
   }\r
   \r
   void onAppendToWordList(final RowBase row) {\r
@@ -465,6 +492,10 @@ public class DictionaryActivity extends ListActivity {
     rawText.append(row.getTokenRow(true).getToken()).append("\t");\r
     rawText.append(row.getRawText(saveOnlyFirstSubentry));\r
     Log.d(LOG, "Writing : " + rawText);\r
+\r
+    // Request focus so that if we start typing again, it clears the text input.\r
+    getListView().requestFocus();\r
+\r
     try {\r
       wordList.getParentFile().mkdirs();\r
       final PrintWriter out = new PrintWriter(\r
@@ -479,6 +510,9 @@ public class DictionaryActivity extends ListActivity {
   }\r
 \r
   void onCopy(final RowBase row) {\r
+    // Request focus so that if we start typing again, it clears the text input.\r
+    getListView().requestFocus();\r
+\r
     Log.d(LOG, "Copy, row=" + row);\r
     final StringBuilder result = new StringBuilder();\r
     result.append(row.getRawText(false));\r
@@ -501,6 +535,12 @@ public class DictionaryActivity extends ListActivity {
       Log.d(LOG, "Clearing dictionary prefs.");\r
       DictionaryActivity.clearDictionaryPrefs(this);\r
     }\r
+    if (keyCode == KeyEvent.KEYCODE_ENTER) {\r
+//      Log.d(LOG, "Trying to hide soft keyboard.");\r
+//      final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);\r
+//      manager.hideSoftInputFromWindow(searchText, InputMethodManager.SHOW_FORCED);\r
+\r
+    }\r
     return super.onKeyDown(keyCode, event);\r
   }\r
 \r
@@ -602,7 +642,7 @@ public class DictionaryActivity extends ListActivity {
   // IndexAdapter\r
   // --------------------------------------------------------------------------\r
 \r
-  static final class IndexAdapter extends BaseAdapter {\r
+  final class IndexAdapter extends BaseAdapter {\r
     \r
     final Index index;\r
 \r
@@ -681,6 +721,9 @@ public class DictionaryActivity extends ListActivity {
 \r
         final String col2Text = index.swapPairEntries ? pair.lang1 : pair.lang2;\r
         column2.setText(col2Text, TextView.BufferType.NORMAL);\r
+        \r
+        column1.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);\r
+        column2.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);\r
 \r
         result.addView(tableRow);\r
       }\r
@@ -691,7 +734,7 @@ public class DictionaryActivity extends ListActivity {
     private View getView(TokenRow row, ViewGroup parent) {\r
       final TextView textView = new TextView(parent.getContext());\r
       textView.setText(row.getToken());\r
-      textView.setTextSize(20);\r
+      textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 6 * fontSizeSp / 5);\r
       return textView;\r
     }\r
     \r