michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.sync.setup.activities; michael@0: michael@0: import org.mozilla.gecko.R; michael@0: import org.mozilla.gecko.background.common.log.Logger; michael@0: michael@0: import android.app.Activity; michael@0: import android.net.Uri; michael@0: import android.os.Bundle; michael@0: import android.view.Window; michael@0: import android.webkit.WebChromeClient; michael@0: import android.webkit.WebView; michael@0: import android.webkit.WebViewClient; michael@0: michael@0: /** michael@0: * Displays URI in an embedded WebView. Closes if there no URI is passed in. michael@0: * @author liuche michael@0: * michael@0: */ michael@0: public class WebViewActivity extends SyncActivity { michael@0: private final static String LOG_TAG = "WebViewActivity"; michael@0: michael@0: @Override michael@0: public void onCreate(Bundle savedInstanceState) { michael@0: super.onCreate(savedInstanceState); michael@0: getWindow().requestFeature(Window.FEATURE_PROGRESS); michael@0: setContentView(R.layout.sync_setup_webview); michael@0: // Extract URI to launch from Intent. michael@0: Uri uri = this.getIntent().getData(); michael@0: if (uri == null) { michael@0: Logger.debug(LOG_TAG, "No URI passed to display."); michael@0: finish(); michael@0: return; michael@0: } michael@0: michael@0: WebView wv = (WebView) findViewById(R.id.web_engine); michael@0: // Add a progress bar. michael@0: final Activity activity = this; michael@0: wv.setWebChromeClient(new WebChromeClient() { michael@0: @Override michael@0: public void onProgressChanged(WebView view, int progress) { michael@0: // Activities and WebViews measure progress with different scales. michael@0: // The progress meter will automatically disappear when we reach 100% michael@0: activity.setProgress(progress * 100); michael@0: } michael@0: }); michael@0: wv.setWebViewClient(new WebViewClient() { michael@0: // Handle url loading in this WebView, instead of asking the ActivityManager. michael@0: @Override michael@0: public boolean shouldOverrideUrlLoading(WebView view, String url) { michael@0: view.loadUrl(url); michael@0: return false; michael@0: } michael@0: }); michael@0: wv.loadUrl(uri.toString()); michael@0: michael@0: } michael@0: }