FileDocCategorySizeDatePackage
HTMLViewerActivity.javaAPI DocAndroid 1.5 API5614Wed May 06 22:42:46 BST 2009com.android.htmlviewer

HTMLViewerActivity

public class HTMLViewerActivity extends android.app.Activity
Wraps a WebView widget within an Activity. When launched, it uses the URI from the intent as the URL to load into the WebView. It supports all URLs schemes that a standard WebView supports, as well as loading the top level markup using the file scheme. The WebView default settings are used with the exception of normal layout is set. This activity shows a loading progress bar in the window title and sets the window title to the title of the content.

Fields Summary
private android.webkit.WebView
mWebView
static final int
MAXFILESIZE
static final String
LOGTAG
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle savedInstanceState)


    
        
        super.onCreate(savedInstanceState);

        // Call createInstance() explicitly. createInstance() is called in 
        // BrowserFrame by WebView. As it is called in WebCore thread, it can 
        // happen after onResume() is called. To use getInstance() in onResume,
        // createInstance() needs to be called first.
        CookieSyncManager.createInstance(this);

        requestWindowFeature(Window.FEATURE_PROGRESS);
        
        mWebView = new WebView(this);
        setContentView(mWebView);
        
        // Setup callback support for title and progress bar
        mWebView.setWebChromeClient( new WebChrome() );
        
        // Configure the webview
        WebSettings s = mWebView.getSettings();
        s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        s.setUseWideViewPort(true);
        s.setSavePassword(false);
        s.setSaveFormData(false);
        s.setBlockNetworkLoads(true);
        
        // Javascript is purposely disabled, so that nothing can be 
        // automatically run.
        s.setJavaScriptEnabled(false);
        
        // Restore a webview if we are meant to restore
        if (savedInstanceState != null) {
            mWebView.restoreState(savedInstanceState);
        } else {
            // Check the intent for the content to view
            Intent intent = getIntent();
            if (intent.getData() != null) {
                Uri uri = intent.getData();
                if ("file".equals(uri.getScheme())) {
                    String contentUri = 
                        FileContentProvider.BASE_URI + 
                        uri.getEncodedPath() + 
                        "?" +
                        intent.getType();
                    mWebView.loadUrl(contentUri);
                } else {
                    mWebView.loadUrl(intent.getData().toString() + 
                        "?" + intent.getType());
                }
            }
        }
    
protected voidonDestroy()

        super.onDestroy();
        mWebView.destroy();
    
protected voidonResume()

        super.onResume();
        CookieSyncManager.getInstance().startSync(); 
    
protected voidonSaveInstanceState(android.os.Bundle outState)

        // the default implementation requires each view to have an id. As the
        // browser handles the state itself and it doesn't use id for the views,
        // don't call the default implementation. Otherwise it will trigger the
        // warning like this, "couldn't save which view has focus because the 
        // focused view XXX has no id".
        mWebView.saveState(outState);
    
protected voidonStop()

        super.onStop();
        
        CookieSyncManager.getInstance().stopSync(); 
        mWebView.stopLoading();