X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2FDictionaryActivity.java;h=78c8a476b822cb0de1d69de411af4cef3a0d4512;hb=90f2a1acc5b5386f8af6636d9fea0706e2dbf36f;hp=5d937f8078a0179a1c2e26f0359eadf9211664a3;hpb=3c64fc1b4f0a77ce6c06f86b7b3d5f880050fe29;p=Dictionary.git diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 5d937f8..78c8a47 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -278,12 +278,14 @@ public class DictionaryActivity extends ListActivity { searchText.requestFocus(); searchText.addTextChangedListener(searchTextWatcher); - String text = ""; + + // Set the search text from the intent, then the saved state. + String text = getIntent().getStringExtra(C.SEARCH_TOKEN); if (savedInstanceState != null) { text = savedInstanceState.getString(C.SEARCH_TOKEN); - if (text == null) { - text = ""; - } + } + if (text == null) { + text = ""; } setSearchText(text, true); Log.d(LOG, "Trying to restore searchText=" + text); @@ -791,12 +793,26 @@ public class DictionaryActivity extends ListActivity { } searchText.setText(text); searchText.requestFocus(); + moveCursorToRight(); + if (triggerSearch) { + onSearchTextChange(text); + } + } + + private long cursorDelayMillis = 100; + private void moveCursorToRight() { if (searchText.getLayout() != null) { + cursorDelayMillis = 100; // Surprising, but this can crash when you rotate... Selection.moveToRightEdge(searchText.getText(), searchText.getLayout()); - } - if (triggerSearch) { - onSearchTextChange(text); + } else { + uiHandler.postDelayed(new Runnable() { + @Override + public void run() { + moveCursorToRight(); + } + }, cursorDelayMillis); + cursorDelayMillis = Math.min(10 * 1000, 2 * cursorDelayMillis); } }