ContentObservable.java revision 86de0590b94bcce27e3038c27464bed510bb564a
1/* 2 * Copyright (C) 2007 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.database; 18 19/** 20 * A specialization of {@link Observable} for {@link ContentObserver} 21 * that provides methods for sending notifications to a list of 22 * {@link ContentObserver} objects. 23 */ 24public class ContentObservable extends Observable<ContentObserver> { 25 // Even though the generic method defined in Observable would be perfectly 26 // fine on its own, we can't delete this overridden method because it would 27 // potentially break binary compatibility with existing applications. 28 @Override 29 public void registerObserver(ContentObserver observer) { 30 super.registerObserver(observer); 31 } 32 33 /** 34 * Invokes {@link ContentObserver#dispatchChange} on each observer. 35 * 36 * If <code>selfChange</code> is true, only delivers the notification 37 * to the observer if it has indicated that it wants to receive self-change 38 * notifications by implementing {@link ContentObserver#deliverSelfNotifications} 39 * to return true. 40 * 41 * @param selfChange True if this is a self-change notification. 42 */ 43 public void dispatchChange(boolean selfChange) { 44 synchronized(mObservers) { 45 for (ContentObserver observer : mObservers) { 46 if (!selfChange || observer.deliverSelfNotifications()) { 47 observer.dispatchChange(selfChange); 48 } 49 } 50 } 51 } 52 53 /** 54 * Invokes {@link ContentObserver#onChange} on each observer. 55 * 56 * @param selfChange True if this is a self-change notification. 57 * 58 * @deprecated Use {@link #dispatchChange} instead. 59 */ 60 @Deprecated 61 public void notifyChange(boolean selfChange) { 62 synchronized(mObservers) { 63 for (ContentObserver observer : mObservers) { 64 observer.onChange(selfChange); 65 } 66 } 67 } 68} 69