Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.kimeeo:proteus:5.0.0-rc11'
}
dependencies {
implementation("com.github.kimeeo:proteus:5.0.0-rc11")
}
<dependency>
<groupId>com.github.kimeeo</groupId>
<artifactId>proteus</artifactId>
<version>5.0.0-rc11</version>
</dependency>
libraryDependencies += "com.github.kimeeo" % "proteus" % "5.0.0-rc11"
:dependencies [[com.github.kimeeo/proteus "5.0.0-rc11"]]
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.
// 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-core:5.0.0-rc8@aar'
compile 'com.github.flipkart-incubator:gson-adapter:5.0.0-rc8@aar'
}
git clone https://github.com/flipkart-incubator/proteus.git
build.gradle
filedependencies {
compile project('proteus:proteus-core')
compile project('proteus:gson-adapter')
}
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.
npm start
Ready to tinker
The easiest way to contribute is by forking the repo, making your changes and creating a pull request.
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.
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