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.testapp.adapter; 17 18 import android.databinding.BindingAdapter; 19 import android.databinding.DataBindingComponent; 20 import android.databinding.testapp.TestComponent; 21 import android.widget.TextView; 22 23 public class InstanceAdapter { 24 private final String format; 25 26 public InstanceAdapter(String format) { 27 this.format = format; 28 } 29 30 @BindingAdapter("instanceAttr0") 31 public void setInstanceAttr0(TextView view, String text) { 32 view.setText(String.format(format, text, "foo", "bar", "baz")); 33 } 34 35 @BindingAdapter({"instanceAttr1", "instanceAttr2"}) 36 public void setInstanceAttr1(TextView view, String text, String text2) { 37 view.setText(String.format(format, text, text2, "foo", "bar")); 38 } 39 40 @BindingAdapter("instanceAttr3") 41 public void setInstanceAttr3(TextView view, String oldText, String text) { 42 view.setText(String.format(format, oldText, text, "foo", "bar")); 43 } 44 45 @BindingAdapter({"instanceAttr4", "instanceAttr5"}) 46 public void setInstanceAttr4(TextView view, String oldText1, String oldText2, 47 String text1, String text2) { 48 view.setText(String.format(format, oldText1, oldText2, text1, text2)); 49 } 50 51 @BindingAdapter("instanceAttr6") 52 public static void setInstanceAttr6(DataBindingComponent component, TextView view, String text) { 53 view.setText(String.format("%s %s", text, component == null ? "null" : "component")); 54 } 55 56 @BindingAdapter("instanceAttr7") 57 public void setInstanceAttr7(DataBindingComponent component, TextView view, String text) { 58 view.setText(String.format(format, text, component == null ? "null" : "component", "bar", "baz")); 59 } 60 61 @BindingAdapter({"instanceAttr8", "instanceAttr9"}) 62 public void setInstanceAttr8(TestComponent component, TextView view, String text, String text2) { 63 view.setText(String.format(format, text, text2, component == null ? "null" : "component", 64 "bar")); 65 } 66 } 67