diff --git a/src/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryService.java b/src/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryService.java index c3e4a79..0ac858a 100644 --- a/src/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryService.java +++ b/src/pedals/is/floatingjapanesedictionary/FloatingJapaneseDictionaryService.java @@ -25,6 +25,7 @@ import pedals.is.floatingjapanesedictionary.dictionarysearcher.DictionaryEntries; import pedals.is.floatingjapanesedictionary.dictionarysearcher.DictionaryEntry; +import pedals.is.floatingjapanesedictionary.dictionarysearcher.DictionarySearcherActivity; import pedals.is.floatingjapanesedictionary.downloader.DictionaryManagerService; import android.annotation.TargetApi; import android.app.SearchManager; @@ -51,6 +52,7 @@ public class FloatingJapaneseDictionaryService extends StandOutWindow { public static final int DISPLAY_TEXT = 0, DISPLAY_DEFINITION = 1, DISPLAY_SEARCH = 2; + public static final String SUBMITTED = "SUBMITTED"; private static final String APP_NAME = "Floating Japanese Dictionary"; private static final int APP_ICON = android.R.drawable.ic_menu_add; @@ -123,6 +125,39 @@ public boolean onClose() { } }); + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + + @Override + public boolean onQueryTextSubmit(String query) { + + return false; + } + + @Override + public boolean onQueryTextChange(String query) { + + Intent intent = new Intent( + FloatingJapaneseDictionaryService.this, + DictionarySearcherActivity.class); + intent.setAction(Intent.ACTION_SEARCH); + intent.putExtra(SearchManager.QUERY, query); + intent.putExtra(SUBMITTED, false); + /* + * SearchView itself launches the activity with + * FLAG_ACTIVITY_NEW_TASK. + * + * Because multiple instances of the activity will be fired + * rapidly, FLAG_ACTIVITY_CLEAR_TOP will either start the + * activity, or kill the activity if it is running and start it + * again. + */ + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP + | Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + return true; + } + }); + searchView.setOnSearchClickListener(new View.OnClickListener() { @Override diff --git a/src/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionarySearcherActivity.java b/src/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionarySearcherActivity.java index 2be4f97..b3cca1b 100644 --- a/src/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionarySearcherActivity.java +++ b/src/pedals/is/floatingjapanesedictionary/dictionarysearcher/DictionarySearcherActivity.java @@ -35,7 +35,17 @@ public void onCreate(Bundle savedInstanceState) { Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); - displaySearch(query); + + /* + * If the flag isn't set, it means that we can freely update the + * textfield without worrying about disturbing search on type ime + * composition. We need to update the textfield when a voice search + * occurs so that the user knows what the query was recognized as. + */ + if (intent.getBooleanExtra( + FloatingJapaneseDictionaryService.SUBMITTED, true)) { + displaySearch(query); + } DictionaryEntries result = doQuery(query); if (result.isEmpty()) { displayText("No results");