]> 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 922b9728cda321c11c62614ba554414496ce8025..00d4576012d7b5356bae9aec3ddcacf15335eee8 100644 (file)
@@ -1,3 +1,17 @@
+// Copyright 2011 Google Inc. All Rights Reserved.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//     http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
 package com.hughes.android.dictionary;\r
 \r
 import java.io.File;\r
@@ -26,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
@@ -79,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
@@ -137,6 +154,7 @@ public class DictionaryActivity extends ListActivity {
           this).read(C.DICTIONARY_CONFIGS, QuickDicConfig.class);\r
       dictIndex = prefs.getInt(C.DICT_INDEX, 0) ;\r
       final DictionaryConfig dictionaryConfig = quickDicConfig.dictionaryConfigs.get(dictIndex);\r
+      this.setTitle("QuickDic: " + dictionaryConfig.name);\r
       dictRaf = new RandomAccessFile(dictionaryConfig.localFile, "r");\r
       dictionary = new Dictionary(dictRaf); \r
     } catch (Exception e) {\r
@@ -191,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
@@ -259,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
@@ -319,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
@@ -404,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
@@ -438,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
@@ -450,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
@@ -464,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
@@ -486,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
@@ -587,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
@@ -666,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
@@ -676,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