diff options
Diffstat (limited to 'compiler/src/main/kotlin/android/databinding/tool/writer/DynamicUtilWriter.kt')
-rw-r--r-- | compiler/src/main/kotlin/android/databinding/tool/writer/DynamicUtilWriter.kt | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/compiler/src/main/kotlin/android/databinding/tool/writer/DynamicUtilWriter.kt b/compiler/src/main/kotlin/android/databinding/tool/writer/DynamicUtilWriter.kt index 8d76b030..e7314606 100644 --- a/compiler/src/main/kotlin/android/databinding/tool/writer/DynamicUtilWriter.kt +++ b/compiler/src/main/kotlin/android/databinding/tool/writer/DynamicUtilWriter.kt @@ -8,13 +8,33 @@ class DynamicUtilWriter() { nl("") block("public class DynamicUtil") { nl("@SuppressWarnings(\"deprecation\")") - block("public static int getColorFromResource(final android.view.View root, final int resourceId)") { + block("public static int getColorFromResource(final android.view.View view, final int resourceId)") { if (targetSdk >= 23) { block("if (VERSION.SDK_INT >= VERSION_CODES.M)") { - nl("return root.getContext().getColor(resourceId);") + nl("return view.getContext().getColor(resourceId);") } } - nl("return root.getResources().getColor(resourceId);") + nl("return view.getResources().getColor(resourceId);") + } + + nl("@SuppressWarnings(\"deprecation\")") + block("public static android.content.res.ColorStateList getColorStateListFromResource(final android.view.View view, final int resourceId)") { + if (targetSdk >= 23) { + block("if (VERSION.SDK_INT >= VERSION_CODES.M)") { + nl("return view.getContext().getColorStateList(resourceId);") + } + } + nl("return view.getResources().getColorStateList(resourceId);") + } + + nl("@SuppressWarnings(\"deprecation\")") + block("public static android.graphics.drawable.Drawable getDrawableFromResource(final android.view.View view, final int resourceId)") { + if (targetSdk >= 21) { + block("if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP)") { + nl("return view.getContext().getDrawable(resourceId);") + } + } + nl("return view.getResources().getDrawable(resourceId);") } block("public static boolean parse(String str, boolean fallback)") { |