Observable.java revision 722fe711207a37783dfa7142284b0ebe5bd503fb
1/* 2 * Copyright (C) 2014 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 17package android.databinding; 18 19/** 20 * Observable classes provide a way in which data bound UI can be notified of changes. 21 * {@link ObservableList} and {@link ObservableMap} also provide the ability to notify when 22 * changes occur. ObservableField, ObservableBoolean, ObservableByte, ObservableShort, 23 * ObservableInt, ObservableLong, ObservableFloat, and ObservableDouble provide 24 * a means by which properties may be notified without implementing Observable. 25 * <p> 26 * An Observable object should notify the {@link OnPropertyChangedCallback} whenever 27 * an observed property of the class changes. 28 * <p> 29 * The getter for an observable property should be annotated with {@link Bindable}. 30 * <p> 31 * Convenience class BaseObservable implements this interface and PropertyChangeRegistry 32 * can help classes that don't extend BaseObservable to implement the listener registry. 33 */ 34public interface Observable { 35 36 /** 37 * Adds a callback to listen for changes to the Observable. 38 * @param callback The callback to start listening. 39 */ 40 void addOnPropertyChangedCallback(OnPropertyChangedCallback callback); 41 42 /** 43 * Removes a callback from those listening for changes. 44 * @param callback The callback that should stop listening. 45 */ 46 void removeOnPropertyChangedCallback(OnPropertyChangedCallback callback); 47 48 /** 49 * The callback that is called by Observable when an observable property has changed. 50 */ 51 abstract class OnPropertyChangedCallback { 52 53 /** 54 * Called by an Observable whenever an observable property changes. 55 * @param sender The Observable that is changing. 56 * @param propertyId The BR identifier of the property that has changed. The getter 57 * for this property should be annotated with {@link Bindable}. 58 */ 59 public abstract void onPropertyChanged(Observable sender, int propertyId); 60 } 61} 62