Skip to content

Commit

Permalink
Updated README.md with "using in Android-Projects"
Browse files Browse the repository at this point in the history
Added some information, what's neccesarry to use wslite in Android-Projects with Groovy. Added the information which should be entered in the build.gradle file and a small example for using it...
  • Loading branch information
susannej committed Sep 28, 2016
1 parent 130dc5d commit 26177ca
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Expand Up @@ -636,6 +636,63 @@ class MyService {
}
```

## Using with Android

wslite can easily used in an Android-Project, but you might need the following in your build.gradle of your android-project:

```gradle
compile ('org.codehaus.groovy:groovy-json:2.4.3') {
exclude group: 'org.codehaus.groovy'
}
```
and / or

```gradle
compile ('org.codehaus.groovy:groovy-xml:2.4.3') {
exclude group: 'org.codehaus.groovy'
}
```
in your dependency group.

A small example (with [SwissKnife](https://github.com/Arasthel/SwissKnife) annotations):

```groovy
@OnBackground
public void fetchContractData(String queryType) {
try {
ConnectivityManager cMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)
NetworkInfo networkInfo = cMgr.activeNetworkInfo
if (networkInfo != null && networkInfo.isConnected()) {
def client = new RESTClient("http://example.org:8080/MyApp/", new HTTPClient())
client.authorization = new HTTPBasicAuthorization(credUserName, credUserPassword)
def response = client.get(path: '/api/stat/contractAmount', query: [type: queryType])
if (response.statusCode != 200)
showErrorSnackbar(response.statusCode, response.statusMessage)
else
showDataInView(response.json)
} else
showErrorSnackbar("998", "no connection")
} catch (Exception ex) {
showErrorSnackbar("999", ex.message)
}
}
@OnUIThread
public void showDataInView(data) {
data.each { line ->
...
}
}
@OnUIThread
public void showErrorSnackbar(code, message) {
Snackbar.make(<view>, code + ": " + message, Snackbar.LENGTH_LONG).show()
}
```


## Versioning

This project uses [Semantic Versioning] (http://semver.org/).
Expand Down

0 comments on commit 26177ca

Please sign in to comment.