Giter Site home page Giter Site logo

andjs's Introduction

andjs

v8 js engine for android

  • How to integrate andjs
    • 1: add andjs aar into your project
    • 2: AndJS.Init to initialize first
    • 3: AndJS.injectObject to inject java object, which will be used by javascript
    • 4: AndJS.loadJSBuf(String jsbuf) to Run javascript in V8
  • Sample code
import com.github.wuruxu.andjs.AndJS;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      AndJS.Init(this);  //AndJS Initialize
      
      obj = new MyObject();
      AndJS.injectObject(obj, "myobject", null);  //Inject Java Object into javascript
      
      String jsbuf = "myobject.doLog('This is a JS string');";
			jsbuf += "var msg = myobject.getMessage(); adb.info(msg);";
			jsbuf += "var home = myobject.getMyHome(); home.printRect(0, 0, 512, 512);";
			jsbuf += "var homemsg = home.getMessage(); adb.info(homemsg);";
        
      AndJS.loadJSBuf(jsbuf); // Run Javascript in V8 engine
    }
}

//sample code of MyObject
import com.github.wuruxu.andjs.CalledByJavascript;

public class MyObject extends Object {
	private static final String TAG = "MyObject";
	private MyHome home;

	public MyObject() {
		home = new MyHome();
	}

	@CalledByJavascript
	public void doLog(String msg) {
		Log.i(TAG, " * " + msg);
	}

	@CalledByJavascript
	public String getMessage() {
		return "This is a java string";
	}

	@CalledByJavascript
	public MyHome getMyHome() {
		return home;
	}
}

//sample code of MyHome
import com.github.wuruxu.andjs.CalledByJavascript;

public class MyHome extends Object {
	private static final String TAG = "MyHome";

	public MyHome() {}

	@CalledByJavascript
	public void printRect(int x0, int y0, int x1, int y1) {
		Log.i(TAG, " * x0 " + x0 + " y0 " + y0 + " x1 " + x1 + " y1 " + y1);
	}

	@CalledByJavascript
	public String getMessage() {
		return "This is a java string from MyHome";
	}
}

andjs's People

Contributors

wuruxu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.