• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import android.net.Uri;
20 
21 /**
22  * A specialization of {@link Observable} for {@link ContentObserver}
23  * that provides methods for sending notifications to a list of
24  * {@link ContentObserver} objects.
25  */
26 public class ContentObservable extends Observable<ContentObserver> {
27     // Even though the generic method defined in Observable would be perfectly
28     // fine on its own, we can't delete this overridden method because it would
29     // potentially break binary compatibility with existing applications.
30     @Override
registerObserver(ContentObserver observer)31     public void registerObserver(ContentObserver observer) {
32         super.registerObserver(observer);
33     }
34 
35     /**
36      * Invokes {@link ContentObserver#dispatchChange(boolean)} on each observer.
37      * <p>
38      * If <code>selfChange</code> is true, only delivers the notification
39      * to the observer if it has indicated that it wants to receive self-change
40      * notifications by implementing {@link ContentObserver#deliverSelfNotifications}
41      * to return true.
42      * </p>
43      *
44      * @param selfChange True if this is a self-change notification.
45      *
46      * @deprecated Use {@link #dispatchChange(boolean, Uri)} instead.
47      */
48     @Deprecated
dispatchChange(boolean selfChange)49     public void dispatchChange(boolean selfChange) {
50         dispatchChange(selfChange, null);
51     }
52 
53     /**
54      * Invokes {@link ContentObserver#dispatchChange(boolean, Uri)} on each observer.
55      * Includes the changed content Uri when available.
56      * <p>
57      * If <code>selfChange</code> is true, only delivers the notification
58      * to the observer if it has indicated that it wants to receive self-change
59      * notifications by implementing {@link ContentObserver#deliverSelfNotifications}
60      * to return true.
61      * </p>
62      *
63      * @param selfChange True if this is a self-change notification.
64      * @param uri The Uri of the changed content, or null if unknown.
65      */
dispatchChange(boolean selfChange, Uri uri)66     public void dispatchChange(boolean selfChange, Uri uri) {
67         synchronized(mObservers) {
68             for (ContentObserver observer : mObservers) {
69                 if (!selfChange || observer.deliverSelfNotifications()) {
70                     observer.dispatchChange(selfChange, uri);
71                 }
72             }
73         }
74     }
75 
76     /**
77      * Invokes {@link ContentObserver#onChange} on each observer.
78      *
79      * @param selfChange True if this is a self-change notification.
80      *
81      * @deprecated Use {@link #dispatchChange} instead.
82      */
83     @Deprecated
notifyChange(boolean selfChange)84     public void notifyChange(boolean selfChange) {
85         synchronized(mObservers) {
86             for (ContentObserver observer : mObservers) {
87                 observer.onChange(selfChange, null);
88             }
89         }
90     }
91 }
92