Code example for WebView

Methods: getSettingssetWebChromeClient, getClass

0
	public CalabashChromeClient(final WebView webView) {
		this.webView = webView;
		this.scriptFuture = new WebFuture(webView);
		if (Build.VERSION.SDK_INT < 16) { // jelly bean
			try { 
				Method methodGetConfiguration = webView.getClass().getMethod(
						"getWebChromeClient"); 
				mWebChromeClient = (WebChromeClient) methodGetConfiguration
						.invoke(webView);
			} catch (Exception e) {
				throw new RuntimeException(e);
			} 
		} 
 
        if ( Looper.getMainLooper().getThread() == Thread.currentThread()) {
            webView.setWebChromeClient(this);
        } else { 
            InstrumentationBackend.instrumentation.runOnMainSync(new Runnable() {
                @Override 
                public void run() { 
                    webView.setWebChromeClient(CalabashChromeClient.this);
                } 
            }); 
        } 
	} 
 
	@Override 
	public boolean onJsPrompt(WebView view, String url, String message,
			String defaultValue, JsPromptResult r) {
		if (message != null && message.startsWith("calabash:")) {
			r.confirm("CALABASH_ACK");
			System.out.println("onJsPrompt: " + message);
			String jsonResponse = message.replaceFirst("calabash:", "");
			scriptFuture.setResult(jsonResponse);			
			return true; 
		} else { 
			if (mWebChromeClient == null) {
				r.confirm("CALABASH_ERROR");
				scriptFuture.complete();
				return true; 
			} else { 
				// TODO I'm not what this case does... 
				return mWebChromeClient.onJsPrompt(view, url, message,
						defaultValue, r);
			} 
		} 
	} 
 
	public WebView getWebView() {
		return webView;
	} 
 
	public static CalabashChromeClient prepareWebView(WebView webView) {
		CalabashChromeClient calabashChromeClient = new CalabashChromeClient(
				webView);
		webView.getSettings().setJavaScriptEnabled(true);
		return calabashChromeClient;
	} 
 
	public static List<CalabashChromeClient> findAndPrepareWebViews() {
		List<CalabashChromeClient> webViews = new ArrayList<CalabashChromeClient>();