// Path: databindingdemo/src/main/java/com/example/databindingdemo/model/DetailedInformation.java
// public class DetailedInformation {
//     public final ObservableField<String> userName = new ObservableField<>();
//     public final ObservableInt userAge = new ObservableInt();
// }
// 
// Path: databindingdemo/src/main/java/com/example/databindingdemo/model/UserInfo.java
// public class UserInfo extends BaseObservable {
//     public String userName;
//     public String userAge;
//     public String userBirthday;
//     private static final String TAG = "UserInfo";
// 
//     public UserInfo(String userName, String userAge, String userGender) {
//         this.userName = userName;
//         this.userAge = userAge;
//         this.userBirthday = userGender;
//     }
// 
//     /*
//       注解 Bindable 用于双向数据绑定，需要与notifyPropertyCanged()方法结合使用， 该注解用于标注以“get”
//       或“is”开头的方法，且实体需要继承BaseObservable。
//      */
//     @Bindable
//     public String getUserName() {
//         Log.d(TAG, "getUserName: " + userName);
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         Log.d(TAG, "setUserName: " + userName);
//         this.userName = userName;
//         // 如果该数据发生变化，则会通知更新该值对应的组件
//         notifyPropertyChanged(BR.userName);
//     }
// }


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;
import com.example.databindingdemo.databinding.ActivityMainBinding;
import com.example.databindingdemo.databinding.IncludeLayoutBinding;
import com.example.databindingdemo.databinding.ViewStubBinding;
import com.example.databindingdemo.model.DetailedInformation;
import com.example.databindingdemo.model.UserInfo;
        df.userName.set(userInfo.getUserName());
        df.userAge.set(Integer.valueOf(userInfo.userAge));
        // 在activity_main 中 include 的layout 由于是使用databinding定义的View，因此本质上属于
        // IncludeLayoutBinding
        IncludeLayoutBinding includeLayoutBinding = binding.includeLayout;
        includeLayoutBinding.setDetailInfo(df);

        // 依旧可以使用findViewById()访问view， 但是拒绝这么使用，因为binding中将所有带id的view都进行了实例化
        // name = (TextView) findViewById(R.id.textView);

        binding.viewStub.setOnInflateListener(new ViewStub.OnInflateListener() {
            @Override
            public void onInflate(ViewStub viewStub, View view) {
                // 在被其他布局inflate时，将对应的值绑定上去
                ViewStubBinding binding = DataBindingUtil.bind(view);
                String testText = "testText balala";
                binding.setTestText(testText);
            }
        });

        // 在合适的时间 inflate viewStub
        binding.viewStub.getViewStub().inflate();
    }

    public class ClickListener{

        public void onClick() {
            int age = Integer.parseInt( userInfo.userAge) ;
            age++;
            Log.d(TAG, "onClick: age = " + age);
// Path: databindingdemo/src/main/java/com/example/databindingdemo/model/DetailedInformation.java
// public class DetailedInformation {
//     public final ObservableField<String> userName = new ObservableField<>();
//     public final ObservableInt userAge = new ObservableInt();
// }
// 
// Path: databindingdemo/src/main/java/com/example/databindingdemo/model/UserInfo.java
// public class UserInfo extends BaseObservable {
//     public String userName;
//     public String userAge;
//     public String userBirthday;
//     private static final String TAG = "UserInfo";
// 
//     public UserInfo(String userName, String userAge, String userGender) {
//         this.userName = userName;
//         this.userAge = userAge;
//         this.userBirthday = userGender;
//     }
// 
//     /*
//       注解 Bindable 用于双向数据绑定，需要与notifyPropertyCanged()方法结合使用， 该注解用于标注以“get”
//       或“is”开头的方法，且实体需要继承BaseObservable。
//      */
//     @Bindable
//     public String getUserName() {
//         Log.d(TAG, "getUserName: " + userName);
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         Log.d(TAG, "setUserName: " + userName);
//         this.userName = userName;
//         // 如果该数据发生变化，则会通知更新该值对应的组件
//         notifyPropertyChanged(BR.userName);
//     }
// }


// Path: databindingdemo/src/main/java/com/example/databindingdemo/MainActivity.java
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;
import com.example.databindingdemo.databinding.ActivityMainBinding;
import com.example.databindingdemo.databinding.IncludeLayoutBinding;
import com.example.databindingdemo.databinding.ViewStubBinding;
import com.example.databindingdemo.model.DetailedInformation;
import com.example.databindingdemo.model.UserInfo;

        df.userName.set(userInfo.getUserName());
        df.userAge.set(Integer.valueOf(userInfo.userAge));
        // 在activity_main 中 include 的layout 由于是使用databinding定义的View，因此本质上属于
        // IncludeLayoutBinding
        IncludeLayoutBinding includeLayoutBinding = binding.includeLayout;
        includeLayoutBinding.setDetailInfo(df);

        // 依旧可以使用findViewById()访问view， 但是拒绝这么使用，因为binding中将所有带id的view都进行了实例化
        // name = (TextView) findViewById(R.id.textView);

        binding.viewStub.setOnInflateListener(new ViewStub.OnInflateListener() {
            @Override
            public void onInflate(ViewStub viewStub, View view) {
                // 在被其他布局inflate时，将对应的值绑定上去
                ViewStubBinding binding = DataBindingUtil.bind(view);
                String testText = "testText balala";
                binding.setTestText(testText);
            }
        });

        // 在合适的时间 inflate viewStub
        binding.viewStub.getViewStub().inflate();
    }

    public class ClickListener{

        public void onClick() {
            int age = Integer.parseInt( userInfo.userAge) ;
            age++;
            Log.d(TAG, "onClick: age = " + age);
            userInfo.userAge = age + "";