# json2view **Repository Path**: limpoxe/json2view ## Basic Information - **Project Name**: json2view - **Description**: Update native Android UI on the fly - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-15 - **Last Updated**: 2021-10-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README json2view  ====== **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.
|
Note: Runtime creation of a view without the precompiled version of xml in apk (res/layout), especially for highly complex layouts, can be a potential latency issue.
## Examples
### Changing text color
Using json2view to change text color, background color and position of a view. [(more details)](https://github.com/Avocarrot/json2view/wiki/Changing-Properties)

### Reorganizing the layout
Using json2view to reorganize the layout of a screen. [(more details)](https://github.com/Avocarrot/json2view/wiki/Changing-Layouts)

You can find more help and examples in the [wiki](https://github.com/Avocarrot/json2view/wiki).
Also, a sample project for quick use of the lib can be found in the [sample submodule](https://github.com/Avocarrot/json2view/tree/master/sample)
## Installation
- Download project
```
git clone https://github.com/Avocarrot/json2view.git
```
- 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 every case)_