Handle the voice search intent.
Once the voice search intent has been handled, the title bar
background changes to green, and touching it displays other voice
search possibilities.
Fixes http://b/issue?id=2390686
diff --git a/src/com/android/browser/BrowserProvider.java b/src/com/android/browser/BrowserProvider.java
index 4747721..bd6a723 100644
--- a/src/com/android/browser/BrowserProvider.java
+++ b/src/com/android/browser/BrowserProvider.java
@@ -53,6 +53,7 @@
import java.io.File;
import java.io.FilenameFilter;
+import java.util.ArrayList;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -718,16 +719,105 @@
}
}
+ private static class ResultsCursor extends AbstractCursor {
+ // Array indices for RESULTS_COLUMNS
+ private static final int RESULT_ACTION_ID = 1;
+ private static final int RESULT_DATA_ID = 2;
+ private static final int RESULT_TEXT_ID = 3;
+ private static final int RESULT_ICON_ID = 4;
+ private static final int RESULT_EXTRA_ID = 5;
+
+ private static final String[] RESULTS_COLUMNS = new String[] {
+ "_id",
+ SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
+ SearchManager.SUGGEST_COLUMN_INTENT_DATA,
+ SearchManager.SUGGEST_COLUMN_TEXT_1,
+ SearchManager.SUGGEST_COLUMN_ICON_1,
+ SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA
+ };
+ private final ArrayList<String> mResults;
+ public ResultsCursor(ArrayList<String> results) {
+ mResults = results;
+ }
+ public int getCount() { return mResults.size(); }
+
+ public String[] getColumnNames() {
+ return RESULTS_COLUMNS;
+ }
+
+ public String getString(int column) {
+ switch (column) {
+ case RESULT_ACTION_ID:
+ return Tab.VoiceSearchData.VOICE_SEARCH_RESULTS;
+ case RESULT_TEXT_ID:
+ // The data is used when the phone is in landscape mode. We
+ // still want to show the result string.
+ case RESULT_DATA_ID:
+ return mResults.get(mPos);
+ case RESULT_EXTRA_ID:
+ // The Intent's extra data will store the index into
+ // mResults so the BrowserActivity will know which result to
+ // use.
+ return Integer.toString(mPos);
+ case RESULT_ICON_ID:
+ return Integer.valueOf(R.drawable.magnifying_glass)
+ .toString();
+ default:
+ return null;
+ }
+ }
+ public short getShort(int column) {
+ throw new UnsupportedOperationException();
+ }
+ public int getInt(int column) {
+ throw new UnsupportedOperationException();
+ }
+ public long getLong(int column) {
+ if ((mPos != -1) && column == 0) {
+ return mPos; // use row# as the _id
+ }
+ throw new UnsupportedOperationException();
+ }
+ public float getFloat(int column) {
+ throw new UnsupportedOperationException();
+ }
+ public double getDouble(int column) {
+ throw new UnsupportedOperationException();
+ }
+ public boolean isNull(int column) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private ResultsCursor mResultsCursor;
+
+ /**
+ * Provide a set of results to be returned to query, intended to be used
+ * by the SearchDialog when the BrowserActivity is in voice search mode.
+ * @param results Strings to display in the dropdown from the SearchDialog
+ */
+ /* package */ void setQueryResults(ArrayList<String> results) {
+ if (results == null) {
+ mResultsCursor = null;
+ } else {
+ mResultsCursor = new ResultsCursor(results);
+ }
+ }
+
@Override
public Cursor query(Uri url, String[] projectionIn, String selection,
String[] selectionArgs, String sortOrder)
throws IllegalStateException {
- SQLiteDatabase db = mOpenHelper.getReadableDatabase();
-
int match = URI_MATCHER.match(url);
if (match == -1) {
throw new IllegalArgumentException("Unknown URL");
}
+ if (match == URI_MATCH_SUGGEST && mResultsCursor != null) {
+ Cursor results = mResultsCursor;
+ mResultsCursor = null;
+ return results;
+ }
+ SQLiteDatabase db = mOpenHelper.getReadableDatabase();
if (match == URI_MATCH_SUGGEST || match == URI_MATCH_BOOKMARKS_SUGGEST) {
String suggestSelection;