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
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 *
31 * @deprecated Manually call {@link WebView#onPause()} and {@link WebView#onResume()}
32 */
33@Deprecated
34public class WebViewFragment extends Fragment {
35    private WebView mWebView;
36    private boolean mIsWebViewAvailable;
37
38    public WebViewFragment() {
39    }
40
41    /**
42     * Called to instantiate the view. Creates and returns the WebView.
43     */
44    @Override
45    public View onCreateView(LayoutInflater inflater, ViewGroup container,
46            Bundle savedInstanceState) {
47        if (mWebView != null) {
48            mWebView.destroy();
49        }
50        mWebView = new WebView(getContext());
51        mIsWebViewAvailable = true;
52        return mWebView;
53    }
54
55    /**
56     * Called when the fragment is visible to the user and actively running. Resumes the WebView.
57     */
58    @Override
59    public void onPause() {
60        super.onPause();
61        mWebView.onPause();
62    }
63
64    /**
65     * Called when the fragment is no longer resumed. Pauses the WebView.
66     */
67    @Override
68    public void onResume() {
69        mWebView.onResume();
70        super.onResume();
71    }
72
73    /**
74     * Called when the WebView has been detached from the fragment.
75     * The WebView is no longer available after this time.
76     */
77    @Override
78    public void onDestroyView() {
79        mIsWebViewAvailable = false;
80        super.onDestroyView();
81    }
82
83    /**
84     * Called when the fragment is no longer in use. Destroys the internal state of the WebView.
85     */
86    @Override
87    public void onDestroy() {
88        if (mWebView != null) {
89            mWebView.destroy();
90            mWebView = null;
91        }
92        super.onDestroy();
93    }
94
95    /**
96     * Gets the WebView.
97     */
98    public WebView getWebView() {
99        return mIsWebViewAvailable ? mWebView : null;
100    }
101}
102