User.java revision fead9ca09b117136b35bc5bf137340a754f9eddd
1package com.android.example.bindingdemo.vo; 2 3import android.databinding.Bindable; 4import android.graphics.Color; 5 6import android.databinding.BaseObservable; 7import com.android.example.bindingdemo.BR; 8 9import java.util.Objects; 10 11public class User extends BaseObservable { 12 @Bindable 13 private String name; 14 @Bindable 15 private String lastName; 16 @Bindable 17 private int photoResource = 0; 18 @Bindable 19 private int favoriteColor = Color.RED; 20 @Bindable 21 private int group; 22 public static final int TOOLKITTY = 1; 23 public static final int ROBOT = 2; 24 25 public User(String name, String lastName, int photoResource, int group) { 26 this.name = name; 27 this.lastName = lastName; 28 this.photoResource = photoResource; 29 this.group = group; 30 } 31 32 public void setGroup(int group) { 33 if (this.group == group) { 34 return; 35 } 36 this.group = group; 37 notifyPropertyChanged(BR.group); 38 } 39 40 public int getGroup() { 41 return group; 42 } 43 44 public String getName() { 45 return name; 46 } 47 48 public void setName(String name) { 49 if (Objects.equals(name, this.name)) { 50 return; 51 } 52 this.name = name; 53 notifyPropertyChanged(BR.name); 54 } 55 56 public String getLastName() { 57 return lastName; 58 } 59 60 public void setLastName(String lastName) { 61 if (Objects.equals(lastName, this.lastName)) { 62 return; 63 } 64 this.lastName = lastName; 65 notifyPropertyChanged(BR.lastName); 66 } 67 68 public int getPhotoResource() { 69 return photoResource; 70 } 71 72 public void setPhotoResource(int photoResource) { 73 if (this.photoResource == photoResource) { 74 return; 75 } 76 this.photoResource = photoResource; 77 notifyPropertyChanged(BR.photoResource); 78 } 79 80 public int getFavoriteColor() { 81 return favoriteColor; 82 } 83} 84