]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Ready to release... And fixed cursor placement bug and preserving
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index 5d937f8078a0179a1c2e26f0359eadf9211664a3..78c8a476b822cb0de1d69de411af4cef3a0d4512 100644 (file)
@@ -278,12 +278,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
@@ -791,12 +793,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