/*
* Copyright (C) 2010 The Android Open Source Project
* Portions Copyright (c) 2013 CommonsWare, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.commonsware.cwac.preso;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
/**
* A mashup of a PresentationFragment with a WebViewFragment, for showing
* a WebView's contents on an external display.
*/
public class WebPresentationFragment extends PresentationFragment {
private WebView mWebView;
private boolean mIsWebViewAvailable;
/**
* {@inheritDoc}
*/
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
if (mWebView != null) {
mWebView.destroy();
}
mWebView=new WebView(getContext());
mIsWebViewAvailable=true;
return mWebView;
}
/**
* {@inheritDoc}
*/
@TargetApi(11)
@Override
public void onPause() {
super.onPause();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mWebView.onPause();
}
}
/**
* {@inheritDoc}
*/
@TargetApi(11)
@Override
public void onResume() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mWebView.onResume();
}
super.onResume();
}
/**
* {@inheritDoc}
*/
@Override
public void onDestroyView() {
mIsWebViewAvailable=false;
super.onDestroyView();
}
/**
* {@inheritDoc}
*/
@Override
public void onDestroy() {
if (mWebView != null) {
mWebView.destroy();
mWebView=null;
}
super.onDestroy();
}
/**
* Gets the WebView.
*/
public WebView getWebView() {
return mIsWebViewAvailable ? mWebView : null;
}
}