mobile/android/base/sync/setup/activities/WebViewActivity.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/sync/setup/activities/WebViewActivity.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.sync.setup.activities;
     1.9 +
    1.10 +import org.mozilla.gecko.R;
    1.11 +import org.mozilla.gecko.background.common.log.Logger;
    1.12 +
    1.13 +import android.app.Activity;
    1.14 +import android.net.Uri;
    1.15 +import android.os.Bundle;
    1.16 +import android.view.Window;
    1.17 +import android.webkit.WebChromeClient;
    1.18 +import android.webkit.WebView;
    1.19 +import android.webkit.WebViewClient;
    1.20 +
    1.21 +/**
    1.22 + * Displays URI in an embedded WebView. Closes if there no URI is passed in.
    1.23 + * @author liuche
    1.24 + *
    1.25 + */
    1.26 +public class WebViewActivity extends SyncActivity {
    1.27 +  private final static String LOG_TAG = "WebViewActivity";
    1.28 +
    1.29 +  @Override
    1.30 +  public void onCreate(Bundle savedInstanceState) {
    1.31 +    super.onCreate(savedInstanceState);
    1.32 +    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    1.33 +    setContentView(R.layout.sync_setup_webview);
    1.34 +    // Extract URI to launch from Intent.
    1.35 +    Uri uri = this.getIntent().getData();
    1.36 +    if (uri == null) {
    1.37 +      Logger.debug(LOG_TAG, "No URI passed to display.");
    1.38 +      finish();
    1.39 +      return;
    1.40 +    }
    1.41 +
    1.42 +    WebView wv = (WebView) findViewById(R.id.web_engine);
    1.43 +    // Add a progress bar.
    1.44 +    final Activity activity = this;
    1.45 +    wv.setWebChromeClient(new WebChromeClient() {
    1.46 +      @Override
    1.47 +      public void onProgressChanged(WebView view, int progress) {
    1.48 +        // Activities and WebViews measure progress with different scales.
    1.49 +        // The progress meter will automatically disappear when we reach 100%
    1.50 +        activity.setProgress(progress * 100);
    1.51 +      }
    1.52 +    });
    1.53 +    wv.setWebViewClient(new WebViewClient() {
    1.54 +      // Handle url loading in this WebView, instead of asking the ActivityManager.
    1.55 +      @Override
    1.56 +      public boolean shouldOverrideUrlLoading(WebView view, String url) {
    1.57 +        view.loadUrl(url);
    1.58 +        return false;
    1.59 +      }
    1.60 +    });
    1.61 +    wv.loadUrl(uri.toString());
    1.62 +
    1.63 +  }
    1.64 +}

mercurial