An open API service indexing awesome lists of open source software.

https://github.com/spongebobsun/jswebview

JSWebView is a webview utility which support interaction between Javascript code & Java code.
https://github.com/spongebobsun/jswebview

Last synced: 10 months ago
JSON representation

JSWebView is a webview utility which support interaction between Javascript code & Java code.

Awesome Lists containing this project

README

          

#JSWebView
JSWebView is a webview which support interaction between Javascript code & Java code.

##Project Status
Under developing.

Following features are avaliable currently.

* Choose images from webpage
* Open a new window to preview image from webpage
* Change actionbar title from webpage
* Close webpage window

##Project Structure
The whole project is a test project.

JSWebView Library located in `jswebview` folder.

Folder `dummypicloader` is my own image loading library.

**JS-SDK is located in /app/src/main/assets/jswebview.js**

##Components
This list will be updated when new components are added to this lib.

* JSWebViewActivity

JSWebViewActivity is the main Activity which contains the webview. All activities which use jswebview lib should extends this activity. It will initialize webview and add built in functions & interfaces into it.

* ImageChooseActivity

Browse & choose images in your device. This activity is based on my own image load library - DummyPicLoader.

* ImaePreviewActivity

Preview images in a new Activity. Provide slide to next/prev page when you passing multipule images to it.
* JSWebView

Main widget of this lib. You can add your own js calling handler to it by using `addBaseHandler(...)`.

* JS-sdk

JavaScript sdk for this lib.

##Usage
First of all, import this lib to your IDE and add it to build path or gradle dependence.

Then, create an Activity extends JSWebViewActivity, or add JSWebView widget to your own layout xml file.

WARNNING: When using JSWebView directly in your custom Activity, you will NOT get any result which library build-in activity returns. You should write your won response code in onActivityResult(). You can find return type and format in JSWebViewActivity's source code.

Use loadUrl function in activity or JSWebView
to load your web app.

Write js code to call native code.

Have fun.

##APIs

###JSWebViewActivity
* addBaseHandler(String, CallBackFunction)

Add a native handler with name and action. When JavaScript code call this handler by name, native code will trigger CallBackFunction to perform the action.

* loadUrl(String)

Load url, generally is your web app address or local webpage file.

###JSWebView

Same interface as JSWebViewActivity. When using JSWebView directly rather than inherit JSWebViewActivity, you should write your own 'onActivityResult' function to handle the results returned from library build in activity such as 'ImageChooseActivity'.

###JS-SDK

* jswebview.callNative(functionName, jsonArg)

Call native code with specified function name and arguments. Arguments are in JSON format. Function names are defined in Java code using 'addBaseHandler'

This is the ONLY interface which JavaScript code can invoke native Java code.

* jswebview.addEvent(eventName, callback)

Add a custom function which defined in native code. First parameter is the function name, and second parameter is a callback function which will be triggerd after native code is done processing.

* jswebview.nativeCallBack(eventName, jsonArgs)

Interface for native Java code to call JavaScript code. I've centerialized interfaces between native Java code and JavaScript code. So you can call this function to passing parameters from native code to JavaScript code.