Bug 1042937 - Provide visual feedback while search results are loading. r=margaret

This commit is contained in:
Eric Edens 2014-07-25 08:58:50 -07:00
Родитель 7632df5247
Коммит ea56be3381
4 изменённых файлов: 58 добавлений и 7 удалений

Просмотреть файл

@ -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);
}
}
}
}

Просмотреть файл

@ -0,0 +1,9 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="@color/highlight_orange"/>
</shape>
</clip>
</item>
</layer-list>

Просмотреть файл

@ -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/. -->
<WebView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progress_bar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="@dimen/progress_bar_height"
android:progressDrawable="@drawable/progressbar"/>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

Просмотреть файл

@ -6,6 +6,7 @@
<!-- The height of the search bar is also used to offset the PreSearchFragment
and PostSearchFragment contents -->
<dimen name="search_bar_height">65dp</dimen>
<dimen name="progress_bar_height">3dp</dimen>
<!-- We use background padding to create space around the cards -->
<dimen name="card_background_padding_x">15dp</dimen>