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 
     17 package com.android.camera.data;
     18 
     19 import android.database.ContentObserver;
     20 
     21 /**
     22  * Listening to the changes to the local image and video data. onChange will
     23  * happen on the main thread.
     24  */
     25 public class FilmstripContentObserver extends ContentObserver {
     26 
     27     private ChangeListener mChangeListener;
     28 
     29     public interface ChangeListener {
     30         public void onChange();
     31     }
     32 
     33     private boolean mActivityPaused = false;
     34     private boolean mMediaDataChangedDuringPause = false;
     35 
     36     public FilmstripContentObserver() {
     37         super(null);
     38     }
     39 
     40     public void setForegroundChangeListener(ChangeListener changeListener) {
     41         mChangeListener = changeListener;
     42     }
     43 
     44     public void removeForegroundChangeListener() {
     45         mChangeListener = null;
     46     }
     47 
     48     /**
     49      * When the activity is paused and MediaObserver get onChange() call, then
     50      * we would like to set a dirty bit to reload the data at onResume().
     51      */
     52     @Override
     53     public void onChange(boolean selfChange) {
     54         if (mChangeListener != null) {
     55             mChangeListener.onChange();
     56         }
     57         if (mActivityPaused) {
     58             mMediaDataChangedDuringPause = true;
     59         }
     60     }
     61 
     62     public void setActivityPaused(boolean paused) {
     63         mActivityPaused = paused;
     64         if (!paused) {
     65             mMediaDataChangedDuringPause = false;
     66         }
     67     }
     68 
     69     public boolean isMediaDataChangedDuringPause() {
     70         return mMediaDataChangedDuringPause;
     71     }
     72 }
     73