blob: 466f1740b19037fb8d8b9bb56a5002f7dc4ad144 [file] [log] [blame]
Steve Block1916e7f2010-12-16 17:40:05 +00001/*
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
17package android.webkit;
18
19import android.app.Fragment;
20import android.os.Bundle;
21import android.view.LayoutInflater;
22import android.view.View;
23import android.view.ViewGroup;
24import 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 */
31public 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}