Main.java revision f2477e01787aa58f445919b809d89e252beef54f
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
5package org.chromium.chromedriver_webview_shell;
6
7import android.app.Activity;
8import android.content.Intent;
9import android.content.res.Configuration;
10import android.os.Build;
11import android.os.Bundle;
12import android.view.Window;
13import android.webkit.WebChromeClient;
14import android.webkit.WebSettings;
15import android.webkit.WebView;
16import android.webkit.WebViewClient;
17import android.widget.Toast;
18
19public class Main extends Activity {
20    private WebView mWebView;
21
22    @Override
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
51    protected void onNewIntent(Intent intent) {
52        super.onNewIntent(intent);
53        loadUrl(intent);
54    }
55
56    private void loadUrl(Intent intent) {
57        if (intent != null && intent.getDataString() != null) {
58            mWebView.loadUrl(intent.getDataString());
59        }
60    }
61}
62