Steve Block | 1916e7f | 2010-12-16 17:40:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.webkit; |
| 18 | |
| 19 | import android.app.Fragment; |
| 20 | import android.os.Bundle; |
| 21 | import android.view.LayoutInflater; |
| 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
| 24 | import android.webkit.WebView; |
| 25 | |
| 26 | /** |
| 27 | * A fragment that displays a WebView. |
| 28 | * <p> |
| 29 | * The WebView is automically paused or resumed when the Fragment is paused or resumed. |
| 30 | */ |
| 31 | public class WebViewFragment extends Fragment { |
| 32 | private WebView mWebView; |
| 33 | |
| 34 | public WebViewFragment() { |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Called to instantiate the view. Creates and returns the WebView. |
| 39 | */ |
| 40 | @Override |
| 41 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 42 | Bundle savedInstanceState) { |
| 43 | mWebView = new WebView(getActivity()); |
| 44 | return mWebView; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Called when the fragment is visible to the user and actively running. Resumes the WebView. |
| 49 | */ |
| 50 | @Override |
| 51 | public void onPause() { |
| 52 | super.onPause(); |
| 53 | mWebView.onPause(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Called when the fragment is no longer resumed. Pauses the WebView. |
| 58 | */ |
| 59 | @Override |
| 60 | public void onResume() { |
| 61 | mWebView.onResume(); |
| 62 | super.onResume(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Called when the view has been detached from the fragment. Destroys the WebView. |
| 67 | */ |
| 68 | @Override |
| 69 | public void onDestroyView() { |
| 70 | mWebView.destroy(); |
| 71 | mWebView = null; |
| 72 | super.onDestroyView(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Gets the WebView. |
| 77 | */ |
| 78 | public WebView getWebView() { |
| 79 | return mWebView; |
| 80 | } |
| 81 | } |