Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.sync.setup.activities; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.R; |
michael@0 | 8 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 9 | |
michael@0 | 10 | import android.app.Activity; |
michael@0 | 11 | import android.net.Uri; |
michael@0 | 12 | import android.os.Bundle; |
michael@0 | 13 | import android.view.Window; |
michael@0 | 14 | import android.webkit.WebChromeClient; |
michael@0 | 15 | import android.webkit.WebView; |
michael@0 | 16 | import android.webkit.WebViewClient; |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * Displays URI in an embedded WebView. Closes if there no URI is passed in. |
michael@0 | 20 | * @author liuche |
michael@0 | 21 | * |
michael@0 | 22 | */ |
michael@0 | 23 | public class WebViewActivity extends SyncActivity { |
michael@0 | 24 | private final static String LOG_TAG = "WebViewActivity"; |
michael@0 | 25 | |
michael@0 | 26 | @Override |
michael@0 | 27 | public void onCreate(Bundle savedInstanceState) { |
michael@0 | 28 | super.onCreate(savedInstanceState); |
michael@0 | 29 | getWindow().requestFeature(Window.FEATURE_PROGRESS); |
michael@0 | 30 | setContentView(R.layout.sync_setup_webview); |
michael@0 | 31 | // Extract URI to launch from Intent. |
michael@0 | 32 | Uri uri = this.getIntent().getData(); |
michael@0 | 33 | if (uri == null) { |
michael@0 | 34 | Logger.debug(LOG_TAG, "No URI passed to display."); |
michael@0 | 35 | finish(); |
michael@0 | 36 | return; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | WebView wv = (WebView) findViewById(R.id.web_engine); |
michael@0 | 40 | // Add a progress bar. |
michael@0 | 41 | final Activity activity = this; |
michael@0 | 42 | wv.setWebChromeClient(new WebChromeClient() { |
michael@0 | 43 | @Override |
michael@0 | 44 | public void onProgressChanged(WebView view, int progress) { |
michael@0 | 45 | // Activities and WebViews measure progress with different scales. |
michael@0 | 46 | // The progress meter will automatically disappear when we reach 100% |
michael@0 | 47 | activity.setProgress(progress * 100); |
michael@0 | 48 | } |
michael@0 | 49 | }); |
michael@0 | 50 | wv.setWebViewClient(new WebViewClient() { |
michael@0 | 51 | // Handle url loading in this WebView, instead of asking the ActivityManager. |
michael@0 | 52 | @Override |
michael@0 | 53 | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
michael@0 | 54 | view.loadUrl(url); |
michael@0 | 55 | return false; |
michael@0 | 56 | } |
michael@0 | 57 | }); |
michael@0 | 58 | wv.loadUrl(uri.toString()); |
michael@0 | 59 | |
michael@0 | 60 | } |
michael@0 | 61 | } |