From ea56be33817a537b8b318ce5930f1fe0e0f11ab2 Mon Sep 17 00:00:00 2001 From: Eric Edens Date: Fri, 25 Jul 2014 08:58:50 -0700 Subject: [PATCH] Bug 1042937 - Provide visual feedback while search results are loading. r=margaret --- .../mozilla/search/PostSearchFragment.java | 36 ++++++++++++++++--- .../search/res/drawable/progressbar.xml | 9 +++++ .../layout/search_fragment_post_search.xml | 19 ++++++++-- .../search/res/values/search_dimens.xml | 1 + 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 mobile/android/search/res/drawable/progressbar.xml diff --git a/mobile/android/search/java/org/mozilla/search/PostSearchFragment.java b/mobile/android/search/java/org/mozilla/search/PostSearchFragment.java index 93d4fd4f894a..136d20c3cba1 100644 --- a/mobile/android/search/java/org/mozilla/search/PostSearchFragment.java +++ b/mobile/android/search/java/org/mozilla/search/PostSearchFragment.java @@ -15,10 +15,13 @@ import android.view.ViewGroup; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.ProgressBar; public class PostSearchFragment extends Fragment { private static final String LOGTAG = "PostSearchFragment"; + + private ProgressBar progressBar; private WebView webview; private static final String HIDE_BANNER_SCRIPT = "javascript:(function(){var tag=document.createElement('style');" + @@ -30,15 +33,26 @@ public class PostSearchFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - webview = (WebView) inflater.inflate(R.layout.search_fragment_post_search, container, false); + View mainView = inflater.inflate(R.layout.search_fragment_post_search, container, false); + progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar); + + webview = (WebView) mainView.findViewById(R.id.webview); + webview.setWebChromeClient(new ChromeClient()); webview.setWebViewClient(new LinkInterceptingClient()); - webview.setWebChromeClient(new StyleInjectingClient()); - // This is required for our greasemonkey terror script. webview.getSettings().setJavaScriptEnabled(true); - return webview; + return mainView; + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + webview.setWebChromeClient(null); + webview.setWebViewClient(null); + webview = null; + progressBar = null; } /** @@ -90,12 +104,24 @@ public class PostSearchFragment extends Fragment { * event. Once the title is available, the page will have started parsing the * head element. The script injects its CSS into the head element. */ - private class StyleInjectingClient extends WebChromeClient { + private class ChromeClient extends WebChromeClient { @Override public void onReceivedTitle(WebView view, String title) { super.onReceivedTitle(view, title); view.loadUrl(HIDE_BANNER_SCRIPT); } + + @Override + public void onProgressChanged(WebView view, int newProgress) { + if (newProgress < 100) { + if (progressBar.getVisibility() == View.INVISIBLE) { + progressBar.setVisibility(View.VISIBLE); + } + progressBar.setProgress(newProgress); + } else { + progressBar.setVisibility(View.INVISIBLE); + } + } } } diff --git a/mobile/android/search/res/drawable/progressbar.xml b/mobile/android/search/res/drawable/progressbar.xml new file mode 100644 index 000000000000..e66a23f5defa --- /dev/null +++ b/mobile/android/search/res/drawable/progressbar.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/mobile/android/search/res/layout/search_fragment_post_search.xml b/mobile/android/search/res/layout/search_fragment_post_search.xml index b47f884a8c93..72f1ab08bac3 100644 --- a/mobile/android/search/res/layout/search_fragment_post_search.xml +++ b/mobile/android/search/res/layout/search_fragment_post_search.xml @@ -2,7 +2,22 @@ - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - + android:layout_height="match_parent" + android:orientation="vertical"> + + + + + + diff --git a/mobile/android/search/res/values/search_dimens.xml b/mobile/android/search/res/values/search_dimens.xml index f66e892e4777..63e9ba227925 100644 --- a/mobile/android/search/res/values/search_dimens.xml +++ b/mobile/android/search/res/values/search_dimens.xml @@ -6,6 +6,7 @@ 65dp + 3dp 15dp