Advertisement
Guest User

snippet

a guest
Feb 4th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. @BindingAdapter({"resourceState"})
  2. public static void setResourceState(CompoundButton view, int state) {
  3.     boolean checked;
  4.     checked = state != LocationState.STOPPED;
  5.     if (view.isChecked() != checked) {
  6.         view.setChecked(checked);
  7.     }
  8. }
  9.  
  10. @InverseBindingAdapter(attribute = "resourceState", event = "resourceStateAttrChanged")
  11. public static int getResourceStateAttrChanged(CompoundButton view) {
  12.     if (view.isChecked()) {
  13.         return LocationState.WAITING;
  14.     } else {
  15.         return LocationState.STOPPED;
  16.     }
  17. }
  18.  
  19. @BindingAdapter({"resourceStateAttrChanged"})
  20. public static void setResourceStateAttrChanged(CompoundButton view, final InverseBindingListener attrChange) {
  21.     view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  22.         @Override
  23.         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  24.             Context context = buttonView.getContext();
  25.             if (isChecked) {
  26.                 Repository.getInstance().requestLocationUpdates(context);
  27.             } else {
  28.                 Repository.getInstance().removeLocationUpdates(context);
  29.             }
  30.         }
  31.     });
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement