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 17 package android.database; 18 19 /** 20 * A specialization of Observable for ContentObserver that provides methods for 21 * invoking the various callback methods of ContentObserver. 22 */ 23 public class ContentObservable extends Observable<ContentObserver> { 24 25 @Override 26 public void registerObserver(ContentObserver observer) { 27 super.registerObserver(observer); 28 } 29 30 /** 31 * invokes dispatchUpdate on each observer, unless the observer doesn't want 32 * self-notifications and the update is from a self-notification 33 * @param selfChange 34 */ 35 public void dispatchChange(boolean selfChange) { 36 synchronized(mObservers) { 37 for (ContentObserver observer : mObservers) { 38 if (!selfChange || observer.deliverSelfNotifications()) { 39 observer.dispatchChange(selfChange); 40 } 41 } 42 } 43 } 44 45 /** 46 * invokes onChange on each observer 47 * @param selfChange 48 */ 49 public void notifyChange(boolean selfChange) { 50 synchronized(mObservers) { 51 for (ContentObserver observer : mObservers) { 52 observer.onChange(selfChange); 53 } 54 } 55 } 56 } 57