From c304b019551ccfe928983f3100eda8f9401495c6 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 12 Nov 2014 16:20:47 -0600 Subject: [PATCH] Use SearchView --- .../astrid/activity/TaskListActivity.java | 39 ++++++++++++------- .../src/main/res/menu/task_list_activity.xml | 4 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/astrid/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java index f8d216991..270a66e8c 100644 --- a/astrid/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java @@ -13,15 +13,16 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.speech.SpeechRecognizer; +import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; +import android.support.v7.widget.SearchView; import android.util.TypedValue; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.Toast; @@ -48,7 +49,6 @@ import com.todoroo.astrid.tags.TagFilterExposer; import com.todoroo.astrid.ui.QuickAddBar; import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Flags; -import com.todoroo.astrid.voice.RecognizerApi; import com.todoroo.astrid.voice.VoiceRecognizer; import org.tasks.R; @@ -113,16 +113,6 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList } Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER); - if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) { - String query = getIntent().getStringExtra(SearchManager.QUERY).trim(); - String title = getString(R.string.FLA_search_filter, query); - savedFilter = new Filter(title, title, - new QueryTemplate().where(Task.TITLE.like( - "%" + //$NON-NLS-1$ - query + "%")), //$NON-NLS-1$ - null); - } - if (savedFilter == null) { savedFilter = getDefaultFilter(); extras.putAll(configureIntentAndExtrasWithFilter(getIntent(), savedFilter)); @@ -168,6 +158,28 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList menu.findItem(R.id.menu_clear_completed).setVisible(true); menu.findItem(R.id.menu_sort).setVisible(false); } + final MenuItem item = menu.findItem(R.id.menu_search); + final SearchView actionView = (SearchView) MenuItemCompat.getActionView(item); + actionView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + query = query.trim(); + String title = getString(R.string.FLA_search_filter, query); + Filter savedFilter = new Filter(title, title, + new QueryTemplate().where(Task.TITLE.like( + "%" + //$NON-NLS-1$ + query + "%")), //$NON-NLS-1$ + null); + onFilterItemClicked(savedFilter); + MenuItemCompat.collapseActionView(item); + return true; + } + + @Override + public boolean onQueryTextChange(String query) { + return false; + } + }); return true; } @@ -459,9 +471,6 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList case R.id.menu_settings: tlf.showSettings(); return true; - case R.id.menu_search: - onSearchRequested(); - return true; case R.id.menu_sort: AlertDialog dialog = SortSelectionActivity.createDialog( this, tlf.hasDraggableOption(), tlf, tlf.getSortFlags(), tlf.getSort()); diff --git a/astrid/src/main/res/menu/task_list_activity.xml b/astrid/src/main/res/menu/task_list_activity.xml index ff4cd1e34..8f5d760e3 100644 --- a/astrid/src/main/res/menu/task_list_activity.xml +++ b/astrid/src/main/res/menu/task_list_activity.xml @@ -7,7 +7,9 @@ android:id="@+id/menu_search" android:title="@string/TLA_menu_search" android:icon="?attr/ic_action_search" - tasks:showAsAction="ifRoom" /> + tasks:showAsAction="ifRoom|collapseActionView" + tasks:actionViewClass="android.support.v7.widget.SearchView"/> +