@@ -19,7 +19,10 @@ Design Goals
1919
2020Version
2121-------
22- [ 2.2-pre2] ( https://github.com/ericwlange/AndroidJSCore/releases/tag/2.2-pre2 ) - Please help test this version
22+ [ 3.0-pre1] ( https://github.com/ericwlange/AndroidJSCore/releases/tag/3.0-pre1 ) - Please help test this version
23+
24+ Note there are some significant changes between 3.0 and the 2.x series. In particular, handling of functions
25+ and constructors is simpler (and more correct).
2326
2427Working With AndroidJSCore
2528--------------------------
@@ -68,32 +71,23 @@ AndroidJSCore is much more powerful than that. You can also write functions in
6871Java, but expose them to JavaScript:
6972
7073``` java
71- public interface IExposedToJS {
72- public Integer factorial (Integer x );
73- }
74- public class FactorialObject extends JSObject
75- implements IExposedToJS {
76- public FactorialObject (JSContext ctx ) {
77- super (ctx,IExposedToJS . class);
78- }
79- @Override
74+ JSFunction factorial = new JSFunction (context," factorial" ) {
8075 public Integer factorial (Integer x ) {
8176 int factorial = 1 ;
8277 for (; x > 1 ; x-- ) {
8378 factorial *= x;
8479 }
8580 return factorial;
8681 }
87- }
82+ };
8883```
8984
90- This class creates a Java object that is also a JavaScript object, which exposes
91- a single function property ` factorial ` . It can then be passed to the JavaScript
92- VM:
85+ This creates a JavaScript function that will call the Java method ` factorial ` when
86+ called from JavaScript. It can then be passed to the JavaScript VM:
9387
9488``` java
95- context. property(" myJavaFunctions " , new FactorialObject (context) );
96- context. evaluateScript(" var f = myJavaFunctions. factorial(10);" )
89+ context. property(" factorial " , factorial );
90+ context. evaluateScript(" var f = factorial(10);" )
9791JSValue f = context. property(" f" );
9892System . out. println(df. format(f. toNumber())); // 3628800.0
9993```
@@ -108,7 +102,7 @@ just about everything.
108102
109103Use AndroidJSCore in your project
110104---------------------------------
111- The easy way is to simply download the file ` AndroidJSCore-2.2-pre2 -release.aar ` from
105+ The easy way is to simply download the file ` AndroidJSCore-3.0-pre1 -release.aar ` from
112106the [ latest release] and drop it somewhere in your project (` libs/ ` is meant just for this). Then
113107add the following to your app-level ` build.gradle ` :
114108
@@ -119,7 +113,7 @@ add the following to your app-level `build.gradle`:
119113 }
120114
121115 dependencies {
122- compile(name:'AndroidJSCore-2.2-pre2 -release', ext:'aar')
116+ compile(name:'AndroidJSCore-3.0-pre1 -release', ext:'aar')
123117 }
124118
125119Building the AndroidJSCoreExample app
@@ -131,11 +125,11 @@ If you want to see AndroidJSCore in action, you can run the example app:
131125 cd ~/AndroidJSCore
132126 mkdir ~/AndroidJSCore/lib
133127
134- Then download ` AndroidJSCore-2.2-pre2 -release.aar ` from the [ latest release] and
128+ Then download ` AndroidJSCore-3.0-pre1 -release.aar ` from the [ latest release] and
135129copy it into ` ~/AndroidJSCore/lib ` . Now you can open ` ~/AndroidJSCore/examples/AndroidJSCoreExample `
136130in Android Studio and run it.
137131
138- Building AndroidJSCore-2.2 library
132+ Building AndroidJSCore-3.0 library
139133----------------------------------
140134
141135If you are interested in building the library directly and possibly contributing, you must
@@ -167,7 +161,7 @@ and then re-run `hemroid install javascriptcore`.
167161 % echo sdk.dir=$ANDROID_SDK >> local.properties
168162 % ./gradlew assembleRelease
169163
170- Your library now sits in ` AndroidJSCore/build/outputs/aar/AndroidJSCore-2.2-pre2 -release.aar ` . To use it, simply
164+ Your library now sits in ` AndroidJSCore/build/outputs/aar/AndroidJSCore-3.0-pre1 -release.aar ` . To use it, simply
171165add the following to your app's ` build.gradle ` :
172166
173167 repositories {
0 commit comments