]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Removed font stuff, added notes. Added language names to what's new.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index 5d937f8078a0179a1c2e26f0359eadf9211664a3..f526cb9eebbd46b0d09cde37c042a8459b441a28 100644 (file)
@@ -247,7 +247,8 @@ public class DictionaryActivity extends ListActivity {
       }\r
     }).start();\r
     \r
-    final String fontName = prefs.getString(getString(R.string.fontKey), "FreeSerif.ttf.jpg");\r
+    \r
+    String fontName = prefs.getString(getString(R.string.fontKey), "FreeSerif.ttf.jpg");\r
     if ("SYSTEM".equals(fontName)) {\r
       typeface = Typeface.DEFAULT;\r
     } else {\r
@@ -258,6 +259,9 @@ public class DictionaryActivity extends ListActivity {
         Toast.makeText(this, getString(R.string.fontFailure, e.getLocalizedMessage()), Toast.LENGTH_LONG).show();\r
       }\r
     }\r
+//    if (!"SYSTEM".equals(fontName)) {\r
+//      throw new RuntimeException("Test force using system font: " + fontName);\r
+//    }\r
     if (typeface == null) {\r
       Log.w(LOG, "Unable to create typeface, using default.");\r
       typeface = Typeface.DEFAULT;\r
@@ -267,7 +271,8 @@ public class DictionaryActivity extends ListActivity {
       fontSizeSp = Integer.parseInt(fontSize.trim());\r
     } catch (NumberFormatException e) {\r
       fontSizeSp = 14;\r
-    }\r
+    } \r
+\r
 \r
     setContentView(R.layout.dictionary_activity);\r
     searchText = (EditText) findViewById(R.id.SearchText);\r
@@ -278,12 +283,14 @@ public class DictionaryActivity extends ListActivity {
     \r
     searchText.requestFocus();\r
     searchText.addTextChangedListener(searchTextWatcher);\r
-    String text = "";\r
+    \r
+    // Set the search text from the intent, then the saved state.\r
+    String text = getIntent().getStringExtra(C.SEARCH_TOKEN);\r
     if (savedInstanceState != null) {\r
       text = savedInstanceState.getString(C.SEARCH_TOKEN);\r
-      if (text == null) {\r
-        text = "";\r
-      }\r
+    }\r
+    if (text == null) {\r
+      text = "";\r
     }\r
     setSearchText(text, true);\r
     Log.d(LOG, "Trying to restore searchText=" + text);\r
@@ -384,7 +391,7 @@ public class DictionaryActivity extends ListActivity {
     final SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(context).edit();\r
     prefs.putString(C.DICT_FILE, dictFile.getPath());\r
     prefs.putInt(C.INDEX_INDEX, indexIndex);\r
-    prefs.putString(C.SEARCH_TOKEN, searchToken);\r
+    prefs.putString(C.SEARCH_TOKEN, "");  // Don't need to save search token.\r
     prefs.commit();\r
   }\r
 \r
@@ -791,12 +798,26 @@ public class DictionaryActivity extends ListActivity {
     }\r
     searchText.setText(text);\r
     searchText.requestFocus();\r
+    moveCursorToRight();\r
+    if (triggerSearch) {\r
+      onSearchTextChange(text);\r
+    }\r
+  }\r
+  \r
+  private long cursorDelayMillis = 100;\r
+  private void moveCursorToRight() {\r
     if (searchText.getLayout() != null) {\r
+      cursorDelayMillis = 100;\r
       // Surprising, but this can crash when you rotate...\r
       Selection.moveToRightEdge(searchText.getText(), searchText.getLayout());\r
-    }\r
-    if (triggerSearch) {\r
-      onSearchTextChange(text);\r
+    } else {\r
+      uiHandler.postDelayed(new Runnable() {\r
+        @Override\r
+        public void run() {\r
+          moveCursorToRight();\r
+        }\r
+      }, cursorDelayMillis);\r
+      cursorDelayMillis = Math.min(10 * 1000, 2 * cursorDelayMillis);\r
     }\r
   }\r
 \r