Proteus is meant to be a drop-in replacement for Android’s LayoutInflater
; but unlike the compiled XML layouts bundled in the APK, Proteus inflates layouts at runtime.
With Proteus, you can control your Apps layout from the backend (no WebViews). Forget the boilerplate code to findViewById
, cast it to a TextView
, and then setText()
. Proteus has runtime data bindings and formatters. Plugin in your own custom views and attributes and formatters.
// Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
// Add the dependency
dependencies {
compile 'com.github.flipkart-incubator:proteus:4.2.0'
}
- Clone the proteus in the project folder
git clone https://github.com/flipkart-incubator/proteus.git
- Include the a project in you apps
build.gradle
file
dependencies {
compile project('proteus:library')
}
Instead of writing layouts in XML
, in proteus layouts are defined in JSON
, which can be used to inflate native android UI at runtime. The JSON
layouts can be hosted anywhere (on the device, on servers, etc.).
The "Layout" defines the the view heirarchy, just like XML.
The "Data" (optional) defines data bindings.
You give the layout and data to LayoutBuilder, you get back a native view.
Watch this video to see it in action.
{
"type": "LinearLayout",
"orientation": "vertical",
"padding": "16dp",
"children": [{
"layout_width": "200dp",
"gravity": "center",
"type": "TextView",
"text": "~{{user.profile.name}} ({{user.profile.experience}}$(number))"
}, {
"type": "HorizontalProgressBar",
"layout_width": "200dp",
"layout_marginTop": "8dp",
"max": 6000,
"progress": "$user.profile.experience"
}]
}
{
"user": {
"profile": {
"name": "John Doe",
"experience": 4192
}
}
}
ProteusView view = layoutBuilder.build(container, <layout>, <data>, 0, styles);
container.addView((View) view);
The demo app will let you play around with Proteus as well as help you understand the internals better.
- Install NodeJS here
- open a terminal
- cd into the project directory
- run
npm start
- Start an AVD emulator
- Install the Demo App
Ready to tinker
- FAQ
- Detailed Guide
- API References under construction
- DroidCon Talk
- Demo Videos
- Fork the repo
- Apply your changes
- Submit your pull request
Download this plugin (in beta) for Android Studio. Once enabled, you can select any android XML resource file and go to Tools > Proteus > Convert XML to JSON