1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.databinding.adapters; 17 18 import android.databinding.BindingAdapter; 19 import android.databinding.BindingMethod; 20 import android.databinding.BindingMethods; 21 import android.graphics.drawable.Drawable; 22 import android.net.Uri; 23 import android.widget.ImageView; 24 25 @BindingMethods({ 26 @BindingMethod(type = android.widget.ImageView.class, attribute = "android:tint", method = "setImageTintList"), 27 @BindingMethod(type = android.widget.ImageView.class, attribute = "android:tintMode", method = "setImageTintMode"), 28 }) 29 public class ImageViewBindingAdapter { 30 @BindingAdapter("android:src") 31 public static void setImageUri(ImageView view, String imageUri) { 32 if (imageUri == null) { 33 view.setImageURI(null); 34 } else { 35 view.setImageURI(Uri.parse(imageUri)); 36 } 37 } 38 39 @BindingAdapter("android:src") 40 public static void setImageUri(ImageView view, Uri imageUri) { 41 view.setImageURI(imageUri); 42 } 43 44 @BindingAdapter("android:src") 45 public static void setImageDrawable(ImageView view, Drawable drawable) { 46 view.setImageDrawable(drawable); 47 } 48 } 49