diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2014-05-23 16:03:43 -0700 |
---|---|---|
committer | Fabrice Di Meglio <fdimeglio@google.com> | 2014-05-23 16:09:53 -0700 |
commit | 7e4855e8f644bdecf68ec65b8c1b7c08624a4876 (patch) | |
tree | c514f2ef7245b32b09718d8fcd0793fd0f24353f /src/com/android/settings/dashboard | |
parent | 2416a3e071785241c15463b20d1d34001ba931af (diff) | |
download | packages_apps_Settings-7e4855e8f644bdecf68ec65b8c1b7c08624a4876.zip packages_apps_Settings-7e4855e8f644bdecf68ec65b8c1b7c08624a4876.tar.gz packages_apps_Settings-7e4855e8f644bdecf68ec65b8c1b7c08624a4876.tar.bz2 |
Update Search recents behavior
- per UX request
- Search recents show now by defaults with the recent searches
when the SearchView is empty
- when we press on a Serach recent, we are showing the Search results
and the recents are disappearing
- when keying text in the SearchView, we hide the recents and start
showing the results
- we still save the Search query when hitting on a result
Change-Id: I6c2be21660a30f6973dea27d4852b2068a05963d
Diffstat (limited to 'src/com/android/settings/dashboard')
-rw-r--r-- | src/com/android/settings/dashboard/SearchResultsSummary.java | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/src/com/android/settings/dashboard/SearchResultsSummary.java b/src/com/android/settings/dashboard/SearchResultsSummary.java index 862b53b..1bd0bf0 100644 --- a/src/com/android/settings/dashboard/SearchResultsSummary.java +++ b/src/com/android/settings/dashboard/SearchResultsSummary.java @@ -51,7 +51,7 @@ public class SearchResultsSummary extends Fragment { private static final String EMPTY_QUERY = ""; private static char ELLIPSIS = '\u2026'; - private static final String SAVE_KEY_SHOW_ONLY_RESULTS = ":settings:show_only_results"; + private static final String SAVE_KEY_SHOW_RESULTS = ":settings:show_results"; private SearchView mSearchView; @@ -68,7 +68,7 @@ public class SearchResultsSummary extends Fragment { private String mQuery; - private boolean mShowOnlyResults; + private boolean mShowResults; /** * A basic AsyncTask for updating the query results cursor @@ -83,6 +83,7 @@ public class SearchResultsSummary extends Fragment { protected void onPostExecute(Cursor cursor) { if (!isCancelled()) { setResultsCursor(cursor); + setResultsVisibility(cursor.getCount() > 0); } else if (cursor != null) { cursor.close(); } @@ -102,6 +103,7 @@ public class SearchResultsSummary extends Fragment { protected void onPostExecute(Cursor cursor) { if (!isCancelled()) { setSuggestionsCursor(cursor); + setSuggestionsVisibility(cursor.getCount() > 0); } else if (cursor != null) { cursor.close(); } @@ -116,7 +118,7 @@ public class SearchResultsSummary extends Fragment { mSuggestionsAdapter = new SuggestionsAdapter(getActivity()); if (savedInstanceState != null) { - mShowOnlyResults = savedInstanceState.getBoolean(SAVE_KEY_SHOW_ONLY_RESULTS); + mShowResults = savedInstanceState.getBoolean(SAVE_KEY_SHOW_RESULTS); } } @@ -124,7 +126,7 @@ public class SearchResultsSummary extends Fragment { public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putBoolean(SAVE_KEY_SHOW_ONLY_RESULTS, mShowOnlyResults); + outState.putBoolean(SAVE_KEY_SHOW_RESULTS, mShowResults); } @Override @@ -209,10 +211,9 @@ public class SearchResultsSummary extends Fragment { final Cursor cursor = mSuggestionsAdapter.mCursor; cursor.moveToPosition(position); + mShowResults = true; mQuery = cursor.getString(0); mSearchView.setQuery(mQuery, false); - setSuggestionsVisibility(false); - mShowOnlyResults = true; } }); @@ -220,10 +221,10 @@ public class SearchResultsSummary extends Fragment { } @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); + public void onResume() { + super.onResume(); - if (!mShowOnlyResults) { + if (!mShowResults) { showSomeSuggestions(); } } @@ -250,31 +251,28 @@ public class SearchResultsSummary extends Fragment { public boolean onQueryTextSubmit(String query) { mQuery = getFilteredQueryString(query); - setSuggestionsVisibility(!mShowOnlyResults); + mShowResults = true; + setSuggestionsVisibility(false); updateSearchResults(); + saveQueryToDatabase(); return true; } public boolean onQueryTextChange(String query) { final String newQuery = getFilteredQueryString(query); - boolean isNewQuery; - if (!TextUtils.isEmpty(mQuery)) { - isNewQuery = !mQuery.equals(query); - } else { - isNewQuery = !TextUtils.isEmpty(query); - } - mQuery = newQuery; - if (isNewQuery) { - mShowOnlyResults = false; - } - if (!mShowOnlyResults) { + if (TextUtils.isEmpty(mQuery)) { + mShowResults = false; + setResultsVisibility(false); updateSuggestions(); + } else { + mShowResults = true; + setSuggestionsVisibility(false); + updateSearchResults(); } - updateSearchResults(); return true; } @@ -335,30 +333,33 @@ public class SearchResultsSummary extends Fragment { return filtered.toString(); } - private void updateSuggestions() { + private void clearAllTasks() { + if (mUpdateSearchResultsTask != null) { + mUpdateSearchResultsTask.cancel(false); + mUpdateSearchResultsTask = null; + } if (mUpdateSuggestionsTask != null) { mUpdateSuggestionsTask.cancel(false); mUpdateSuggestionsTask = null; } + } + + private void updateSuggestions() { + clearAllTasks(); if (mQuery == null) { setSuggestionsCursor(null); } else { - setSuggestionsVisibility(true); mUpdateSuggestionsTask = new UpdateSuggestionsTask(); mUpdateSuggestionsTask.execute(mQuery); } } private void updateSearchResults() { - if (mUpdateSearchResultsTask != null) { - mUpdateSearchResultsTask.cancel(false); - mUpdateSearchResultsTask = null; - } + clearAllTasks(); if (TextUtils.isEmpty(mQuery)) { setResultsVisibility(false); setResultsCursor(null); } else { - setResultsVisibility(true); mUpdateSearchResultsTask = new UpdateSearchResultsTask(); mUpdateSearchResultsTask.execute(mQuery); } |