summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kolb <kolby@google.com>2011-01-13 13:01:30 -0800
committerMichael Kolb <kolby@google.com>2011-01-13 13:25:26 -0800
commitbd2dd64dda88ca8a7c2b148d88c5a44e73e1c331 (patch)
tree21169bf65a34c096df1545a9925ad99e6e224f22
parent1e1a9684e8ea75f8cdfd1ef94f67971b31988cdf (diff)
downloadpackages_apps_Browser-bd2dd64dda88ca8a7c2b148d88c5a44e73e1c331.zip
packages_apps_Browser-bd2dd64dda88ca8a7c2b148d88c5a44e73e1c331.tar.gz
packages_apps_Browser-bd2dd64dda88ca8a7c2b148d88c5a44e73e1c331.tar.bz2
fix voice search suggestions
http://b/issue?id=3348242 In voice search mode, make sure the suggestions are routed via tab's activateVoiceSearch Change-Id: I464f186510047a1d2b0d6b2be7809ec66ec74b22
-rw-r--r--src/com/android/browser/SuggestionsAdapter.java25
-rw-r--r--src/com/android/browser/TitleBarXLarge.java10
-rw-r--r--src/com/android/browser/UrlInputView.java20
3 files changed, 32 insertions, 23 deletions
diff --git a/src/com/android/browser/SuggestionsAdapter.java b/src/com/android/browser/SuggestionsAdapter.java
index e2d9386..029877c 100644
--- a/src/com/android/browser/SuggestionsAdapter.java
+++ b/src/com/android/browser/SuggestionsAdapter.java
@@ -25,6 +25,7 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.provider.BrowserContract;
import android.text.TextUtils;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -41,13 +42,15 @@ import java.util.List;
/**
* adapter to wrap multiple cursors for url/search completions
*/
-public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnClickListener {
+public class SuggestionsAdapter extends BaseAdapter implements Filterable,
+ OnClickListener {
static final int TYPE_BOOKMARK = 0;
static final int TYPE_SUGGEST_URL = 1;
static final int TYPE_HISTORY = 2;
static final int TYPE_SEARCH = 3;
static final int TYPE_SUGGEST = 4;
+ static final int TYPE_VOICE_SEARCH = 5;
private static final String[] COMBINED_PROJECTION =
{BrowserContract.Combined._ID, BrowserContract.Combined.TITLE,
@@ -73,7 +76,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli
public void onSearch(String txt);
- public void onSelect(String txt, String extraData);
+ public void onSelect(String txt, int type, String extraData);
public void onFilterComplete(int count);
@@ -114,8 +117,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli
// replace input field text with suggestion text
mListener.onSearch(item.title);
} else {
- mListener.onSelect((TextUtils.isEmpty(item.url)? item.title : item.url),
- item.extra);
+ mListener.onSelect(
+ (TextUtils.isEmpty(item.url)? item.title : item.url),
+ item.type, item.extra);
}
}
@@ -138,8 +142,10 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli
position = (getCount() - 1) - position;
}
if (mVoiceResults != null) {
- return new SuggestItem(mVoiceResults.get(position), null,
- TYPE_SEARCH);
+ SuggestItem item = new SuggestItem(mVoiceResults.get(position),
+ null, TYPE_VOICE_SEARCH);
+ item.extra = Integer.toString(position);
+ return item;
}
if (mMixedResults == null) {
return null;
@@ -186,6 +192,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli
switch (item.type) {
case TYPE_SUGGEST:
case TYPE_SEARCH:
+ case TYPE_VOICE_SEARCH:
id = R.drawable.ic_search_category_suggest;
break;
case TYPE_BOOKMARK:
@@ -203,7 +210,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli
if (id != -1) {
ic1.setImageDrawable(mContext.getResources().getDrawable(id));
}
- ic2.setVisibility(((TYPE_SUGGEST == item.type) || (TYPE_SEARCH == item.type))
+ ic2.setVisibility(((TYPE_SUGGEST == item.type)
+ || (TYPE_SEARCH == item.type)
+ || (TYPE_VOICE_SEARCH == item.type))
? View.VISIBLE : View.GONE);
div.setVisibility(ic2.getVisibility());
ic2.setOnClickListener(this);
@@ -298,6 +307,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli
res.count = mixed.getLineCount();
res.values = mixed;
} else {
+ Log.i("voice", "using voice results");
res.count = mVoiceResults.size();
res.values = mVoiceResults;
}
@@ -396,6 +406,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli
url = u;
type = t;
}
+
}
abstract class CursorSource {
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 8be4df5..b5a8032 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -27,6 +27,7 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.speech.RecognizerResultsIntent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@@ -268,7 +269,14 @@ public class TitleBarXLarge extends TitleBarBase
mUiController.getCurrentTopWebView().requestFocus();
mUi.hideFakeTitleBar();
Intent i = new Intent();
- i.setAction(Intent.ACTION_SEARCH);
+ String action = null;
+ if (UrlInputView.VOICE.equals(source)) {
+ action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
+ source = null;
+ } else {
+ action = Intent.ACTION_SEARCH;
+ }
+ i.setAction(action);
i.putExtra(SearchManager.QUERY, text);
if (extra != null) {
i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
diff --git a/src/com/android/browser/UrlInputView.java b/src/com/android/browser/UrlInputView.java
index 428a0f2..7dc2ed4 100644
--- a/src/com/android/browser/UrlInputView.java
+++ b/src/com/android/browser/UrlInputView.java
@@ -17,7 +17,6 @@
package com.android.browser;
import com.android.browser.SuggestionsAdapter.CompletionListener;
-import com.android.browser.SuggestionsAdapter.SuggestItem;
import android.content.Context;
import android.content.res.Configuration;
@@ -27,8 +26,6 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.InputMethodManager;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
@@ -41,11 +38,12 @@ import java.util.List;
*/
public class UrlInputView extends AutoCompleteTextView
implements OnFocusChangeListener, OnEditorActionListener,
- CompletionListener, OnItemClickListener {
+ CompletionListener {
static final String TYPED = "browser-type";
static final String SUGGESTED = "browser-suggest";
+ static final String VOICE = "voice-search";
private UrlInputListener mListener;
private InputMethodManager mInputManager;
@@ -79,7 +77,6 @@ public class UrlInputView extends AutoCompleteTextView
setSelectAllOnFocus(true);
onConfigurationChanged(ctx.getResources().getConfiguration());
setThreshold(1);
- setOnItemClickListener(this);
}
void setController(UiController controller) {
@@ -185,8 +182,9 @@ public class UrlInputView extends AutoCompleteTextView
}
@Override
- public void onSelect(String url, String extra) {
- finishInput(url, extra, SUGGESTED);
+ public void onSelect(String url, int type, String extra) {
+ finishInput(url, extra, (type == SuggestionsAdapter.TYPE_VOICE_SEARCH)
+ ? VOICE : SUGGESTED);
}
@Override
@@ -209,14 +207,6 @@ public class UrlInputView extends AutoCompleteTextView
}
- @Override
- public void onItemClick(
- AdapterView<?> parent, View view, int position, long id) {
- SuggestItem item = mAdapter.getItem(position);
- onSelect((TextUtils.isEmpty(item.url) ? item.title : item.url),
- item.extra);
- }
-
public void setReverseResults(boolean reverse) {
mAdapter.setReverseResults(reverse);
}