From 82c1baa16a66eabdd7fd1eb6569e61cb6caac4fd Mon Sep 17 00:00:00 2001 From: Leon Scroggins Date: Tue, 2 Feb 2010 16:10:57 -0500 Subject: [PATCH] Handle voice search it provides html content to display. Fix for http://b/issue?id=2407710 --- src/com/android/browser/Tab.java | 88 ++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index c939a13..b434a5d 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -173,47 +173,86 @@ class Tab { * results when reusing the old results. */ /* package */ void activateVoiceSearchMode(Intent intent) { + int index = 0; ArrayList results = intent.getStringArrayListExtra( RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_STRINGS); - ArrayList urls = intent.getStringArrayListExtra( - RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_URLS); if (results != null) { + ArrayList urls = intent.getStringArrayListExtra( + RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_URLS); + ArrayList htmls = intent.getStringArrayListExtra( + RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_HTML); + ArrayList baseUrls = intent.getStringArrayListExtra( + RecognizerResultsIntent + .EXTRA_VOICE_SEARCH_RESULT_HTML_BASE_URLS); // This tab is now entering voice search mode for the first time, or // a new voice search was done. - if (urls == null || results.size() != urls.size()) { + int size = results.size(); + if (urls == null || size != urls.size()) { throw new AssertionError("improper extras passed in Intent"); } - mVoiceSearchData = new VoiceSearchData(results, urls); + if (htmls == null || htmls.size() != size || baseUrls == null || + (baseUrls.size() != size && baseUrls.size() != 1)) { + // If either of these arrays are empty/incorrectly sized, ignore + // them. + htmls = null; + baseUrls = null; + } + mVoiceSearchData = new VoiceSearchData(results, urls, htmls, + baseUrls); } else { String extraData = intent.getStringExtra( SearchManager.EXTRA_DATA_KEY); if (extraData != null) { - mVoiceSearchData.mLastVoiceSearchIndex - = Integer.parseInt(extraData); - if (mVoiceSearchData.mLastVoiceSearchIndex - >= mVoiceSearchData.mVoiceSearchResults.size()) { + index = Integer.parseInt(extraData); + if (index >= mVoiceSearchData.mVoiceSearchResults.size()) { throw new AssertionError("index must be less than " + " size of mVoiceSearchResults"); } } } mVoiceSearchData.mLastVoiceSearchTitle - = mVoiceSearchData.mVoiceSearchResults.get(mVoiceSearchData. - mLastVoiceSearchIndex); + = mVoiceSearchData.mVoiceSearchResults.get(index); if (mInForeground) { mActivity.showVoiceTitleBar(mVoiceSearchData.mLastVoiceSearchTitle); } + if (mVoiceSearchData.mVoiceSearchHtmls != null) { + // When index was found it was already ensured that it was valid + String uriString = mVoiceSearchData.mVoiceSearchHtmls.get(index); + if (uriString != null) { + Uri dataUri = Uri.parse(uriString); + if (RecognizerResultsIntent.URI_SCHEME_INLINE.equals( + dataUri.getScheme())) { + // If there is only one base URL, use it. If there are + // more, there will be one for each index, so use the base + // URL corresponding to the index. + String baseUrl = mVoiceSearchData.mVoiceSearchBaseUrls.get( + mVoiceSearchData.mVoiceSearchBaseUrls.size() > 1 ? + index : 0); + mVoiceSearchData.mLastVoiceSearchUrl = baseUrl; + mMainView.loadDataWithBaseURL(baseUrl, + uriString.substring(RecognizerResultsIntent + .URI_SCHEME_INLINE.length() + 1), "text/html", + "utf-8", baseUrl); + return; + } + } + } mVoiceSearchData.mLastVoiceSearchUrl - = mVoiceSearchData.mVoiceSearchUrls.get(mVoiceSearchData. - mLastVoiceSearchIndex); + = mVoiceSearchData.mVoiceSearchUrls.get(index); + if (null == mVoiceSearchData.mLastVoiceSearchUrl) { + mVoiceSearchData.mLastVoiceSearchUrl = mActivity.smartUrlFilter( + mVoiceSearchData.mLastVoiceSearchTitle); + } mMainView.loadUrl(mVoiceSearchData.mLastVoiceSearchUrl); } /* package */ static class VoiceSearchData { public VoiceSearchData(ArrayList results, - ArrayList urls) { + ArrayList urls, ArrayList htmls, + ArrayList baseUrls) { mVoiceSearchResults = results; mVoiceSearchUrls = urls; - mLastVoiceSearchIndex = 0; + mVoiceSearchHtmls = htmls; + mVoiceSearchBaseUrls = baseUrls; } /* * ArrayList of suggestions to be displayed when opening the @@ -226,9 +265,20 @@ class Tab { */ public ArrayList mVoiceSearchUrls; /* + * ArrayList holding content to load for each item in + * mVoiceSearchResults. + */ + public ArrayList mVoiceSearchHtmls; + /* + * ArrayList holding base urls for the items in mVoiceSearchResults. + * If non null, this will either have the same size as + * mVoiceSearchResults or have a size of 1, in which case all will use + * the same base url + */ + public ArrayList mVoiceSearchBaseUrls; + /* * The last url provided by voice search. Used for comparison to see if - * we are going to a page by some method besides voice search. Only - * meaningful in voice search mode. + * we are going to a page by some method besides voice search. */ public String mLastVoiceSearchUrl; /** @@ -236,12 +286,6 @@ class Tab { * when switching tabs. */ public String mLastVoiceSearchTitle; - /* - * The index into mVoiceSearchResults and mVoiceSearchUrls of the last - * voice search performed. Stored so it can be used to index into - * mVoiceSearchUrls to determine the url in getUrlDataFromIntent. - */ - public int mLastVoiceSearchIndex; } // Container class for the next error dialog that needs to be displayed -- 2.11.0