My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.beanie.samples.jquery;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;

import com.beanie.samples.jquery.client.SampleChromeClient;
import com.beanie.samples.jquery.jsinterfaces.JSInterface;

public class HomeActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

initializeUIElements();
}

private void initializeUIElements(){
WebView webView = (WebView)findViewById(R.id.webView);

// Load the HTML file from the assets directory
webView.loadUrl("file:///android_asset/sample_page.html");

// Enable Javascript on the webView. By default, it's disabled
webView.getSettings().setJavaScriptEnabled(true);

// Set the Web Chrome client for stuff like Alerts
webView.setWebChromeClient(new SampleChromeClient());

// Set the JSInterface that is a connector between your javascrip and Java class
JSInterface jsInterface = new JSInterface(webView);
jsInterface.setOnExitAppListener(new OnExitAppListener()
{
@Override
public void onAppExit()
{
Toast.makeText(getBaseContext(), "Exiting", Toast.LENGTH_LONG).show();
finish();
}
});

webView.addJavascriptInterface(jsInterface, "jsinterface");
}
}

Change log

r26 by coomar.101 on Oct 19, 2010   Diff
Initial commit
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1606 bytes, 47 lines
Powered by Google Project Hosting