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 functions to flavour proteus to your requirements.
// Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
// Add in your app level dependency
dependencies {
implementation 'com.github.flipkart-incubator.proteus:proteus-core:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:gson-adapter:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:cardview-v7:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:design:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:recyclerview-v7:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:support-v4:5.0.1'
}
Instead of writing layouts in XML
, in proteus layouts are described 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. These data bindings are similar to Android's Data Binding library.
Give the layout
and data
to ProteusLayoutInflater
and get back a native view hierarchy.
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}"
}, {
"type": "HorizontalProgressBar",
"layout_width": "200dp",
"layout_marginTop": "8dp",
"max": 6000,
"progress": "@{user.profile.experience}"
}]
}
{
"user": {
"profile": {
"name": "John Doe",
"experience": 4192
}
}
}
ProteusView view = proteusLayoutInflater.inflate(<layout>, <data>);
container.addView(view.getAsView());
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
- Native Android Widgets
- CardView v7
- Android Design Library
- RecyclerView v7
- Android Support v4
The easiest way to contribute is by forking the repo, making your changes and creating a pull request.
- Adding new Views and Attribute Proccessors.
- Adding new Functions.
- Adding JavaDoc and Wiki.
- Completing TODOs
- Writing unit tests.
- Finding bugs and issues. (submit here)
- Fixing bugs and issues.
- Implement performance/benchmarking tools.
If you are using proteus check out the can, cannot and must
You can check out the contributors here, but if you wish to contact us; just drop in a mail.
Find us on StackOverflow at proteus.
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