Home | History | Annotate | Download | only in data
      1 /*
      2  * Copyright (C) 2013 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 package com.android.photos.data;
     17 
     18 import android.net.Uri;
     19 
     20 import com.android.photos.data.PhotoProvider.ChangeNotification;
     21 
     22 import java.util.ArrayList;
     23 
     24 /**
     25  * Used for capturing notifications from PhotoProvider without relying on
     26  * ContentResolver. MockContentResolver does not allow sending notification to
     27  * ContentObservers, so PhotoProvider allows this alternative for testing.
     28  */
     29 public class NotificationWatcher implements ChangeNotification {
     30     private ArrayList<Uri> mUris = new ArrayList<Uri>();
     31     private boolean mSyncToNetwork = false;
     32 
     33     @Override
     34     public void notifyChange(Uri uri, boolean syncToNetwork) {
     35         mUris.add(uri);
     36         mSyncToNetwork = mSyncToNetwork || syncToNetwork;
     37     }
     38 
     39     public boolean isNotified(Uri uri) {
     40         return mUris.contains(uri);
     41     }
     42 
     43     public int notificationCount() {
     44         return mUris.size();
     45     }
     46 
     47     public boolean syncToNetwork() {
     48         return mSyncToNetwork;
     49     }
     50 
     51     public void reset() {
     52         mUris.clear();
     53         mSyncToNetwork = false;
     54     }
     55 }
     56