All Projects → MichaelRocks → DataBindingCompat

MichaelRocks / DataBindingCompat

Licence: Apache-2.0 license
A Gradle plugin that makes databinding work well with appcompat

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to DataBindingCompat

Androidlife
📔 CaMnter's android learning life and footprint.
Stars: ✭ 293 (+2153.85%)
Mutual labels:  gradle-plugin, databinding
gradle-jnlp-plugin
Gradle plugin to generate jnlp files, sign jars etc. for being able to start an application with Java Webstart
Stars: ✭ 19 (+46.15%)
Mutual labels:  gradle-plugin
kfc-plugins
Kotlin/JS Fast Configuration
Stars: ✭ 37 (+184.62%)
Mutual labels:  gradle-plugin
FirebaseTestLab-Android
No description or website provided.
Stars: ✭ 50 (+284.62%)
Mutual labels:  gradle-plugin
androidNativeBundle
a gradle plugin that support publish c/c++ headers to 'aar' and depend those 'aar'
Stars: ✭ 60 (+361.54%)
Mutual labels:  gradle-plugin
fabric-loom
Gradle build system plugin used to automate the setup of a minecraft mod development environment.
Stars: ✭ 150 (+1053.85%)
Mutual labels:  gradle-plugin
gradle-git-versioning-plugin
This extension will set project version, based on current Git branch or tag.
Stars: ✭ 44 (+238.46%)
Mutual labels:  gradle-plugin
fat-aar
The fat-aar plugin that can be used under android plugin 3.0.1 and gradle wrapper 4.4.
Stars: ✭ 32 (+146.15%)
Mutual labels:  gradle-plugin
groocss
GrooCSS - code CSS in Groovy
Stars: ✭ 24 (+84.62%)
Mutual labels:  gradle-plugin
android-shortcut-gradle-plugin
Android Gradle plugin generates App Shortcuts shortcuts.xml for different flavors with different applicationId.
Stars: ✭ 20 (+53.85%)
Mutual labels:  gradle-plugin
parcl
Gradle plugin for bundling your Java application for distribution on Windows, Mac and Linux
Stars: ✭ 52 (+300%)
Mutual labels:  gradle-plugin
sentry-android-gradle-plugin
Gradle plugin for Sentry Android. Upload proguard, debug files, and more.
Stars: ✭ 67 (+415.38%)
Mutual labels:  gradle-plugin
EasyTask MVVM Kotlin
Todo app based on MVVM, Kotlin Coroutines, Navigation Component, Room Database, Retrofit, Data Binding
Stars: ✭ 49 (+276.92%)
Mutual labels:  databinding
laboratory
Feature flags for multi-module Kotlin Android projects
Stars: ✭ 71 (+446.15%)
Mutual labels:  gradle-plugin
kt2ts-gradle-plugin
Generate TypeScript from Kotlin (or any jvm language) by annotations
Stars: ✭ 15 (+15.38%)
Mutual labels:  gradle-plugin
LiveData-DataBinding-Kotlin
Sample to practice LiveData + DataBinding
Stars: ✭ 89 (+584.62%)
Mutual labels:  databinding
native-build-tools
Native-image plugins for various build tools
Stars: ✭ 168 (+1192.31%)
Mutual labels:  gradle-plugin
kosogor
Defaults and simplified Kotlins-DSL interfaces for Gradle
Stars: ✭ 18 (+38.46%)
Mutual labels:  gradle-plugin
WanAndroidJetpack
🔥 WanAndroid 客户端,Kotlin + MVVM + Jetpack + Retrofit + Glide。基于 MVVM 架构,用 Jetpack 实现,网络采用 Kotlin 的协程和 Retrofit 配合使用!精美的 UI,便捷突出的功能实现,欢迎下载体验!
Stars: ✭ 124 (+853.85%)
Mutual labels:  databinding
sonar-scanner-gradle
SonarQube Scanner for Gradle
Stars: ✭ 132 (+915.38%)
Mutual labels:  gradle-plugin

Build Status

Deprecated

VectorDrawables are supported in DataBinding natively since AGP 4.0.0.

DataBindingCompat

A Gradle plugin that adds support for VectorDrawableCompat to the Data Binding Library.

Why?

The Data Binding Library supports resources in binding expressions, and drawable resources in particular.

  <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@{condition ? @drawable/image1 : @drawable/image2}" />

But if your project uses support vector drawables you're in a big trouble.

android {  
  defaultConfig {  
    vectorDrawables.useSupportLibrary = true  
  }  
} 

Unfortunately, the Data Binding Library doesn't call AppCompatResources.getDrawable() when loading drawables, so the binding above will throw an exception at runtime on pre-Lollipop devices. DataBindingCompat solves this issue and all you need to do is just to apply the Gradle plugin.

Usage

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath 'io.michaelrocks:databindingcompat:1.1.7'
  }
}

apply plugin: 'com.android.application'
apply plugin: 'io.michaelrocks.databindingcompat'

How it works

When you use a drawable resource in a binding expression the Data Binding Library inflates this drawable by calling the ViewDataBinding.getDrawableFromResource() method. The DataBindingCompat plugin patches ViewDataBinding class at compile time and replaces the implementation of getDrawableFromResource() with an invocation of AppCompatResources.getDrawable(). The same transformation the plugin does with the ViewDataBinding.getColorStateListFromResource() method. And that's it.

ViewDataBinding before patching:

protected static Drawable getDrawableFromResource(View view, int resourceId) {
  if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
    return view.getContext().getDrawable(resourceId);
  } else {
    return view.getResources().getDrawable(resourceId);
  }
}

protected static ColorStateList getColorStateListFromResource(View view, int resourceId) {
  if (VERSION.SDK_INT >= VERSION_CODES.M) {
    return view.getContext().getColorStateList(resourceId);
  } else {
    return view.getResources().getColorStateList(resourceId);
  }
}

ViewDataBinding after patching:

protected static Drawable getDrawableFromResource(View view, int resourceId) {
  return AppCompatResources.getDrawable(view.getContext(), resourceId));
}

protected static ColorStateList getColorStateListFromResource(View view, int resourceId) {
  return AppCompatResources.getColorStateList(view.getContext(), resourceId));
}

License

Copyright 2017 Michael Rozumyanskiy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].