<NME> README.md
<BEF> json2view  ![travis-ci](https://travis-ci.org/Avocarrot/json2view.svg)
======

**json2view** is a simple library that can convert a compatible JSON file to an Android view so you can load dynamically the view in your Android app without the need to update the APK.

This removes the hassle of updating, re-compiling and uploading the APK to Google Play everytime you want to make small or big changes in the UI.


# Installation
- Download project
```git clone https://github.com/Avocarrot/koukouroukou.git```

- add json2view in your project by adding in your settings.gradle
```include ':json2view'
project(':json2view').projectDir = new File(settingsDir, '$(koukouroukouPath)/koukouroukou/json2view')```

- add in build.gradle of application module (not project build.gradle) in `dependencies` section
```compile project(':json2view')```

# Usage
create and attach view in the specific Parent (created from xml) <br/>
3. If you need to deploy UI fixes quickly and in real-time.

In the case of [Avocarrot](http://www.avocarrot.com), we are using json2view to run A/B test experiments and quickly deploy UI enhancements that improve revenue performance of native ads integrations in our network.

## How it works

you can check more example in [Usage](https://github.com/Avocarrot/koukouroukou/wiki/Usage)

# Basic Json Format
The input json must have 3 fields for every View you need to add. To add a TextView
```javascript
{
    "widget": "android.widget.TextView",
	"properties": [],
	"views":[] /*optional*/
}
```

# Supported Properties
Most of the properties for Android View are supported. <br/>
You can find the full list [Available Properties](https://github.com/Avocarrot/koukouroukou/wiki/Available-Properties)


## pros


- add json2view in your project by adding in your settings.gradle
```
include ':json2view'
project(':json2view'*).projectDir = new File(settingsDir, '$(json2viewPath)/json2view/json2view')
```


- add in build.gradle of application module (not project build.gradle) in `dependencies` section

```
compile project(':json2view')
```

## Getting started

### Basic JSON format
The input JSON has 3 fields for every view we want to create :

* `widget` : canonicalName of View (for views in package `android.widget` you can ommit `android.widget`)
* `properties` : list of properties for the view. ([Available Properties](https://github.com/Avocarrot/json2view/wiki/Available-Properties)) By default we add `layout_width` & `layout_height` with value `wrap_content'
* `views` : children views for ViewGroup _(optional)_

eg. JSON to create a empty TextView
```javascript
{
    "widget": "android.widgetTextView",
	"properties": []
}
```

eg. JSON to create a TextView with textSize : 12sp and text : "Hello Avocarrot!"
```javascript
{
    "widget": "TextView",
	"properties": [
	    {"name":"textSize", "type": "dimen", "value":"13sp"},
	    {"name":"text", "type": "string", "value":"Hello Avocarrot!"}
	]
}
```

You can find some examples for xml to JSON conversions in the wiki [here](https://github.com/Avocarrot/json2view/wiki/Xml-2-JSON-Examples)

You can use *ConvertXML2JSON.groovy* (from ./utils) to convert any android xml to json2view valid JSON file
_(the script needs further development to create a valid JSON for <b>every</b> case)_ <br/>
try : <br/>

```
./gradlew runScript -Pxml=./pathToInputXmlFile.xml
```
from the root folder of the project


### Loading dynamic layout
create and attach view in the specific Parent (created from xml) <br/>
```java
ViewParent viewParent = (ViewParent) findViewById(R.id.parent_view_id)
JSONObject jsonObject = ... // load from network, sdcard etc
View sampleView = DynamicView.createView(this, jsonObject, viewParent);
```

You can check some example use cases in the wiki [here](https://github.com/Avocarrot/json2view/wiki/Creating-Dynamic-Layouts)


## Contributing

1. Fork the repo
2. Apply your changes
3. Write tests
4. Submit your pull request

For feedback or suggestions you can drop us a line at support@avocarrot.com

## License
[The MIT License (MIT)](https://github.com/Avocarrot/json2view/blob/master/LICENSE)


Also check out the project at [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-json2view-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1453)

<MSG> update readme script [skip ci]

<DFF> @@ -8,14 +8,24 @@ Json2View can convert a compatible json file to an android view so you can load
 
 # Installation
 - Download project
-```git clone https://github.com/Avocarrot/koukouroukou.git```
+```
+git clone https://github.com/Avocarrot/koukouroukou.git
+```
+
 
 - add json2view in your project by adding in your settings.gradle
-```include ':json2view'
-project(':json2view').projectDir = new File(settingsDir, '$(koukouroukouPath)/koukouroukou/json2view')```
+```
+include ':json2view'
+project(':json2view'*).projectDir = new File(settingsDir, '$(koukouroukouPath)/koukouroukou/json2view')
+```
+
 
 - add in build.gradle of application module (not project build.gradle) in `dependencies` section
-```compile project(':json2view')```
+
+```
+compile project(':json2view')
+```
+
 
 # Usage
 create and attach view in the specific Parent (created from xml) <br/>
@@ -28,18 +38,29 @@ View sampleView = DynamicView.createView(this, jsonObject, viewParent);
 you can check more example in [Usage](https://github.com/Avocarrot/koukouroukou/wiki/Usage)
 
 # Basic Json Format
-The input json must have 3 fields for every View you need to add. To add a TextView
+The input json has 3 fields for every view we want to create :
+
+* `widget` : canonicalName of View (for views in package `android.widget` you can ommit `android.widget`)
+* `properties` : list of properties for the view. ([Available Properties](https://github.com/Avocarrot/koukouroukou/wiki/Available-Properties)) By default we add `layout_width` & `layout_height` with value `wrap_content'
+* `views` : (optional) for View Group add children views
+
+ eg. json to create a empty TextView
 ```javascript
 {
-    "widget": "android.widget.TextView",
-	"properties": [],
-	"views":[] /*optional*/
+    "widget": "android.widgetTextView",
+	"properties": []
+}
+```
+ eg. json to create a TextView with textSize : 12sp and text : "Hello Avocarrot!"
+```javascript
+{
+    "widget": "TextView",
+	"properties": [
+	    {"name":"textSize", "type": "dimen", "value":"13sp"},
+	    {"name":"text", "type": "string", "value":"Hello Avocarrot!"}
+	]
 }
 ```
-
-# Supported Properties
-Most of the properties for Android View are supported. <br/>
-You can find the full list [Available Properties](https://github.com/Avocarrot/koukouroukou/wiki/Available-Properties)
 
 
 ## pros

update readme script [skip ci]