Home | History | Annotate | Download | only in chromedriver_webview_shell
      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.os.Bundle;
     10 import android.view.Window;
     11 import android.webkit.WebChromeClient;
     12 import android.webkit.WebSettings;
     13 import android.webkit.WebView;
     14 import android.webkit.WebViewClient;
     15 import android.widget.Toast;
     16 
     17 public class Main extends Activity {
     18     private WebView mWebView;
     19 
     20     @Override
     21     protected void onCreate(Bundle savedInstanceState) {
     22         super.onCreate(savedInstanceState);
     23 
     24         getWindow().requestFeature(Window.FEATURE_PROGRESS);
     25         setContentView(R.layout.main_layout);
     26 
     27         WebView.setWebContentsDebuggingEnabled(true);
     28         mWebView = (WebView) findViewById(R.id.webview);
     29         WebSettings webSettings = mWebView.getSettings();
     30         webSettings.setJavaScriptEnabled(true);
     31 
     32         final Activity activity = this;
     33         mWebView.setWebChromeClient(new WebChromeClient() {
     34             @Override
     35             public void onProgressChanged(WebView view, int progress) {
     36                 activity.setProgress(progress * 100);
     37             }
     38          });
     39         mWebView.setWebViewClient(new WebViewClient() {
     40             @Override
     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