Correctly set search string when entering search
Changes
1) When entering search mode, explicitly clear the
search query
2) Make sure that the cursor starts after the text
that is programmatically inserted via setQueryText().
Manual tests:
-Type into search bar. Exit app. Resume app.
Open search bar again. Search bar should be empty.
-Type into search bar. Rotate app. Search bar shouldn't
be empty.
-Type into search bar. Close search. Open search.
The search view should be empty.
-execute "$ adb shell input keyboard text abcd". In KK
the search view will show "dabc". Now this shows "abcd".
-Place cursor in middle of a search term. Enter new text
using the soft keyboard or use adb shell to enter new text.
In both cases the new text appears after the cursor
position.
Bug: 18410365
Change-Id: I7ce260913e3c8e7448678bd2178859fb9c9270ab
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index 6a5c1cb..634f9ad 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -143,7 +143,7 @@
new OnClickListener() {
@Override
public void onClick(View v) {
- mSearchView.setText(null);
+ setQueryString(null);
}
});
mSearchContainer.findViewById(R.id.search_back_button).setOnClickListener(
@@ -254,9 +254,8 @@
}
if (mSearchMode) {
setFocusOnSearchView();
- } else {
- mSearchView.setText(null);
}
+ setQueryString(null);
} else if (flag) {
// Everything is already set up. Still make sure the keyboard is up
if (mSearchView != null) setFocusOnSearchView();
@@ -271,6 +270,10 @@
mQueryString = query;
if (mSearchView != null) {
mSearchView.setText(query);
+ // When programmatically entering text into the search view, the most reasonable
+ // place for the cursor is after all the text.
+ mSearchView.setSelection(mSearchView.getText() == null ?
+ 0 : mSearchView.getText().length());
}
}
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index ba77438..f7c2de2 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -1188,8 +1188,8 @@
&& !Character.isWhitespace(unicodeChar)) {
String query = new String(new int[]{ unicodeChar }, 0, 1);
if (!mActionBarAdapter.isSearchMode()) {
- mActionBarAdapter.setQueryString(query);
mActionBarAdapter.setSearchMode(true);
+ mActionBarAdapter.setQueryString(query);
return true;
}
}