DynamicUtilWriter.kt revision 012f7781add1b38b28c0c68a94172715e635c00e
1package android.databinding.tool.writer 2 3 4class DynamicUtilWriter() { 5 public fun write() : String { 6 return """ 7package android.databinding; 8 9import android.content.res.ColorStateList; 10import android.graphics.drawable.Drawable; 11import android.os.Build.VERSION; 12import android.os.Build.VERSION_CODES; 13import android.view.View; 14 15public class DynamicUtil { 16 @SuppressWarnings("deprecation") 17 public static ColorStateList getColorStateListFromResource(View root, int resourceId) { 18 if (VERSION.SDK_INT >= VERSION_CODES.M) { 19 return root.getContext().getColorStateList(resourceId); 20 } else { 21 return root.getResources().getColorStateList(resourceId); 22 } 23 } 24 25 @SuppressWarnings("deprecation") 26 public static Drawable getDrawableFromResource(View root, int resourceId) { 27 if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { 28 return root.getContext().getDrawable(resourceId); 29 } else { 30 return root.getResources().getDrawable(resourceId); 31 } 32 } 33} 34""" 35 } 36}