• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.chromedriver_webview_shell;
6 
7 import android.app.Activity;
8 import android.content.Intent;
9 import android.content.res.Configuration;
10 import android.os.Build;
11 import android.os.Bundle;
12 import android.view.Window;
13 import android.webkit.WebChromeClient;
14 import android.webkit.WebSettings;
15 import android.webkit.WebView;
16 import android.webkit.WebViewClient;
17 import android.widget.Toast;
18 
19 public class Main extends Activity {
20     private WebView mWebView;
21 
22     @Override
onCreate(Bundle savedInstanceState)23     protected void onCreate(Bundle savedInstanceState) {
24         super.onCreate(savedInstanceState);
25 
26         getWindow().requestFeature(Window.FEATURE_PROGRESS);
27         setContentView(R.layout.main_layout);
28 
29         WebView.setWebContentsDebuggingEnabled(true);
30         mWebView = (WebView) findViewById(R.id.webview);
31         WebSettings webSettings = mWebView.getSettings();
32         webSettings.setJavaScriptEnabled(true);
33 
34         final Activity activity = this;
35         mWebView.setWebChromeClient(new WebChromeClient() {
36             public void onProgressChanged(WebView view, int progress) {
37                 activity.setProgress(progress * 100);
38             }
39          });
40         mWebView.setWebViewClient(new WebViewClient() {
41             public void onReceivedError(WebView view, int errorCode, String description,
42                 String failingUrl) {
43                 Toast.makeText(activity, "Error: " + description, Toast.LENGTH_SHORT).show();
44            }
45          });
46 
47         loadUrl(getIntent());
48     }
49 
50     @Override
onNewIntent(Intent intent)51     protected void onNewIntent(Intent intent) {
52         super.onNewIntent(intent);
53         loadUrl(intent);
54     }
55 
loadUrl(Intent intent)56     private void loadUrl(Intent intent) {
57         if (intent != null && intent.getDataString() != null) {
58             mWebView.loadUrl(intent.getDataString());
59         }
60     }
61 }
62